From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-eopbgr720121.outbound.protection.outlook.com ([40.107.72.121]:64608 "EHLO NAM05-CO1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1730352AbeIXUum (ORCPT ); Mon, 24 Sep 2018 16:50:42 -0400 From: Sasha Levin To: "stable@vger.kernel.org" , "linux-kernel@vger.kernel.org" CC: Varun Prakash , "Martin K . Petersen" , Sasha Levin Subject: [PATCH AUTOSEL 4.18 07/76] scsi: csiostor: add a check for NULL pointer after kmalloc() Date: Mon, 24 Sep 2018 14:48:04 +0000 Message-ID: <20180924144751.164410-7-alexander.levin@microsoft.com> References: <20180924144751.164410-1-alexander.levin@microsoft.com> In-Reply-To: <20180924144751.164410-1-alexander.levin@microsoft.com> Content-Language: en-US Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Sender: stable-owner@vger.kernel.org List-ID: From: Varun Prakash [ Upstream commit 89809b028b6f54187b7d81a0c69b35d394c52e62 ] Reported-by: Colin Ian King Signed-off-by: Varun Prakash Signed-off-by: Martin K. Petersen Signed-off-by: Sasha Levin --- 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_h= w.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, } =20 /* - * 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; } =20 + /* allocate memory to read the header of the firmware on the + * card + */ + card_fw =3D 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 =3D FW_FNAME_T5; else @@ -2317,11 +2324,6 @@ csio_hw_flash_fw(struct csio_hw *hw, int *reset) fw_size =3D fw->size; } =20 - /* allocate memory to read the header of the firmware on the - * card - */ - card_fw =3D kmalloc(sizeof(*card_fw), GFP_KERNEL); - /* upgrade FW logic */ ret =3D csio_hw_prep_fw(hw, fw_info, fw_data, fw_size, card_fw, hw->fw_state, reset); --=20 2.17.1