scsi: csiostor: add a check for NULL pointer after kmalloc()

Reported-by: Colin Ian King <colin.king@canonical.com>
Signed-off-by: Varun Prakash <varun@chelsio.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
This commit is contained in:
Varun Prakash 2018-08-11 21:03:58 +05:30 коммит произвёл Martin K. Petersen
Родитель a7ccd92c8d
Коммит 89809b028b
1 изменённых файлов: 9 добавлений и 7 удалений

Просмотреть файл

@ -2364,8 +2364,8 @@ bye:
} }
/* /*
* Returns -EINVAL if attempts to flash the firmware failed * Returns -EINVAL if attempts to flash the firmware failed,
* else returns 0, * -ENOMEM if memory allocation failed else returns 0,
* if flashing was not attempted because the card had the * if flashing was not attempted because the card had the
* latest firmware ECANCELED is returned * latest firmware ECANCELED is returned
*/ */
@ -2393,6 +2393,13 @@ csio_hw_flash_fw(struct csio_hw *hw, int *reset)
return -EINVAL; return -EINVAL;
} }
/* allocate memory to read the header of the firmware on the
* card
*/
card_fw = kmalloc(sizeof(*card_fw), GFP_KERNEL);
if (!card_fw)
return -ENOMEM;
if (csio_is_t5(pci_dev->device & CSIO_HW_CHIP_MASK)) if (csio_is_t5(pci_dev->device & CSIO_HW_CHIP_MASK))
fw_bin_file = FW_FNAME_T5; fw_bin_file = FW_FNAME_T5;
else else
@ -2406,11 +2413,6 @@ csio_hw_flash_fw(struct csio_hw *hw, int *reset)
fw_size = fw->size; fw_size = fw->size;
} }
/* allocate memory to read the header of the firmware on the
* card
*/
card_fw = kmalloc(sizeof(*card_fw), GFP_KERNEL);
/* upgrade FW logic */ /* upgrade FW logic */
ret = csio_hw_prep_fw(hw, fw_info, fw_data, fw_size, card_fw, ret = csio_hw_prep_fw(hw, fw_info, fw_data, fw_size, card_fw,
hw->fw_state, reset); hw->fw_state, reset);