[PATCH 8/9] arch/powerpc/kernel: Drop unnecessary null test

Subsystems: linux for powerpc (32-bit and 64-bit), the rest

STALE5855d

3 messages, 3 authors, 2010-08-03 · open the first message on its own page

[PATCH 8/9] arch/powerpc/kernel: Drop unnecessary null test

From: Julia Lawall <hidden>
Date: 2010-08-03 21:35:20

From: Julia Lawall <redacted>

list_for_each_entry binds its first argument to a non-null value, and thus
any null test on the value of that argument is superfluous.

The semantic patch that makes this change is as follows:
(http://coccinelle.lip6.fr/)

// <smpl>
@@
iterator I;
expression x,E,E1,E2;
statement S,S1,S2;
@@

I(x,...) { <...
- if (x != NULL || ...)
  S
  ...> }
// </smpl>

Signed-off-by: Julia Lawall <redacted>

---
 arch/powerpc/kernel/pci_of_scan.c |    3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/arch/powerpc/kernel/pci_of_scan.c b/arch/powerpc/kernel/pci_of_scan.c
index 6ddb795..62dd363 100644
--- a/arch/powerpc/kernel/pci_of_scan.c
+++ b/arch/powerpc/kernel/pci_of_scan.c
@@ -336,8 +336,7 @@ static void __devinit __of_scan_bus(struct device_node *node,
 		if (dev->hdr_type == PCI_HEADER_TYPE_BRIDGE ||
 		    dev->hdr_type == PCI_HEADER_TYPE_CARDBUS) {
 			struct device_node *child = pci_device_to_OF_node(dev);
-			if (dev)
-				of_scan_pci_bridge(child, dev);
+			of_scan_pci_bridge(child, dev);
 		}
 	}
 }

Re: [PATCH 8/9] arch/powerpc/kernel: Drop unnecessary null test

From: Dan Carpenter <hidden>
Date: 2010-08-03 21:52:08

On Tue, Aug 03, 2010 at 11:35:17PM +0200, Julia Lawall wrote:
quoted hunk
diff --git a/arch/powerpc/kernel/pci_of_scan.c b/arch/powerpc/kernel/pci_of_scan.c
index 6ddb795..62dd363 100644
--- a/arch/powerpc/kernel/pci_of_scan.c
+++ b/arch/powerpc/kernel/pci_of_scan.c
@@ -336,8 +336,7 @@ static void __devinit __of_scan_bus(struct device_node *node,
 		if (dev->hdr_type == PCI_HEADER_TYPE_BRIDGE ||
 		    dev->hdr_type == PCI_HEADER_TYPE_CARDBUS) {
 			struct device_node *child = pci_device_to_OF_node(dev);
-			if (dev)
-				of_scan_pci_bridge(child, dev);
+			of_scan_pci_bridge(child, dev);
The intention was probably to check "child" instead of "dev".
pci_device_to_OF_node() can return NULL.  On the other hand the code
has been this way for a year and no one has complained...

regards,
dan carpenter
 		}
 	}
 }

Re: [PATCH 8/9] arch/powerpc/kernel: Drop unnecessary null test

From: Grant Likely <hidden>
Date: 2010-08-03 22:00:49

On Tue, Aug 3, 2010 at 3:51 PM, Dan Carpenter [off-list ref] wrote:
On Tue, Aug 03, 2010 at 11:35:17PM +0200, Julia Lawall wrote:
quoted
diff --git a/arch/powerpc/kernel/pci_of_scan.c b/arch/powerpc/kernel/pci=
_of_scan.c
quoted
index 6ddb795..62dd363 100644
--- a/arch/powerpc/kernel/pci_of_scan.c
+++ b/arch/powerpc/kernel/pci_of_scan.c
@@ -336,8 +336,7 @@ static void __devinit __of_scan_bus(struct device_no=
de *node,
quoted
=A0 =A0 =A0 =A0 =A0 =A0 =A0 if (dev->hdr_type =3D=3D PCI_HEADER_TYPE_BRI=
DGE ||
quoted
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 dev->hdr_type =3D=3D PCI_HEADER_TYPE=
_CARDBUS) {
quoted
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 struct device_node *child =
=3D pci_device_to_OF_node(dev);
quoted
- =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (dev)
- =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 of_scan_pci_br=
idge(child, dev);
quoted
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 of_scan_pci_bridge(child, dev)=
;
The intention was probably to check "child" instead of "dev".
pci_device_to_OF_node() can return NULL. =A0On the other hand the code
has been this way for a year and no one has complained...
Still, it should be fixed.  It is likely that I'll be generalizing
this code for other architectures in the near future.  I'll spin a
patch.

g.
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help