]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
scsi: fnic: Use vcalloc() instead of vmalloc() and memset(0)
authorThorsten Blum <thorsten.blum@linux.dev>
Thu, 7 Nov 2024 10:42:59 +0000 (11:42 +0100)
committerMartin K. Petersen <martin.petersen@oracle.com>
Wed, 4 Dec 2024 18:03:27 +0000 (13:03 -0500)
Use vcalloc() instead of vmalloc() followed by memset(0) to simplify the
functions fnic_trace_buf_init() and fnic_fc_trace_init().

Compile-tested only.

Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
Link: https://lore.kernel.org/r/20241107104300.1252-1-thorsten.blum@linux.dev
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
drivers/scsi/fnic/fnic_trace.c

index aaa4ea02fb7cd25cd60542a9d4d096f6bfb6a4a6..e5e0c0492f2356e24b96919626ed646e7a76cef7 100644 (file)
@@ -485,8 +485,7 @@ int fnic_trace_buf_init(void)
        }
 
        fnic_trace_entries.page_offset =
-               vmalloc(array_size(fnic_max_trace_entries,
-                                  sizeof(unsigned long)));
+               vcalloc(fnic_max_trace_entries, sizeof(unsigned long));
        if (!fnic_trace_entries.page_offset) {
                printk(KERN_ERR PFX "Failed to allocate memory for"
                                  " page_offset\n");
@@ -497,8 +496,6 @@ int fnic_trace_buf_init(void)
                err = -ENOMEM;
                goto err_fnic_trace_buf_init;
        }
-       memset((void *)fnic_trace_entries.page_offset, 0,
-                 (fnic_max_trace_entries * sizeof(unsigned long)));
        fnic_trace_entries.wr_idx = fnic_trace_entries.rd_idx = 0;
        fnic_buf_head = fnic_trace_buf_p;
 
@@ -559,8 +556,7 @@ int fnic_fc_trace_init(void)
        fc_trace_max_entries = (fnic_fc_trace_max_pages * PAGE_SIZE)/
                                FC_TRC_SIZE_BYTES;
        fnic_fc_ctlr_trace_buf_p =
-               (unsigned long)vmalloc(array_size(PAGE_SIZE,
-                                                 fnic_fc_trace_max_pages));
+               (unsigned long)vcalloc(fnic_fc_trace_max_pages, PAGE_SIZE);
        if (!fnic_fc_ctlr_trace_buf_p) {
                pr_err("fnic: Failed to allocate memory for "
                       "FC Control Trace Buf\n");
@@ -568,13 +564,9 @@ int fnic_fc_trace_init(void)
                goto err_fnic_fc_ctlr_trace_buf_init;
        }
 
-       memset((void *)fnic_fc_ctlr_trace_buf_p, 0,
-                       fnic_fc_trace_max_pages * PAGE_SIZE);
-
        /* Allocate memory for page offset */
        fc_trace_entries.page_offset =
-               vmalloc(array_size(fc_trace_max_entries,
-                                  sizeof(unsigned long)));
+               vcalloc(fc_trace_max_entries, sizeof(unsigned long));
        if (!fc_trace_entries.page_offset) {
                pr_err("fnic:Failed to allocate memory for page_offset\n");
                if (fnic_fc_ctlr_trace_buf_p) {
@@ -585,8 +577,6 @@ int fnic_fc_trace_init(void)
                err = -ENOMEM;
                goto err_fnic_fc_ctlr_trace_buf_init;
        }
-       memset((void *)fc_trace_entries.page_offset, 0,
-              (fc_trace_max_entries * sizeof(unsigned long)));
 
        fc_trace_entries.rd_idx = fc_trace_entries.wr_idx = 0;
        fc_trace_buf_head = fnic_fc_ctlr_trace_buf_p;