lkml.org 
[lkml]   [2018]   [Sep]   [24]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    Patch in this message
    /
    From
    Subject[PATCH AUTOSEL 4.18 07/76] scsi: csiostor: add a check for NULL pointer after kmalloc()
    Date
    From: Varun Prakash <varun@chelsio.com>

    [ Upstream commit 89809b028b6f54187b7d81a0c69b35d394c52e62 ]

    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>
    Signed-off-by: Sasha Levin <alexander.levin@microsoft.com>
    ---
    drivers/scsi/csiostor/csio_hw.c | 16 +++++++++-------
    1 file changed, 9 insertions(+), 7 deletions(-)

    diff --git a/drivers/scsi/csiostor/csio_hw.c b/drivers/scsi/csiostor/csio_hw.c
    index a10cf25ee7f9..1ee255a62f1b 100644
    --- a/drivers/scsi/csiostor/csio_hw.c
    +++ b/drivers/scsi/csiostor/csio_hw.c
    @@ -2275,8 +2275,8 @@ static int csio_hw_prep_fw(struct csio_hw *hw, struct fw_info *fw_info,
    }

    /*
    - * Returns -EINVAL if attempts to flash the firmware failed
    - * else returns 0,
    + * Returns -EINVAL if attempts to flash the firmware failed,
    + * -ENOMEM if memory allocation failed else returns 0,
    * if flashing was not attempted because the card had the
    * latest firmware ECANCELED is returned
    */
    @@ -2304,6 +2304,13 @@ csio_hw_flash_fw(struct csio_hw *hw, int *reset)
    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))
    fw_bin_file = FW_FNAME_T5;
    else
    @@ -2317,11 +2324,6 @@ csio_hw_flash_fw(struct csio_hw *hw, int *reset)
    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 */
    ret = csio_hw_prep_fw(hw, fw_info, fw_data, fw_size, card_fw,
    hw->fw_state, reset);
    --
    2.17.1
    \
     
     \ /
      Last update: 2018-09-24 17:12    [W:2.610 / U:0.420 seconds]
    ©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site