Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752622AbdCDRmq (ORCPT ); Sat, 4 Mar 2017 12:42:46 -0500 Received: from mail-wm0-f54.google.com ([74.125.82.54]:35719 "EHLO mail-wm0-f54.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752442AbdCDRmn (ORCPT ); Sat, 4 Mar 2017 12:42:43 -0500 Subject: Re: [PATCH] scsi: lpfc: sanity check hrq is null before dereferencing it To: Colin King , Dick Kennedy , "James E . J . Bottomley" , "Martin K . Petersen" , linux-scsi@vger.kernel.org References: <20170224135642.5690-1-colin.king@canonical.com> Cc: kernel-janitors@vger.kernel.org, linux-kernel@vger.kernel.org From: James Smart Message-ID: Date: Sat, 4 Mar 2017 09:42:38 -0800 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.7.1 MIME-Version: 1.0 In-Reply-To: <20170224135642.5690-1-colin.king@canonical.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1296 Lines: 45 Looks good. I included it in the lpfc patch set just posted. -- james On 2/24/2017 5:56 AM, Colin King wrote: > From: Colin Ian King > > The sanity check for hrq should be moved to before the deference > of hrq to ensure we don't perform a null pointer deference. > > Detected by CoverityScan, CID#1411650 ("Dereference before null check") > > Signed-off-by: Colin Ian King > --- > drivers/scsi/lpfc/lpfc_sli.c | 10 +++++----- > 1 file changed, 5 insertions(+), 5 deletions(-) > > diff --git a/drivers/scsi/lpfc/lpfc_sli.c b/drivers/scsi/lpfc/lpfc_sli.c > index e43e5e2..1fba5dc 100644 > --- a/drivers/scsi/lpfc/lpfc_sli.c > +++ b/drivers/scsi/lpfc/lpfc_sli.c > @@ -15185,17 +15185,17 @@ lpfc_mrq_create(struct lpfc_hba *phba, struct lpfc_queue **hrqp, > drq = drqp[idx]; > cq = cqp[idx]; > > - if (hrq->entry_count != drq->entry_count) { > - status = -EINVAL; > - goto out; > - } > - > /* sanity check on queue memory */ > if (!hrq || !drq || !cq) { > status = -ENODEV; > goto out; > } > > + if (hrq->entry_count != drq->entry_count) { > + status = -EINVAL; > + goto out; > + } > + > if (idx == 0) { > bf_set(lpfc_mbx_rq_create_num_pages, > &rq_create->u.request,