]> www.infradead.org Git - nvme.git/commitdiff
nvmet: replace kmalloc + memset with kzalloc for data allocation
authorYu-Chun Lin <eleanor15x@gmail.com>
Sat, 30 Nov 2024 17:02:58 +0000 (01:02 +0800)
committerKeith Busch <kbusch@kernel.org>
Wed, 4 Dec 2024 17:20:00 +0000 (09:20 -0800)
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>
drivers/nvme/target/pr.c

index 25a02b50d9f3d37e4e156ef6c26181af4f87eb83..90e9f5bbe581527afcea0141c2edc5d8bed4f8e5 100644 (file)
@@ -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;