Skip to contentSkip to conversation

nvmet: replace kmalloc + memset with kzalloc for data allocation

PATCH Applied Yu-Chun Lin 4 participants 4 messages Nov 30, 2024 – Dec 3, 2024

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 nvmet: replace kmalloc + memset with kzalloc for data allocation

cocci warnings: (new ones prefixed by >>)

Quoted 1 line
Quoted 1 line

drivers/nvme/target/pr.c:831:8-15: WARNING: kzalloc should be used for data, instead of kmalloc/memset

The pattern of using 'kmalloc' followed by 'memset' is replaced with 'kzalloc', which is functionally equivalent to 'kmalloc' + 'memset', but more efficient. 'kzalloc' automatically zeroes the allocated memory, making it a faster and more streamlined solution.

---
build test only.

 drivers/nvme/target/pr.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/nvme/target/pr.c +1 -2
index 25a02b50d9f3..90e9f5bbe581 100644
@@ -828,12 +828,11 @@ static void nvmet_execute_pr_report(struct nvmet_req *req)
 		goto out;
 	}
 
-	data = kmalloc(num_bytes, GFP_KERNEL);
+	data = kzalloc(num_bytes, GFP_KERNEL);
 	if (!data) {
 		status = NVME_SC_INTERNAL;
 		goto out;
 	}
-	memset(data, 0, num_bytes);
 	data->gen = cpu_to_le32(atomic_read(&pr->generation));
 	data->ptpls = 0;
 	ctrl_eds = data->regctl_eds;
Signature · 1 line
2.43.0
Reviewed-by on v1 1/1
#2 lore raw
In reply to Yu-Chun Lin
Quoted 11 lines · Yu-Chun Lin

cocci warnings: (new ones prefixed by >>)

Quoted 1 line
Quoted 1 line

drivers/nvme/target/pr.c:831:8-15: WARNING: kzalloc should be used for data, instead of kmalloc/memset

The pattern of using 'kmalloc' followed by 'memset' is replaced with 'kzalloc', which is functionally equivalent to 'kmalloc' + 'memset', but more efficient. 'kzalloc' automatically zeroes the allocated memory, making it a faster and more streamlined solution.

Looks good.

-ck

maintainer Applied
#3 lore raw
In reply to Yu-Chun Lin
Quoted 7 lines · Yu-Chun Lin

cocci warnings: (new ones prefixed by >>)

Quoted 1 line
Quoted 1 line

drivers/nvme/target/pr.c:831:8-15: WARNING: kzalloc should be used for data, instead of kmalloc/memset

The pattern of using 'kmalloc' followed by 'memset' is replaced with 'kzalloc', which is functionally equivalent to 'kmalloc' + 'memset', but more efficient. 'kzalloc' automatically zeroes the allocated memory, making it a faster and more streamlined solution.

Thanks, applied to nvme-6.13.