public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Dan Carpenter <dan.carpenter@oracle.com>
To: Colin King <colin.king@canonical.com>
Cc: Himanshu Madhani <hmadhani@marvell.com>,
	"James E . J . Bottomley" <jejb@linux.ibm.com>,
	"Martin K . Petersen" <martin.petersen@oracle.com>,
	Quinn Tran <qutran@marvell.com>,
	linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org,
	kernel-janitors@vger.kernel.org
Subject: Re: [PATCH][next] scsi: qla2xxx: fix null pointer dereference on null_fcport
Date: Mon, 6 Jan 2020 17:45:22 +0300	[thread overview]
Message-ID: <20200106144522.GL3911@kadam> (raw)
In-Reply-To: <20200106141144.52888-1-colin.king@canonical.com>

On Mon, Jan 06, 2020 at 02:11:44PM +0000, Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
> 
> Currently several error exit return paths end up passing a null
> new_fcport pointer to function qla2x00_free_fcport and this causes
> a null pointer dereference.  Fix this by moving and renaming the
> exit path label to be after the call to qla2x00_free_fcport to avoid
> the errorneous and unnecessary call to qla2x00_free_fcport.
> 
> Addresses-Coverity: ("Dereference after null check")
> Fixes: 3dae220595ba ("scsi: qla2xxx: Use common routine to free fcport struct")
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> ---
>  drivers/scsi/qla2xxx/qla_init.c | 9 ++++-----
>  1 file changed, 4 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/scsi/qla2xxx/qla_init.c b/drivers/scsi/qla2xxx/qla_init.c
> index a5076f43edea..ed056626d7a3 100644
> --- a/drivers/scsi/qla2xxx/qla_init.c
> +++ b/drivers/scsi/qla2xxx/qla_init.c
> @@ -5108,7 +5108,7 @@ qla2x00_configure_local_loop(scsi_qla_host_t *vha)
>  	rval = qla2x00_get_id_list(vha, ha->gid_list, ha->gid_list_dma,
>  	    &entries);
>  	if (rval != QLA_SUCCESS)
> -		goto cleanup_allocation;
> +		goto exit;
>  
>  	ql_dbg(ql_dbg_disc, vha, 0x2011,
>  	    "Entries in ID list (%d).\n", entries);
> @@ -5138,7 +5138,7 @@ qla2x00_configure_local_loop(scsi_qla_host_t *vha)
>  		ql_log(ql_log_warn, vha, 0x2012,
>  		    "Memory allocation failed for fcport.\n");
>  		rval = QLA_MEMORY_ALLOC_FAILED;
> -		goto cleanup_allocation;
> +		goto exit;
>  	}
>  	new_fcport->flags &= ~FCF_FABRIC_DEVICE;
>  
> @@ -5228,7 +5228,7 @@ qla2x00_configure_local_loop(scsi_qla_host_t *vha)
>  				ql_log(ql_log_warn, vha, 0xd031,
>  				    "Failed to allocate memory for fcport.\n");
>  				rval = QLA_MEMORY_ALLOC_FAILED;
> -				goto cleanup_allocation;
> +				goto exit;

This leaks now.

>  			}
>  			spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
>  			new_fcport->flags &= ~FCF_FABRIC_DEVICE;
> @@ -5239,7 +5239,6 @@ qla2x00_configure_local_loop(scsi_qla_host_t *vha)
>  		/* Base iIDMA settings on HBA port speed. */
>  		fcport->fp_speed = ha->link_data_rate;
>  
> -		found_devs++;

Delete "found_devs" completely.  Also remove the "new_fcport = NULL;"
line because that's not required any more.

regards,
dan carpenter


      reply	other threads:[~2020-01-06 14:45 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-01-06 14:11 [PATCH][next] scsi: qla2xxx: fix null pointer dereference on null_fcport Colin King
2020-01-06 14:45 ` Dan Carpenter [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200106144522.GL3911@kadam \
    --to=dan.carpenter@oracle.com \
    --cc=colin.king@canonical.com \
    --cc=hmadhani@marvell.com \
    --cc=jejb@linux.ibm.com \
    --cc=kernel-janitors@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=martin.petersen@oracle.com \
    --cc=qutran@marvell.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox