pm80xx : Fix missing NULL pointer checks and memory leaks
authorSuresh Thiagarajan <Suresh.Thiagarajan@pmcs.com>
Fri, 9 May 2014 06:01:01 +0000 (11:31 +0530)
committerChristoph Hellwig <hch@lst.de>
Mon, 19 May 2014 17:12:26 +0000 (19:12 +0200)
Checking return value for the memory allocattion and freeing it
while exiting the function

Signed-off-by: Viswas G <Viswas.G@pmcs.com>
Signed-off-by: Suresh Thiagarajan <Suresh.Thiagarajan@pmcs.com>
Reviewed-by: Tomas Henzl <thenzl@redhat.com>
Acked-by: Jack Wang <xjtuwjp@gmail.com>
Signed-off-by: Christoph Hellwig <hch@lst.de>
drivers/scsi/pm8001/pm8001_ctl.c

index 28b4e813915352674a1a5aaf9e722fed2259f993..fe5eee4d0a1133645116fb7af6e799e0154bddf7 100644 (file)
@@ -395,6 +395,8 @@ static ssize_t pm8001_ctl_bios_version_show(struct device *cdev,
        payload.offset = 0;
        payload.length = 4096;
        payload.func_specific = kzalloc(4096, GFP_KERNEL);
+       if (!payload.func_specific)
+               return -ENOMEM;
        PM8001_CHIP_DISP->get_nvmd_req(pm8001_ha, &payload);
        wait_for_completion(&completion);
        virt_addr = pm8001_ha->memoryMap.region[NVMD].virt_ptr;
@@ -402,6 +404,7 @@ static ssize_t pm8001_ctl_bios_version_show(struct device *cdev,
                bios_index++)
                str += sprintf(str, "%c",
                        *((u8 *)((u8 *)virt_addr+bios_index)));
+       kfree(payload.func_specific);
        return str - buf;
 }
 static DEVICE_ATTR(bios_version, S_IRUGO, pm8001_ctl_bios_version_show, NULL);