Skip to content

Commit 89809b0

Browse files
Varun Prakashmartinkpetersen
authored andcommitted
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>
1 parent a7ccd92 commit 89809b0

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

drivers/scsi/csiostor/csio_hw.c

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2364,8 +2364,8 @@ static int csio_hw_prep_fw(struct csio_hw *hw, struct fw_info *fw_info,
23642364
}
23652365

23662366
/*
2367-
* Returns -EINVAL if attempts to flash the firmware failed
2368-
* else returns 0,
2367+
* Returns -EINVAL if attempts to flash the firmware failed,
2368+
* -ENOMEM if memory allocation failed else returns 0,
23692369
* if flashing was not attempted because the card had the
23702370
* latest firmware ECANCELED is returned
23712371
*/
@@ -2393,6 +2393,13 @@ csio_hw_flash_fw(struct csio_hw *hw, int *reset)
23932393
return -EINVAL;
23942394
}
23952395

2396+
/* allocate memory to read the header of the firmware on the
2397+
* card
2398+
*/
2399+
card_fw = kmalloc(sizeof(*card_fw), GFP_KERNEL);
2400+
if (!card_fw)
2401+
return -ENOMEM;
2402+
23962403
if (csio_is_t5(pci_dev->device & CSIO_HW_CHIP_MASK))
23972404
fw_bin_file = FW_FNAME_T5;
23982405
else
@@ -2406,11 +2413,6 @@ csio_hw_flash_fw(struct csio_hw *hw, int *reset)
24062413
fw_size = fw->size;
24072414
}
24082415

2409-
/* allocate memory to read the header of the firmware on the
2410-
* card
2411-
*/
2412-
card_fw = kmalloc(sizeof(*card_fw), GFP_KERNEL);
2413-
24142416
/* upgrade FW logic */
24152417
ret = csio_hw_prep_fw(hw, fw_info, fw_data, fw_size, card_fw,
24162418
hw->fw_state, reset);

0 commit comments

Comments
 (0)