diff mbox series

[v2,4/8] qla2xxx: klocwork - Check valid rport returned by fc_bsg_to_rport

Message ID 20230607113843.37185-5-njavali@marvell.com (mailing list archive)
State Accepted
Headers show
Series qla2xxx klocwork fixes | expand

Commit Message

Nilesh Javali June 7, 2023, 11:38 a.m. UTC
Klocwork reported warning of rport maybe NULL
and will be dereferenced.
rport returned by call to fc_bsg_to_rport could
be NULL and dereferenced.

Check valid rport returned by fc_bsg_to_rport.

Cc: stable@vger.kernel.org
Signed-off-by: Nilesh Javali <njavali@marvell.com>
---
 drivers/scsi/qla2xxx/qla_bsg.c | 4 ++++
 1 file changed, 4 insertions(+)

Comments

Himanshu Madhani June 15, 2023, 12:36 a.m. UTC | #1
> On Jun 7, 2023, at 4:38 AM, Nilesh Javali <njavali@marvell.com> wrote:
> 
> Klocwork reported warning of rport maybe NULL
> and will be dereferenced.
> rport returned by call to fc_bsg_to_rport could
> be NULL and dereferenced.
> 
> Check valid rport returned by fc_bsg_to_rport.
> 
> Cc: stable@vger.kernel.org
> Signed-off-by: Nilesh Javali <njavali@marvell.com>
> ---
> drivers/scsi/qla2xxx/qla_bsg.c | 4 ++++
> 1 file changed, 4 insertions(+)
> 
> diff --git a/drivers/scsi/qla2xxx/qla_bsg.c b/drivers/scsi/qla2xxx/qla_bsg.c
> index dba7bba788d7..c928b27061a9 100644
> --- a/drivers/scsi/qla2xxx/qla_bsg.c
> +++ b/drivers/scsi/qla2xxx/qla_bsg.c
> @@ -283,6 +283,10 @@ qla2x00_process_els(struct bsg_job *bsg_job)
> 
> if (bsg_request->msgcode == FC_BSG_RPT_ELS) {
> rport = fc_bsg_to_rport(bsg_job);
> + if (!rport) {
> + rval = -ENOMEM;
> + goto done;
> + }
> fcport = *(fc_port_t **) rport->dd_data;
> host = rport_to_shost(rport);
> vha = shost_priv(host);
> -- 
> 2.23.1
> 

Reviewed-by: Himanshu Madhani <himanshu.madhani@oracle.com>
diff mbox series

Patch

diff --git a/drivers/scsi/qla2xxx/qla_bsg.c b/drivers/scsi/qla2xxx/qla_bsg.c
index dba7bba788d7..c928b27061a9 100644
--- a/drivers/scsi/qla2xxx/qla_bsg.c
+++ b/drivers/scsi/qla2xxx/qla_bsg.c
@@ -283,6 +283,10 @@  qla2x00_process_els(struct bsg_job *bsg_job)
 
 	if (bsg_request->msgcode == FC_BSG_RPT_ELS) {
 		rport = fc_bsg_to_rport(bsg_job);
+		if (!rport) {
+			rval = -ENOMEM;
+			goto done;
+		}
 		fcport = *(fc_port_t **) rport->dd_data;
 		host = rport_to_shost(rport);
 		vha = shost_priv(host);