Skip to contentSkip to conversation

pata_platform struct resource signness fix

PATCH In review Wang Jian 5 participants 10 messages Sep 25, 2008 – Sep 29, 2008 libata

lore
Share & tools
lore

Wang Jian

author
#0 lore raw

PATCH 1/1 pata_platform struct resource signness fix

Hi,

This patch is to pata_platform.c but at this time, it's powerpc specific because it can only be triggerred using openfirmware, so I post the patch here. The patch is against 2.6.26-rc8.

The problem is triggerred when ata device is populated using pata_of_platform.c, and no irq is assigned (poll mode, such as CF card).

pata_of_platform_probe() parse device tree and

        if (ret == NO_IRQ)
	                irq_res.start = irq_res.end = -1;

Then irq is 0xffffffff, not NULL. Probe will fail coz irq can't be requested.

---
(irq_res->start > 0) will be true even when it is (-1). When the device has no irq, irq_res->start is assigned (-1).

---
 drivers/ata/pata_platform.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
drivers/ata/pata_platform.c +1 -1
index 8f65ad6..b12cd0c 100644
@@ -123,7 +123,7 @@ int __devinit __pata_platform_probe(struct device *dev,
 	/*
 	 * And the IRQ
 	 */
-	if (irq_res && irq_res->start > 0) {
+	if (irq_res && irq_res->start != -1) {
 		irq = irq_res->start;
 		irq_flags = irq_res->flags;
 	}
Signature · 1 line
1.5.5.4
author
#1 lore raw

The alternative fix can be.

drivers/ata/pata_of_platform.c +1 -1
index 408da30..1f18ad9 100644
@@ -52,7 +52,7 @@ static int __devinit pata_of_platform_probe(struct of_device *ofdev,
 
        ret = of_irq_to_resource(dn, 0, &irq_res);
        if (ret == NO_IRQ)
-               irq_res.start = irq_res.end = -1;
+               irq_res.start = irq_res.end = 0;
        else
                irq_res.flags = 0;
 

I just didn't spend much time to see which is better.

Quoted 39 lines · Wang Jian

Hi,

This patch is to pata_platform.c but at this time, it's powerpc specific because it can only be triggerred using openfirmware, so I post the patch here. The patch is against 2.6.26-rc8.

The problem is triggerred when ata device is populated using pata_of_platform.c, and no irq is assigned (poll mode, such as CF card).

pata_of_platform_probe() parse device tree and

        if (ret == NO_IRQ)
	                irq_res.start = irq_res.end = -1;

Then irq is 0xffffffff, not NULL. Probe will fail coz irq can't be requested.

---
(irq_res->start > 0) will be true even when it is (-1). When the device has no irq, irq_res->start is assigned (-1).

---
 drivers/ata/pata_platform.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
drivers/ata/pata_platform.c +1 -1
index 8f65ad6..b12cd0c 100644
@@ -123,7 +123,7 @@ int __devinit __pata_platform_probe(struct device *dev,
 	/*
 	 * And the IRQ
 	 */
-	if (irq_res && irq_res->start > 0) {
+	if (irq_res && irq_res->start != -1) {
 		irq = irq_res->start;
 		irq_flags = irq_res->flags;
 	}
#2 lore raw
Quoted 1 line · Wang Jian

The alternative fix can be.

This one is better as 0 is defined as 'invalid irq' for all architectures. Added linux-ide and Anton to cc.

- Leo

Quoted 66 lines
drivers/ata/pata_of_platform.c +1 -1
index 408da30..1f18ad9 100644
@@ -52,7 +52,7 @@ static int __devinit pata_of_platform_probe(struct
 of_device *ofdev,
 
       ret = of_irq_to_resource(dn, 0, &irq_res);
       if (ret == NO_IRQ)
-               irq_res.start = irq_res.end = -1;
+               irq_res.start = irq_res.end = 0;
       else
               irq_res.flags = 0;

I just didn't spend much time to see which is better.

Quoted 41 lines · Wang Jian

Hi,

This patch is to pata_platform.c but at this time, it's powerpc specific because it can only be triggerred using openfirmware, so I post the patch here. The patch is against 2.6.26-rc8.

The problem is triggerred when ata device is populated using pata_of_platform.c, and no irq is assigned (poll mode, such as CF card).

pata_of_platform_probe() parse device tree and

       if (ret == NO_IRQ)
                       irq_res.start = irq_res.end = -1;

Then irq is 0xffffffff, not NULL. Probe will fail coz irq can't be requested.

---
(irq_res->start > 0) will be true even when it is (-1). When the device has no irq, irq_res->start is assigned (-1).

---
 drivers/ata/pata_platform.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
drivers/ata/pata_platform.c +1 -1
index 8f65ad6..b12cd0c 100644
@@ -123,7 +123,7 @@ int __devinit __pata_platform_probe(struct device
 *dev,
       /*
        * And the IRQ
        */
-       if (irq_res && irq_res->start > 0) {
+       if (irq_res && irq_res->start != -1) {
               irq = irq_res->start;
               irq_flags = irq_res->flags;
Quoted 1 line
       }

_______________________________________________
Linuxppc-dev mailing list
[email protected]
https://ozlabs.org/mailman/listinfo/linuxppc-dev

#3 lore raw
Quoted 5 lines · Li Yang
Quoted 1 line · Wang Jian

The alternative fix can be.

This one is better as 0 is defined as 'invalid irq' for all architectures. Added linux-ide and Anton to cc.

Thanks for the correct Cc.

I've sent a patch to fix the issue more than a month ago.

http://www.mail-archive.com/[email protected]/msg22851.html

Jeff, could you apply the patch?

Thanks!

Signature · 3 lines
Anton Vorontsov
email: [email protected]
irc://irc.freenode.net/bd2
#4 lore raw
Quoted 6 lines · Anton Vorontsov
Quoted 4 lines · Li Yang
Quoted 1 line · Wang Jian

The alternative fix can be.

This one is better as 0 is defined as 'invalid irq' for all architectures. Added linux-ide and Anton to cc.

Quoted 7 lines

Thanks for the correct Cc.

I've sent a patch to fix the issue more than a month ago.

http://www.mail-archive.com/[email protected]/msg22851.html

Jeff, could you apply the patch?

Can you resend, I don't seem to have it...

#5 lore raw

PATCH 1/1 pata_of_platform: fix no irq handling

When no irq specified the pata_of_platform fills the irq_res with -1, which is wrong to do for two reasons:

1. By definition, 'no irq' should be IRQ 0, not some negative integer;
2. pata_platform checks for irq_res.start > 0, but since irq_res.start is unsigned type, the check will be true for `-1'.

---

Quoted 9 lines · Jeff Garzik
Quoted 8 lines · Anton Vorontsov
Quoted 4 lines · Li Yang
Quoted 1 line · Wang Jian

The alternative fix can be.

This one is better as 0 is defined as 'invalid irq' for all architectures. Added linux-ide and Anton to cc.

Thanks for the correct Cc.

Quoted 7 lines
Quoted 5 lines

I've sent a patch to fix the issue more than a month ago.

http://www.mail-archive.com/[email protected]/msg22851.html

Jeff, could you apply the patch?

Can you resend, I don't seem to have it...

Here it is.

Thanks,

 drivers/ata/pata_of_platform.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
drivers/ata/pata_of_platform.c +1 -1
index 408da30..1f18ad9 100644
@@ -52,7 +52,7 @@ static int __devinit pata_of_platform_probe(struct of_device *ofdev,
 
 	ret = of_irq_to_resource(dn, 0, &irq_res);
 	if (ret == NO_IRQ)
-		irq_res.start = irq_res.end = -1;
+		irq_res.start = irq_res.end = 0;
 	else
 		irq_res.flags = 0;
 
Signature · 1 line
1.5.6.3
author
#6 lore raw
In reply to Li Yang
Quoted 5 lines · Li Yang
Quoted 1 line · Wang Jian

The alternative fix can be.

This one is better as 0 is defined as 'invalid irq' for all architectures. Added linux-ide and Anton to cc.

However, this is not very true. Just git grep "#define NO_IRQ" and see. It seems that the NO_IRQ is in transition from (-1) to (0).

I happened to code the same 2 patches as Anton Vorontsov <[email protected]> had done without knowing his earlier work. I think he was also confused by (-1) and (0).

Quoted 68 lines

- Leo

Quoted 63 lines
drivers/ata/pata_of_platform.c +1 -1
index 408da30..1f18ad9 100644
@@ -52,7 +52,7 @@ static int __devinit pata_of_platform_probe(struct
 of_device *ofdev,
 
       ret = of_irq_to_resource(dn, 0, &irq_res);
       if (ret == NO_IRQ)
-               irq_res.start = irq_res.end = -1;
+               irq_res.start = irq_res.end = 0;
       else
               irq_res.flags = 0;

I just didn't spend much time to see which is better.

Quoted 40 lines · Wang Jian

Hi,

This patch is to pata_platform.c but at this time, it's powerpc specific because it can only be triggerred using openfirmware, so I post the patch here. The patch is against 2.6.26-rc8.

The problem is triggerred when ata device is populated using pata_of_platform.c, and no irq is assigned (poll mode, such as CF card).

pata_of_platform_probe() parse device tree and

       if (ret == NO_IRQ)
                       irq_res.start = irq_res.end = -1;

Then irq is 0xffffffff, not NULL. Probe will fail coz irq can't be requested.

---
(irq_res->start > 0) will be true even when it is (-1). When the device has no irq, irq_res->start is assigned (-1).

---
 drivers/ata/pata_platform.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
drivers/ata/pata_platform.c +1 -1
index 8f65ad6..b12cd0c 100644
@@ -123,7 +123,7 @@ int __devinit __pata_platform_probe(struct device
 *dev,
       /*
        * And the IRQ
        */
-       if (irq_res && irq_res->start > 0) {
+       if (irq_res && irq_res->start != -1) {
               irq = irq_res->start;
               irq_flags = irq_res->flags;
Quoted 1 line
       }

_______________________________________________
Linuxppc-dev mailing list
[email protected]
https://ozlabs.org/mailman/listinfo/linuxppc-dev

#7 lore raw
Quoted 9 lines · Wang Jian
Quoted 5 lines · Li Yang
Quoted 1 line · Wang Jian

The alternative fix can be.

This one is better as 0 is defined as 'invalid irq' for all architectures. Added linux-ide and Anton to cc.

However, this is not very true. Just git grep "#define NO_IRQ" and see. It seems that the NO_IRQ is in transition from (-1) to (0).

Yeah, there is a mess, but it gets better as time goes by. The platforms/drivers should be fixed, since 0 is the only invalid VIRQ.

Signature · 3 lines
Anton Vorontsov
email: [email protected]
irc://irc.freenode.net/bd2
#8 lore raw
In reply to Wang Jian
Quoted 5 lines · Wang Jian

Hi,

This patch is to pata_platform.c but at this time, it's powerpc specific because it can only be triggerred using openfirmware, so I post the patch here. The patch is against 2.6.26-rc8.

Powerpc isn't the only arch to use openfirmware. Anyway, you have to cc [email protected] if you want the patch to be merged.

- Leo

author
#9 lore raw

As I said, I didn't spend much time on the issue, so I don't know which patch is better. (But I do think the patch to pata_of_platform.c is better ATM).

AFAIK, powerpc is the only consumer of pata_of_platform.c, so I think this list is better for discussion.

I should cc: Anton Vorontsov <[email protected]> but last time I cc:
him I got bounced.

Quoted 13 lines · Leo Li
Quoted 5 lines · Wang Jian

Hi,

This patch is to pata_platform.c but at this time, it's powerpc specific because it can only be triggerred using openfirmware, so I post the patch here. The patch is against 2.6.26-rc8.

Powerpc isn't the only arch to use openfirmware. Anyway, you have to cc [email protected] if you want the patch to be merged.

- Leo