[PATCH] PPC: CHRP - fix possible NULL pointer dereference

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

STALE6866d

4 messages, 2 authors, 2007-11-23 · open the first message on its own page

[PATCH] PPC: CHRP - fix possible NULL pointer dereference

From: Cyrill Gorcunov <hidden>
Date: 2007-11-22 20:04:28

From: Cyrill Gorcunov <redacted>

This patch does fix possible NULL pointer dereference
inside of strncmp() if of_get_property() failed.

Signed-off-by: Cyrill Gorcunov <redacted>
---

 arch/powerpc/platforms/chrp/setup.c |   23 +++++++++++++----------
 1 files changed, 13 insertions(+), 10 deletions(-)
diff --git a/arch/powerpc/platforms/chrp/setup.c b/arch/powerpc/platforms/chrp/setup.c
index 5930626..e3f276d 100644
--- a/arch/powerpc/platforms/chrp/setup.c
+++ b/arch/powerpc/platforms/chrp/setup.c
@@ -115,7 +115,7 @@ void chrp_show_cpuinfo(struct seq_file *m)
 	seq_printf(m, "machine\t\t: CHRP %s\n", model);
 
 	/* longtrail (goldengate) stuff */
-	if (!strncmp(model, "IBM,LongTrail", 13)) {
+	if (model && !strncmp(model, "IBM,LongTrail", 13)) {
 		/* VLSI VAS96011/12 `Golden Gate 2' */
 		/* Memory banks */
 		sdramen = (in_le32(gg2_pci_config_base + GG2_PCI_DRAM_CTRL)
@@ -203,16 +203,19 @@ static void __init sio_fixup_irq(const char *name, u8 device, u8 level,
 static void __init sio_init(void)
 {
 	struct device_node *root;
+	const char *model = NULL;
 
-	if ((root = of_find_node_by_path("/")) &&
-	    !strncmp(of_get_property(root, "model", NULL),
-			"IBM,LongTrail", 13)) {
-		/* logical device 0 (KBC/Keyboard) */
-		sio_fixup_irq("keyboard", 0, 1, 2);
-		/* select logical device 1 (KBC/Mouse) */
-		sio_fixup_irq("mouse", 1, 12, 2);
-	}
-	of_node_put(root);
+	root = of_find_node_by_path("/");
+	if (root) {
+		model = of_get_property(root, "model", NULL);
+		if (model && !strncmp(model,"IBM,LongTrail", 13)) {
+			/* logical device 0 (KBC/Keyboard) */
+			sio_fixup_irq("keyboard", 0, 1, 2);
+			/* select logical device 1 (KBC/Mouse) */
+			sio_fixup_irq("mouse", 1, 12, 2);
+		}
+		of_node_put(root);
+ 	}
 }
 
 

Re: [PATCH] PPC: CHRP - fix possible NULL pointer dereference

From: Stephen Rothwell <hidden>
Date: 2007-11-22 23:17:11

On Thu, 22 Nov 2007 22:54:23 +0300 Cyrill Gorcunov [off-list ref] wrote:
This patch does fix possible NULL pointer dereference
inside of strncmp() if of_get_property() failed.
Thanks for this.
 static void __init sio_init(void)
 {
 	struct device_node *root;
+	const char *model = NULL;
You don't need this initialization as you always assign the variable
before you use it.
+	root = of_find_node_by_path("/");
+	if (root) {
	if (!root)
		return;

would save a level of indentation. Not important.

-- 
Cheers,
Stephen Rothwell                    sfr@canb.auug.org.au
http://www.canb.auug.org.au/~sfr/

Re: [PATCH] PPC: CHRP - fix possible NULL pointer dereference

From: Cyrill Gorcunov <hidden>
Date: 2007-11-23 04:24:07

On 11/23/07, Stephen Rothwell [off-list ref] wrote:
On Thu, 22 Nov 2007 22:54:23 +0300 Cyrill Gorcunov [off-list ref]
wrote:
quoted
This patch does fix possible NULL pointer dereference
inside of strncmp() if of_get_property() failed.
Thanks for this.
quoted
 static void __init sio_init(void)
 {
  struct device_node *root;
+ const char *model = NULL;
You don't need this initialization as you always assign the variable
before you use it.
quoted
+ root = of_find_node_by_path("/");
+ if (root) {
 if (!root)
  return;

would save a level of indentation. Not important.

--
Cheers,
Stephen Rothwell                    sfr@canb.auug.org.au
http://www.canb.auug.org.au/~sfr/
Oh my :) Thanks. I'll fix it and resend.

Re: [PATCH] PPC: CHRP - fix possible NULL pointer dereference

From: Cyrill Gorcunov <hidden>
Date: 2007-11-23 05:43:18

Here is updated version
---
From: Cyrill Gorcunov <redacted>

This patch does fix possible NULL pointer dereference
inside of strncmp() if of_get_property() failed.

Signed-off-by: Cyrill Gorcunov <redacted>
---
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help