linux-scsi.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/4] scsi: lpfc: Adjustments for two function implementations
@ 2023-12-28 17:20 Markus Elfring
  2023-12-28 17:22 ` [PATCH 1/4] scsi: lpfc: Improve exception handling in lpfc_rcv_plogi() Markus Elfring
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Markus Elfring @ 2023-12-28 17:20 UTC (permalink / raw)
  To: linux-scsi, kernel-janitors, Dick Kennedy, James Smart,
	James E. J. Bottomley, Martin K. Petersen
  Cc: LKML

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Thu, 28 Dec 2023 18:12:34 +0100

A few update suggestions were taken into account
from static source code analysis.

Markus Elfring (4):
  Improve exception handling in lpfc_rcv_plogi()
  Return directly after a failed kzalloc() in lpfc_sli_read_link_ste()
  Delete an unnecessary return statement in lpfc_sli_read_link_ste()
  Delete an unnecessary variable initialisation in lpfc_sli_read_link_ste()

 drivers/scsi/lpfc/lpfc_nportdisc.c | 18 +++++++-----------
 drivers/scsi/lpfc/lpfc_sli.c       |  5 ++---
 2 files changed, 9 insertions(+), 14 deletions(-)

--
2.43.0


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

* [PATCH 1/4] scsi: lpfc: Improve exception handling in lpfc_rcv_plogi()
  2023-12-28 17:20 [PATCH 0/4] scsi: lpfc: Adjustments for two function implementations Markus Elfring
@ 2023-12-28 17:22 ` Markus Elfring
  2023-12-28 17:24 ` [PATCH 2/4] scsi: lpfc: Return directly after a failed kzalloc() in lpfc_sli_read_link_ste() Markus Elfring
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Markus Elfring @ 2023-12-28 17:22 UTC (permalink / raw)
  To: linux-scsi, kernel-janitors, Dick Kennedy, James Smart,
	James E. J. Bottomley, Martin K. Petersen
  Cc: LKML

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Thu, 28 Dec 2023 17:00:07 +0100

The kfree() function was called in one case by the
lpfc_rcv_plogi() function during error handling
even if the passed variable contained a null pointer.
This issue was detected by using the Coccinelle software.

* Thus adjust jump targets.

* Delete three variable assignments and a repeated pointer check
  which became unnecessary with this refactoring.

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
 drivers/scsi/lpfc/lpfc_nportdisc.c | 18 +++++++-----------
 1 file changed, 7 insertions(+), 11 deletions(-)

diff --git a/drivers/scsi/lpfc/lpfc_nportdisc.c b/drivers/scsi/lpfc/lpfc_nportdisc.c
index d9074929fbab..2559f2ac7277 100644
--- a/drivers/scsi/lpfc/lpfc_nportdisc.c
+++ b/drivers/scsi/lpfc/lpfc_nportdisc.c
@@ -459,10 +459,6 @@ lpfc_rcv_plogi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
 	ndlp->nlp_nvme_info &= ~NLP_NVME_NSLER;
 	ndlp->nlp_flag &= ~NLP_FIRSTBURST;

-	login_mbox = NULL;
-	link_mbox = NULL;
-	save_iocb = NULL;
-
 	/* Check for Nport to NPort pt2pt protocol */
 	if ((vport->fc_flag & FC_PT2PT) &&
 	    !(vport->fc_flag & FC_PT2PT_PLOGI)) {
@@ -509,7 +505,7 @@ lpfc_rcv_plogi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
 			link_mbox = mempool_alloc(phba->mbox_mem_pool,
 						  GFP_KERNEL);
 			if (!link_mbox)
-				goto out;
+				goto reject_response;
 			lpfc_config_link(phba, link_mbox);
 			link_mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
 			link_mbox->vport = vport;
@@ -522,7 +518,7 @@ lpfc_rcv_plogi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
 			rc = lpfc_sli_issue_mbox(phba, link_mbox, MBX_NOWAIT);
 			if (rc == MBX_NOT_FINISHED) {
 				mempool_free(link_mbox, phba->mbox_mem_pool);
-				goto out;
+				goto reject_response;
 			}
 		}

@@ -540,11 +536,11 @@ lpfc_rcv_plogi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,

 	login_mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
 	if (!login_mbox)
-		goto out;
+		goto reject_response;

 	save_iocb = kzalloc(sizeof(*save_iocb), GFP_KERNEL);
 	if (!save_iocb)
-		goto out;
+		goto free_mempool;

 	/* Save info from cmd IOCB to be used in rsp after all mbox completes */
 	memcpy((uint8_t *)save_iocb, (uint8_t *)cmdiocb,
@@ -657,9 +653,9 @@ lpfc_rcv_plogi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
 	return 1;
 out:
 	kfree(save_iocb);
-	if (login_mbox)
-		mempool_free(login_mbox, phba->mbox_mem_pool);
-
+free_mempool:
+	mempool_free(login_mbox, phba->mbox_mem_pool);
+reject_response:
 	stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
 	stat.un.b.lsRjtRsnCodeExp = LSEXP_OUT_OF_RESOURCE;
 	lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
--
2.43.0


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

* [PATCH 2/4] scsi: lpfc: Return directly after a failed kzalloc() in lpfc_sli_read_link_ste()
  2023-12-28 17:20 [PATCH 0/4] scsi: lpfc: Adjustments for two function implementations Markus Elfring
  2023-12-28 17:22 ` [PATCH 1/4] scsi: lpfc: Improve exception handling in lpfc_rcv_plogi() Markus Elfring
@ 2023-12-28 17:24 ` Markus Elfring
  2023-12-28 17:26 ` [PATCH 3/4] scsi: lpfc: Delete an unnecessary return statement " Markus Elfring
  2023-12-28 17:28 ` [PATCH 4/4] scsi: lpfc: Delete an unnecessary variable initialisation " Markus Elfring
  3 siblings, 0 replies; 5+ messages in thread
From: Markus Elfring @ 2023-12-28 17:24 UTC (permalink / raw)
  To: linux-scsi, kernel-janitors, Dick Kennedy, James Smart,
	James E. J. Bottomley, Martin K. Petersen
  Cc: LKML

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Thu, 28 Dec 2023 17:13:50 +0100

The kfree() function was called in one case by
the lpfc_sli_read_link_ste() function during error handling
even if the passed variable contained a null pointer.
This issue was detected by using the Coccinelle software.

Thus return directly after a call of the function “kzalloc” failed
at the beginning.

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
 drivers/scsi/lpfc/lpfc_sli.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/scsi/lpfc/lpfc_sli.c b/drivers/scsi/lpfc/lpfc_sli.c
index 706985358c6a..93339425ce3c 100644
--- a/drivers/scsi/lpfc/lpfc_sli.c
+++ b/drivers/scsi/lpfc/lpfc_sli.c
@@ -20701,7 +20701,7 @@ lpfc_sli_read_link_ste(struct lpfc_hba *phba)
 	/* Get adapter Region 23 data */
 	rgn23_data = kzalloc(DMP_RGN23_SIZE, GFP_KERNEL);
 	if (!rgn23_data)
-		goto out;
+		return;

 	if (phba->sli_rev < LPFC_SLI_REV4)
 		data_size = lpfc_sli_get_config_region23(phba, rgn23_data);
--
2.43.0


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

* [PATCH 3/4] scsi: lpfc: Delete an unnecessary return statement in lpfc_sli_read_link_ste()
  2023-12-28 17:20 [PATCH 0/4] scsi: lpfc: Adjustments for two function implementations Markus Elfring
  2023-12-28 17:22 ` [PATCH 1/4] scsi: lpfc: Improve exception handling in lpfc_rcv_plogi() Markus Elfring
  2023-12-28 17:24 ` [PATCH 2/4] scsi: lpfc: Return directly after a failed kzalloc() in lpfc_sli_read_link_ste() Markus Elfring
@ 2023-12-28 17:26 ` Markus Elfring
  2023-12-28 17:28 ` [PATCH 4/4] scsi: lpfc: Delete an unnecessary variable initialisation " Markus Elfring
  3 siblings, 0 replies; 5+ messages in thread
From: Markus Elfring @ 2023-12-28 17:26 UTC (permalink / raw)
  To: linux-scsi, kernel-janitors, Dick Kennedy, James Smart,
	James E. J. Bottomley, Martin K. Petersen
  Cc: LKML

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Thu, 28 Dec 2023 17:45:29 +0100

The script “checkpatch.pl” pointed information out like the following.

WARNING: void function return statements are not generally useful

Thus remove such a statement in the affected function.

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
 drivers/scsi/lpfc/lpfc_sli.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/drivers/scsi/lpfc/lpfc_sli.c b/drivers/scsi/lpfc/lpfc_sli.c
index 93339425ce3c..8de598c9e03b 100644
--- a/drivers/scsi/lpfc/lpfc_sli.c
+++ b/drivers/scsi/lpfc/lpfc_sli.c
@@ -20778,7 +20778,6 @@ lpfc_sli_read_link_ste(struct lpfc_hba *phba)

 out:
 	kfree(rgn23_data);
-	return;
 }

 /**
--
2.43.0


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

* [PATCH 4/4] scsi: lpfc: Delete an unnecessary variable initialisation in lpfc_sli_read_link_ste()
  2023-12-28 17:20 [PATCH 0/4] scsi: lpfc: Adjustments for two function implementations Markus Elfring
                   ` (2 preceding siblings ...)
  2023-12-28 17:26 ` [PATCH 3/4] scsi: lpfc: Delete an unnecessary return statement " Markus Elfring
@ 2023-12-28 17:28 ` Markus Elfring
  3 siblings, 0 replies; 5+ messages in thread
From: Markus Elfring @ 2023-12-28 17:28 UTC (permalink / raw)
  To: linux-scsi, kernel-janitors, Dick Kennedy, James Smart,
	James E. J. Bottomley, Martin K. Petersen
  Cc: LKML

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Thu, 28 Dec 2023 18:00:11 +0100

The variable “rgn23_data” will be reassigned by a following statement.
Thus omit the explicit initialisation at the beginning.

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
 drivers/scsi/lpfc/lpfc_sli.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/scsi/lpfc/lpfc_sli.c b/drivers/scsi/lpfc/lpfc_sli.c
index 8de598c9e03b..1ce5671a7e07 100644
--- a/drivers/scsi/lpfc/lpfc_sli.c
+++ b/drivers/scsi/lpfc/lpfc_sli.c
@@ -20694,7 +20694,7 @@ lpfc_sli4_get_config_region23(struct lpfc_hba *phba, char *rgn23_data)
 void
 lpfc_sli_read_link_ste(struct lpfc_hba *phba)
 {
-	uint8_t *rgn23_data = NULL;
+	uint8_t *rgn23_data;
 	uint32_t if_type, data_size, sub_tlv_len, tlv_offset;
 	uint32_t offset = 0;

--
2.43.0


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

end of thread, other threads:[~2023-12-28 17:28 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-12-28 17:20 [PATCH 0/4] scsi: lpfc: Adjustments for two function implementations Markus Elfring
2023-12-28 17:22 ` [PATCH 1/4] scsi: lpfc: Improve exception handling in lpfc_rcv_plogi() Markus Elfring
2023-12-28 17:24 ` [PATCH 2/4] scsi: lpfc: Return directly after a failed kzalloc() in lpfc_sli_read_link_ste() Markus Elfring
2023-12-28 17:26 ` [PATCH 3/4] scsi: lpfc: Delete an unnecessary return statement " Markus Elfring
2023-12-28 17:28 ` [PATCH 4/4] scsi: lpfc: Delete an unnecessary variable initialisation " Markus Elfring

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).