2023-12-27 17:15:07

by Markus Elfring

[permalink] [raw]
Subject: [PATCH 0/2] nvmet-fc: Adjustments for nvmet_fc_alloc_ls_iodlist()

From: Markus Elfring <[email protected]>
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



2023-12-27 17:16:58

by Markus Elfring

[permalink] [raw]
Subject: [PATCH 1/2] nvmet-fc: One function call less in nvmet_fc_alloc_ls_iodlist() after error detection

From: Markus Elfring <[email protected]>
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 <[email protected]>
---
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


2023-12-27 17:18:43

by Markus Elfring

[permalink] [raw]
Subject: [PATCH 2/2] nvmet-fc: Improve a size determination in nvmet_fc_alloc_ls_iodlist()

From: Markus Elfring <[email protected]>
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 <[email protected]>
---
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


2024-01-02 21:19:40

by Keith Busch

[permalink] [raw]
Subject: Re: [PATCH 0/2] nvmet-fc: Adjustments for nvmet_fc_alloc_ls_iodlist()

On Wed, Dec 27, 2023 at 06:14:35PM +0100, Markus Elfring wrote:
> From: Markus Elfring <[email protected]>
> Date: Wed, 27 Dec 2023 18:09:09 +0100
>
> A few update suggestions were taken into account
> from static source code analysis.

These look good to me.

Reviewed-by: Keith Busch <[email protected]>