diff mbox series

[v2,6/8] qla2xxx: klocwork - pointer may be dereferenced

Message ID 20230607113843.37185-7-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
From: Shreyas Deodhar <sdeodhar@marvell.com>

Klocwork tool reported pointer 'rport' returned
from call to function 'fc_bsg_to_rport' may be
NULL and will be dereferenced.

Add a fix to validate rport before dereferencing.

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

Comments

Himanshu Madhani June 15, 2023, 12:37 a.m. UTC | #1
> On Jun 7, 2023, at 4:38 AM, Nilesh Javali <njavali@marvell.com> wrote:
> 
> From: Shreyas Deodhar <sdeodhar@marvell.com>
> 
> Klocwork tool reported pointer 'rport' returned
> from call to function 'fc_bsg_to_rport' may be
> NULL and will be dereferenced.
> 
> Add a fix to validate rport before dereferencing.
> 
> Cc: stable@vger.kernel.org
> Signed-off-by: Shreyas Deodhar <sdeodhar@marvell.com>
> Signed-off-by: Nilesh Javali <njavali@marvell.com>
> ---
> drivers/scsi/qla2xxx/qla_bsg.c | 2 ++
> 1 file changed, 2 insertions(+)
> 
> diff --git a/drivers/scsi/qla2xxx/qla_bsg.c b/drivers/scsi/qla2xxx/qla_bsg.c
> index c928b27061a9..19bb64bdd88b 100644
> --- a/drivers/scsi/qla2xxx/qla_bsg.c
> +++ b/drivers/scsi/qla2xxx/qla_bsg.c
> @@ -2996,6 +2996,8 @@ qla24xx_bsg_request(struct bsg_job *bsg_job)
> 
> if (bsg_request->msgcode == FC_BSG_RPT_ELS) {
> rport = fc_bsg_to_rport(bsg_job);
> + if (!rport)
> + return ret;
> host = rport_to_shost(rport);
> vha = shost_priv(host);
> } else {
> -- 
> 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 c928b27061a9..19bb64bdd88b 100644
--- a/drivers/scsi/qla2xxx/qla_bsg.c
+++ b/drivers/scsi/qla2xxx/qla_bsg.c
@@ -2996,6 +2996,8 @@  qla24xx_bsg_request(struct bsg_job *bsg_job)
 
 	if (bsg_request->msgcode == FC_BSG_RPT_ELS) {
 		rport = fc_bsg_to_rport(bsg_job);
+		if (!rport)
+			return ret;
 		host = rport_to_shost(rport);
 		vha = shost_priv(host);
 	} else {