Skip to contentSkip to conversation

pata_amd: fix sparse warning

PATCH Applied [email protected] 3 participants 4 messages Mar 28, 2008 – Apr 4, 2008 libata

lore
Share & tools
lore
#0 lore raw

PATCH 2/2 pata_amd: fix sparse warning

From: Harvey Harrison <[email protected]>

Current code is essentially choosing between dividing by 1 or dividing by two, make the conditions a little more obvious.

As a bonus, removes a sparse error:
drivers/ata/pata_amd.c:59:11: warning: symbol '__x' shadows an earlier one drivers/ata/pata_amd.c:59:11: originally declared here

---

 drivers/ata/pata_amd.c |    4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/ata/pata_amd.c renamed from drivers/ata/pata_amd.c~pata_amd-fix-sparse-warning +3 -1
diff -puN drivers/ata/pata_amd.c~pata_amd-fix-sparse-warning drivers/ata/pata_amd.c
@@ -56,7 +56,9 @@ static void timing_setup(struct ata_port
 	u8 t;
 
 	T = 1000000000 / amd_clock;
-	UT = T / min_t(int, max_t(int, clock, 1), 2);
+	UT = T;
+	if (clock >= 2)
+		UT = T / 2;
 
 	if (ata_timing_compute(adev, speed, &at, T, UT) < 0) {
 		dev_printk(KERN_ERR, &pdev->dev, "unknown mode %d.\n", speed);

_

#1 lore raw
Quoted 21 lines · [email protected] wrote:

From: Harvey Harrison <[email protected]>

Current code is essentially choosing between dividing by 1 or dividing by two, make the conditions a little more obvious.

As a bonus, removes a sparse error:
drivers/ata/pata_amd.c:59:11: warning: symbol '__x' shadows an earlier one drivers/ata/pata_amd.c:59:11: originally declared here

---

 drivers/ata/pata_amd.c |    4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff -puN drivers/ata/pata_amd.c~pata_amd-fix-sparse-warning drivers/ata/pata_amd.c

drivers/ata/pata_amd.c static void timing_setup(struct ata_port · line 61

Quoted 7 lines
drivers/ata/pata_amd.c renamed from drivers/ata/pata_amd.c~pata_amd-fix-sparse-warning +3 -1
@@ -56,7 +56,9 @@ static void timing_setup(struct ata_port
 	u8 t;
 
 	T = 1000000000 / amd_clock;
-	UT = T / min_t(int, max_t(int, clock, 1), 2);
+	UT = T;
+	if (clock >= 2)
+		UT = T / 2;

Why assign UT twice, potentially?

#2 lore raw

On Sat, Mar 29, 2008 at 9:17 AM, Jeff Garzik <[email protected]> wrote:
...

Quoted 5 lines

drivers/ata/pata_amd.c static void timing_setup(struct ata_port · line 61

Quoted 3 lines
drivers/ata/pata_amd.c renamed from drivers/ata/pata_amd.c~pata_amd-fix-sparse-warning +3 -0
+     UT = T;
+     if (clock >= 2)
+             UT = T / 2;

Why assign UT twice, potentially?

This construct used in many places in the kernel because it makes the code more readable.

"UT" is a regular "int" type and assigning it twice is ok.

e.g. from tg3_writephy():
...

        ret = -EBUSY;
        if (loops != 0)
                ret = 0;

hth,
grant

Applied
#3 lore raw
In reply to [email protected]
Quoted 21 lines · [email protected] wrote:

From: Harvey Harrison <[email protected]>

Current code is essentially choosing between dividing by 1 or dividing by two, make the conditions a little more obvious.

As a bonus, removes a sparse error:
drivers/ata/pata_amd.c:59:11: warning: symbol '__x' shadows an earlier one drivers/ata/pata_amd.c:59:11: originally declared here

---

 drivers/ata/pata_amd.c |    4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff -puN drivers/ata/pata_amd.c~pata_amd-fix-sparse-warning drivers/ata/pata_amd.c

drivers/ata/pata_amd.c static void timing_setup(struct ata_port · line 63

Quoted 9 lines
drivers/ata/pata_amd.c renamed from drivers/ata/pata_amd.c~pata_amd-fix-sparse-warning +3 -1
@@ -56,7 +56,9 @@ static void timing_setup(struct ata_port
 	u8 t;
 
 	T = 1000000000 / amd_clock;
-	UT = T / min_t(int, max_t(int, clock, 1), 2);
+	UT = T;
+	if (clock >= 2)
+		UT = T / 2;
 
 	if (ata_timing_compute(adev, speed, &at, T, UT) < 0) {

applied