Skip to content

Commit

Permalink
nvmet: replace kmalloc + memset with kzalloc for data allocation
Browse files Browse the repository at this point in the history
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 <[email protected]>
Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
Reviewed-by: Kuan-Wei Chiu <[email protected]>
Reviewed-by: Chaitanya Kulkarni <[email protected]>
Reviewed-by: Christoph Hellwig <[email protected]>
Signed-off-by: Yu-Chun Lin <[email protected]>
Signed-off-by: Keith Busch <[email protected]>
  • Loading branch information
eleanorLYJ authored and keithbusch committed Dec 4, 2024
1 parent 88c23a3 commit 41d826c
Showing 1 changed file with 1 addition and 2 deletions.
3 changes: 1 addition & 2 deletions drivers/nvme/target/pr.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 41d826c

Please sign in to comment.