Skip to content

Commit 41d826c

Browse files
eleanorLYJkeithbusch
authored andcommitted
nvmet: replace kmalloc + memset with kzalloc for data allocation
cocci warnings: (new ones prefixed by >>) >> 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. Reported-by: kernel test robot <lkp@intel.com> Closes: https://lore.kernel.org/oe-kbuild-all/202411301434.LEckbcWx-lkp@intel.com/ Reviewed-by: Kuan-Wei Chiu <visitorckw@gmail.com> Reviewed-by: Chaitanya Kulkarni <kch@nvidia.com> Reviewed-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Yu-Chun Lin <eleanor15x@gmail.com> Signed-off-by: Keith Busch <kbusch@kernel.org>
1 parent 88c23a3 commit 41d826c

File tree

1 file changed

+1
-2
lines changed
  • drivers/nvme/target

1 file changed

+1
-2
lines changed

drivers/nvme/target/pr.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -828,12 +828,11 @@ static void nvmet_execute_pr_report(struct nvmet_req *req)
828828
goto out;
829829
}
830830

831-
data = kmalloc(num_bytes, GFP_KERNEL);
831+
data = kzalloc(num_bytes, GFP_KERNEL);
832832
if (!data) {
833833
status = NVME_SC_INTERNAL;
834834
goto out;
835835
}
836-
memset(data, 0, num_bytes);
837836
data->gen = cpu_to_le32(atomic_read(&pr->generation));
838837
data->ptpls = 0;
839838
ctrl_eds = data->regctl_eds;

0 commit comments

Comments
 (0)