cocci.inria.fr archive mirror
 help / color / mirror / Atom feed
* [cocci] [PATCH 0/2] nvmet-fc: Adjustments for nvmet_fc_alloc_ls_iodlist()
@ 2023-12-27 17:14 Markus Elfring
  2023-12-27 17:16 ` [cocci] [PATCH 1/2] nvmet-fc: One function call less in nvmet_fc_alloc_ls_iodlist() after error detection Markus Elfring
  2023-12-27 17:18 ` [cocci] [PATCH 2/2] nvmet-fc: Improve a size determination in nvmet_fc_alloc_ls_iodlist() Markus Elfring
  0 siblings, 2 replies; 3+ messages in thread
From: Markus Elfring @ 2023-12-27 17:14 UTC (permalink / raw)
  To: linux-nvme, kernel-janitors, Chaitanya Kulkarni,
	Christoph Hellwig, James Smart, Sagi Grimberg
  Cc: LKML, cocci

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Wed, 27 Dec 2023 18:09:09 +0100

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

Markus Elfring (2):
  One function call less after error detection
  Improve a size determination

 drivers/nvme/target/fc.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

--
2.43.0


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

* [cocci] [PATCH 1/2] nvmet-fc: One function call less in nvmet_fc_alloc_ls_iodlist() after error detection
  2023-12-27 17:14 [cocci] [PATCH 0/2] nvmet-fc: Adjustments for nvmet_fc_alloc_ls_iodlist() Markus Elfring
@ 2023-12-27 17:16 ` Markus Elfring
  2023-12-27 17:18 ` [cocci] [PATCH 2/2] nvmet-fc: Improve a size determination in nvmet_fc_alloc_ls_iodlist() Markus Elfring
  1 sibling, 0 replies; 3+ messages in thread
From: Markus Elfring @ 2023-12-27 17:16 UTC (permalink / raw)
  To: linux-nvme, kernel-janitors, Chaitanya Kulkarni,
	Christoph Hellwig, James Smart, Sagi Grimberg
  Cc: LKML, cocci

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Wed, 27 Dec 2023 17:52:46 +0100

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

Thus use another label.

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
 drivers/nvme/target/fc.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/nvme/target/fc.c b/drivers/nvme/target/fc.c
index bd59990b5250..856a68404f32 100644
--- a/drivers/nvme/target/fc.c
+++ b/drivers/nvme/target/fc.c
@@ -553,7 +553,7 @@ nvmet_fc_alloc_ls_iodlist(struct nvmet_fc_tgtport *tgtport)
 				       sizeof(union nvmefc_ls_responses),
 				       GFP_KERNEL);
 		if (!iod->rqstbuf)
-			goto out_fail;
+			goto out_delete_entry;

 		iod->rspbuf = (union nvmefc_ls_responses *)&iod->rqstbuf[1];

@@ -568,6 +568,7 @@ nvmet_fc_alloc_ls_iodlist(struct nvmet_fc_tgtport *tgtport)

 out_fail:
 	kfree(iod->rqstbuf);
+out_delete_entry:
 	list_del(&iod->ls_rcv_list);
 	for (iod--, i--; i >= 0; iod--, i--) {
 		fc_dma_unmap_single(tgtport->dev, iod->rspdma,
--
2.43.0


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

* [cocci] [PATCH 2/2] nvmet-fc: Improve a size determination in nvmet_fc_alloc_ls_iodlist()
  2023-12-27 17:14 [cocci] [PATCH 0/2] nvmet-fc: Adjustments for nvmet_fc_alloc_ls_iodlist() Markus Elfring
  2023-12-27 17:16 ` [cocci] [PATCH 1/2] nvmet-fc: One function call less in nvmet_fc_alloc_ls_iodlist() after error detection Markus Elfring
@ 2023-12-27 17:18 ` Markus Elfring
  1 sibling, 0 replies; 3+ messages in thread
From: Markus Elfring @ 2023-12-27 17:18 UTC (permalink / raw)
  To: linux-nvme, kernel-janitors, Chaitanya Kulkarni,
	Christoph Hellwig, James Smart, Sagi Grimberg
  Cc: LKML, cocci

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Wed, 27 Dec 2023 18:03:10 +0100

Replace the specification of a data structure by a pointer dereference
as the parameter for the operator "sizeof" to make the corresponding size
determination a bit safer according to the Linux coding style convention.

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
 drivers/nvme/target/fc.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/nvme/target/fc.c b/drivers/nvme/target/fc.c
index 856a68404f32..ada257b3c681 100644
--- a/drivers/nvme/target/fc.c
+++ b/drivers/nvme/target/fc.c
@@ -537,8 +537,7 @@ nvmet_fc_alloc_ls_iodlist(struct nvmet_fc_tgtport *tgtport)
 	struct nvmet_fc_ls_iod *iod;
 	int i;

-	iod = kcalloc(NVMET_LS_CTX_COUNT, sizeof(struct nvmet_fc_ls_iod),
-			GFP_KERNEL);
+	iod = kcalloc(NVMET_LS_CTX_COUNT, sizeof(*iod), GFP_KERNEL);
 	if (!iod)
 		return -ENOMEM;

--
2.43.0


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

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

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-12-27 17:14 [cocci] [PATCH 0/2] nvmet-fc: Adjustments for nvmet_fc_alloc_ls_iodlist() Markus Elfring
2023-12-27 17:16 ` [cocci] [PATCH 1/2] nvmet-fc: One function call less in nvmet_fc_alloc_ls_iodlist() after error detection Markus Elfring
2023-12-27 17:18 ` [cocci] [PATCH 2/2] nvmet-fc: Improve a size determination in nvmet_fc_alloc_ls_iodlist() 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).