[POWERPC] Sky Cpu and Nexus: check for platform_get_resource retcode
authorCyrill Gorcunov <gorcunov@gmail.com>
Tue, 2 Oct 2007 20:30:06 +0000 (13:30 -0700)
committerPaul Mackerras <paulus@samba.org>
Wed, 3 Oct 2007 02:02:44 +0000 (12:02 +1000)
Add adds checking for platform_get_resource() return code to prevent
possible NULL pointer usage.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: Kumar Gala <galak@gate.crashing.org>
Cc: Brian Waite <waite@skycomputers.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Paul Mackerras <paulus@samba.org>
drivers/misc/hdpuftrs/hdpu_cpustate.c
drivers/misc/hdpuftrs/hdpu_nexus.c

index b5c6f21..b16742c 100644 (file)
@@ -194,6 +194,11 @@ static int hdpu_cpustate_probe(struct platform_device *pdev)
        int ret;
 
        res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+       if (!res) {
+               printk(KERN_ERR "sky_cpustate: "
+                      "Invalid memory resource.\n");
+               return -EINVAL;
+       }
        cpustate.set_addr = (unsigned long *)res->start;
        cpustate.clr_addr = (unsigned long *)res->end - 1;
 
index fda9998..01bc917 100644 (file)
@@ -62,6 +62,11 @@ static int hdpu_nexus_probe(struct platform_device *pdev)
        int *nexus_id_addr;
 
        res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+       if (!res) {
+               printk(KERN_ERR "sky_nexus: "
+                      "Invalid memory resource.\n");
+               return -EINVAL;
+       }
        nexus_id_addr = ioremap(res->start,
                                (unsigned long)(res->end - res->start));
        if (nexus_id_addr) {
@@ -69,7 +74,7 @@ static int hdpu_nexus_probe(struct platform_device *pdev)
                chassis_id = *nexus_id_addr & 0xff;
                iounmap(nexus_id_addr);
        } else {
-               printk(KERN_ERR "Could not map slot id\n");
+               printk(KERN_ERR "sky_nexus: Could not map slot id\n");
        }
 
        hdpu_slot_id = create_proc_entry("sky_slot_id", 0666, &proc_root);