[SCSI] csiostor: Don't leak mem or fail to release firmware in csio_hw_flash_config()
authorJesper Juhl <jj@chaosbits.net>
Wed, 26 Dec 2012 20:31:51 +0000 (21:31 +0100)
committerJames Bottomley <JBottomley@Parallels.com>
Tue, 29 Jan 2013 23:48:50 +0000 (10:48 +1100)
If kzalloc() or csio_hw_check_fwconfig() fail we may leave the
csio_hw_flash_config() function without freeing allocated memory or
firmware. This should take care of the leaks.

Signed-off-by: Jesper Juhl <jj@chaosbits.net>
Acked-by: Naresh Kumar Inna <naresh@chelsio.com>
Signed-off-by: James Bottomley <JBottomley@Parallels.com>
drivers/scsi/csiostor/csio_hw.c

index 8ecdb94a59f40d30db6d97ed96c63207951a5334..bdd78fb4fc70c5a7c91131e35a94a00e6bf6bb94 100644 (file)
@@ -2131,13 +2131,16 @@ csio_hw_flash_config(struct csio_hw *hw, u32 *fw_cfg_param, char *path)
                value_to_add = 4 - (cf->size % 4);
 
        cfg_data = kzalloc(cf->size+value_to_add, GFP_KERNEL);
-       if (cfg_data == NULL)
-               return -ENOMEM;
+       if (cfg_data == NULL) {
+               ret = -ENOMEM;
+               goto leave;
+       }
 
        memcpy((void *)cfg_data, (const void *)cf->data, cf->size);
-
-       if (csio_hw_check_fwconfig(hw, fw_cfg_param) != 0)
-               return -EINVAL;
+       if (csio_hw_check_fwconfig(hw, fw_cfg_param) != 0) {
+               ret = -EINVAL;
+               goto leave;
+       }
 
        mtype = FW_PARAMS_PARAM_Y_GET(*fw_cfg_param);
        maddr = FW_PARAMS_PARAM_Z_GET(*fw_cfg_param) << 16;
@@ -2149,9 +2152,9 @@ csio_hw_flash_config(struct csio_hw *hw, u32 *fw_cfg_param, char *path)
                strncpy(path, "/lib/firmware/" CSIO_CF_FNAME, 64);
        }
 
+leave:
        kfree(cfg_data);
        release_firmware(cf);
-
        return ret;
 }