Skip to contentSkip to conversation

CHRP: Fix possible NULL pointer dereference

PATCH New Miloslav Semler 1 participant 1 message Sep 3, 2008

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 CHRP: Fix possible NULL pointer dereference

This fixes a possible NULL pointer dereference inside of strncmp() if
of_get_property() fails.

This is backport of:
http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=commit;h=9ac71d00398674aaec664f30559f0a21d963862f

Signed-off-by Miloslav Semler

---
diff -uprN linux-2.6.16.62/arch/powerpc/platforms/chrp/setup.c linux-2.6.16.62-new/arch/powerpc/platforms/chrp/setup.c --- linux-2.6.16.62/arch/powerpc/platforms/chrp/setup.c 2008-07-21 21:48:10.000000000 +0200
+++ linux-2.6.16.62-new/arch/powerpc/platforms/chrp/setup.c

2008-09-03 11:33:54.000000000 +0200
@@ -103,7 +103,7 @@ void chrp_show_cpuinfo(struct seq_file *
        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)
@@ -190,9 +190,14 @@ static void __init sio_fixup_irq(const c
 static void __init sio_init(void)
 {
        struct device_node *root;

+ const char *model;

- if ((root = find_path_device("/")) &&
- !strncmp(get_property(root, "model", NULL), "IBM,LongTrail",
13)) {
+ root = find_path_device("/");
+ if(!root)
+ return;
+
+ model = 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) */