All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/2] scsi: qla2xxx: silence a static checker warning
@ 2023-06-26 10:58 Dan Carpenter
  2023-06-26 10:58 ` [PATCH 2/2] scsi: qla2xxx: Fix error code in qla2x00_start_sp() Dan Carpenter
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Dan Carpenter @ 2023-06-26 10:58 UTC (permalink / raw)
  To: Nilesh Javali
  Cc: GR-QLogic-Storage-Upstream, James E.J. Bottomley,
	Martin K. Petersen, Nathan Chancellor, Nick Desaulniers, Tom Rix,
	linux-scsi, llvm, kernel-janitors

Smatch and Clang both complain that LOGIN_TEMPLATE_SIZE is more than
sizeof(ha->plogi_els_payld.fl_csp).

Smatch warning:
    drivers/scsi/qla2xxx/qla_iocb.c:3075 qla24xx_els_dcmd2_iocb()
    warn: '&ha->plogi_els_payld.fl_csp' sometimes too small '16' size = 112

Clang warning:
    include/linux/fortify-string.h:592:4: error: call to
    '__read_overflow2_field' declared with 'warning' attribute: detected
    read beyond size of field (2nd parameter); maybe use struct_group()?
    [-Werror,-Wattribute-warning]
                        __read_overflow2_field(q_size_field, size);

When I was reading this code I assumed the "- 4" meant that we were
skipping the last 4 bytes but actually it turned out that we are
skipping the first four bytes.

I have re-written it remove the magic numbers, be more clear and
silence the static checker warnings.

Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
---
 drivers/scsi/qla2xxx/qla_def.h  | 1 -
 drivers/scsi/qla2xxx/qla_iocb.c | 3 ++-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/scsi/qla2xxx/qla_def.h b/drivers/scsi/qla2xxx/qla_def.h
index d44c4d37b50b..4ae38305c15a 100644
--- a/drivers/scsi/qla2xxx/qla_def.h
+++ b/drivers/scsi/qla2xxx/qla_def.h
@@ -4462,7 +4462,6 @@ struct qla_hw_data {
 
 	/* n2n */
 	struct fc_els_flogi plogi_els_payld;
-#define LOGIN_TEMPLATE_SIZE (sizeof(struct fc_els_flogi) - 4)
 
 	void            *swl;
 
diff --git a/drivers/scsi/qla2xxx/qla_iocb.c b/drivers/scsi/qla2xxx/qla_iocb.c
index a1675f056a5c..9c70c4e973ee 100644
--- a/drivers/scsi/qla2xxx/qla_iocb.c
+++ b/drivers/scsi/qla2xxx/qla_iocb.c
@@ -3073,7 +3073,8 @@ qla24xx_els_dcmd2_iocb(scsi_qla_host_t *vha, int els_opcode,
 	memset(ptr, 0, sizeof(struct els_plogi_payload));
 	memset(resp_ptr, 0, sizeof(struct els_plogi_payload));
 	memcpy(elsio->u.els_plogi.els_plogi_pyld->data,
-	    &ha->plogi_els_payld.fl_csp, LOGIN_TEMPLATE_SIZE);
+	       (void *)&ha->plogi_els_payld + offsetof(struct fc_els_flogi, fl_csp),
+	       sizeof(ha->plogi_els_payld) - offsetof(struct fc_els_flogi, fl_csp));
 
 	elsio->u.els_plogi.els_cmd = els_opcode;
 	elsio->u.els_plogi.els_plogi_pyld->opcode = els_opcode;
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 2/2] scsi: qla2xxx: Fix error code in qla2x00_start_sp()
  2023-06-26 10:58 [PATCH 1/2] scsi: qla2xxx: silence a static checker warning Dan Carpenter
@ 2023-06-26 10:58 ` Dan Carpenter
  2023-07-06  1:30   ` Martin K. Petersen
  2023-07-06  1:30 ` [PATCH 1/2] scsi: qla2xxx: silence a static checker warning Martin K. Petersen
  2023-07-11 16:31 ` Martin K. Petersen
  2 siblings, 1 reply; 5+ messages in thread
From: Dan Carpenter @ 2023-06-26 10:58 UTC (permalink / raw)
  To: Quinn Tran
  Cc: Nilesh Javali, GR-QLogic-Storage-Upstream, James E.J. Bottomley,
	Martin K. Petersen, Himanshu Madhani, linux-scsi,
	kernel-janitors

This should be negative -EAGAIN instead of positive.  The callers
treat non-zero error codes the same so it doesn't really impact
runtime beyond some trivial differences to debug output.

Fixes: 80676d054e5a ("scsi: qla2xxx: Fix session cleanup hang")
Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
---
 drivers/scsi/qla2xxx/qla_iocb.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/scsi/qla2xxx/qla_iocb.c b/drivers/scsi/qla2xxx/qla_iocb.c
index 9c70c4e973ee..730d8609276c 100644
--- a/drivers/scsi/qla2xxx/qla_iocb.c
+++ b/drivers/scsi/qla2xxx/qla_iocb.c
@@ -3912,7 +3912,7 @@ qla2x00_start_sp(srb_t *sp)
 
 	pkt = __qla2x00_alloc_iocbs(sp->qpair, sp);
 	if (!pkt) {
-		rval = EAGAIN;
+		rval = -EAGAIN;
 		ql_log(ql_log_warn, vha, 0x700c,
 		    "qla2x00_alloc_iocbs failed.\n");
 		goto done;
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH 1/2] scsi: qla2xxx: silence a static checker warning
  2023-06-26 10:58 [PATCH 1/2] scsi: qla2xxx: silence a static checker warning Dan Carpenter
  2023-06-26 10:58 ` [PATCH 2/2] scsi: qla2xxx: Fix error code in qla2x00_start_sp() Dan Carpenter
@ 2023-07-06  1:30 ` Martin K. Petersen
  2023-07-11 16:31 ` Martin K. Petersen
  2 siblings, 0 replies; 5+ messages in thread
From: Martin K. Petersen @ 2023-07-06  1:30 UTC (permalink / raw)
  To: Dan Carpenter
  Cc: Nilesh Javali, GR-QLogic-Storage-Upstream, James E.J. Bottomley,
	Martin K. Petersen, Nathan Chancellor, Nick Desaulniers, Tom Rix,
	linux-scsi, llvm, kernel-janitors


Dan,

> Smatch and Clang both complain that LOGIN_TEMPLATE_SIZE is more than
> sizeof(ha->plogi_els_payld.fl_csp).

Applied to 6.5/scsi-staging, thanks!

-- 
Martin K. Petersen	Oracle Linux Engineering

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH 2/2] scsi: qla2xxx: Fix error code in qla2x00_start_sp()
  2023-06-26 10:58 ` [PATCH 2/2] scsi: qla2xxx: Fix error code in qla2x00_start_sp() Dan Carpenter
@ 2023-07-06  1:30   ` Martin K. Petersen
  0 siblings, 0 replies; 5+ messages in thread
From: Martin K. Petersen @ 2023-07-06  1:30 UTC (permalink / raw)
  To: Dan Carpenter
  Cc: Quinn Tran, Nilesh Javali, GR-QLogic-Storage-Upstream,
	James E.J. Bottomley, Martin K. Petersen, Himanshu Madhani,
	linux-scsi, kernel-janitors


Dan,

> This should be negative -EAGAIN instead of positive. The callers treat
> non-zero error codes the same so it doesn't really impact runtime
> beyond some trivial differences to debug output.

Applied to 6.5/scsi-staging, thanks!

-- 
Martin K. Petersen	Oracle Linux Engineering

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH 1/2] scsi: qla2xxx: silence a static checker warning
  2023-06-26 10:58 [PATCH 1/2] scsi: qla2xxx: silence a static checker warning Dan Carpenter
  2023-06-26 10:58 ` [PATCH 2/2] scsi: qla2xxx: Fix error code in qla2x00_start_sp() Dan Carpenter
  2023-07-06  1:30 ` [PATCH 1/2] scsi: qla2xxx: silence a static checker warning Martin K. Petersen
@ 2023-07-11 16:31 ` Martin K. Petersen
  2 siblings, 0 replies; 5+ messages in thread
From: Martin K. Petersen @ 2023-07-11 16:31 UTC (permalink / raw)
  To: Nilesh Javali, Dan Carpenter
  Cc: Martin K . Petersen, GR-QLogic-Storage-Upstream,
	James E.J. Bottomley, Nathan Chancellor, Nick Desaulniers,
	Tom Rix, linux-scsi, llvm, kernel-janitors

On Mon, 26 Jun 2023 13:58:03 +0300, Dan Carpenter wrote:

> Smatch and Clang both complain that LOGIN_TEMPLATE_SIZE is more than
> sizeof(ha->plogi_els_payld.fl_csp).
> 
> Smatch warning:
>     drivers/scsi/qla2xxx/qla_iocb.c:3075 qla24xx_els_dcmd2_iocb()
>     warn: '&ha->plogi_els_payld.fl_csp' sometimes too small '16' size = 112
> 
> [...]

Applied to 6.5/scsi-fixes, thanks!

[1/2] scsi: qla2xxx: silence a static checker warning
      https://git.kernel.org/mkp/scsi/c/134f66959cd0
[2/2] scsi: qla2xxx: Fix error code in qla2x00_start_sp()
      https://git.kernel.org/mkp/scsi/c/e579b007eff3

-- 
Martin K. Petersen	Oracle Linux Engineering

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2023-07-11 16:32 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-06-26 10:58 [PATCH 1/2] scsi: qla2xxx: silence a static checker warning Dan Carpenter
2023-06-26 10:58 ` [PATCH 2/2] scsi: qla2xxx: Fix error code in qla2x00_start_sp() Dan Carpenter
2023-07-06  1:30   ` Martin K. Petersen
2023-07-06  1:30 ` [PATCH 1/2] scsi: qla2xxx: silence a static checker warning Martin K. Petersen
2023-07-11 16:31 ` Martin K. Petersen

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.