scsi: fnic: Use vzalloc() instead of vmalloc() and memset(0)
Subsystems (2)
PATCH v2 1/1 scsi: fnic: Use vzalloc() instead of vmalloc() and memset(0)
Use vzalloc() instead of vmalloc() followed by memset(0) to simplify the functions fnic_trace_buf_init() and fnic_fc_trace_init().
Remove unnecessary unsigned long cast.
Compile-tested only.
---
Changes in v2:
- Remove unsigned long cast as suggested by Johannes Thumshirn
- Link to v1: https://lore.kernel.org/linux-kernel/[email protected]/
--- drivers/scsi/fnic/fnic_trace.c | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-)
drivers/scsi/fnic/fnic_trace.c +3 -11
@@ -485,7 +485,7 @@ int fnic_trace_buf_init(void) } fnic_trace_entries.page_offset = -vmalloc (array_size (fnic_max_trace_entries, +vzalloc (array_size (fnic_max_trace_entries,sizeof (unsigned long )));if (!fnic_trace_entries.page_offset) { printk(KERN_ERR PFX "Failed to allocate memory for"
@@ -497,8 +497,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 +557,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)); +vzalloc (array_size (PAGE_SIZE , fnic_fc_trace_max_pages));if (!fnic_fc_ctlr_trace_buf_p) {pr_err ("fnic: Failed to allocate memory for " "FC Control Trace Buf\n" );
@@ -568,12 +565,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, +vzalloc (array_size (fc_trace_max_entries,sizeof (unsigned long )));if (!fc_trace_entries.page_offset) {pr_err ("fnic:Failed to allocate memory for page_offset\n" );
@@ -585,8 +579,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;
Signature · 1 line
2.46.2
Quoted 22 lines · Thorsten Blum
Use
vzalloc()instead ofvmalloc()followed by memset(0) to simplify the functionsfnic_trace_buf_init()andfnic_fc_trace_init().Remove unnecessary unsigned long cast.
Compile-tested only.
Cc Johannes Thumshirn <[email protected]>Signed-off-by Thorsten Blum <[email protected]>---
Changes in v2:
- Remove unsigned long cast as suggested by Johannes Thumshirn
- Link to v1: https://lore.kernel.org/linux-kernel/[email protected]/--- drivers/scsi/fnic/fnic_trace.c | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-)drivers/scsi/fnic/fnic_trace.c +0
-0
drivers/scsi/fnic/fnic_trace.c int fnic_trace_buf_init(void) · line 489
Quoted 6 lines
drivers/scsi/fnic/fnic_trace.c +1
-1@@ -485,7 +485,7 @@ int fnic_trace_buf_init(void) } fnic_trace_entries.page_offset = -vmalloc (array_size (fnic_max_trace_entries, +vzalloc (array_size (fnic_max_trace_entries,sizeof (unsigned long )));
Sorry for not having spotted it earlier, but all those vzalloc(array_size(foo, bar)); calls can be turned into vcalloc(foo, bar);
Quoted 25 lines · Johannes Thumshirn
Quoted 24 lines · Thorsten Blum
Use
vzalloc()instead ofvmalloc()followed by memset(0) to simplify the functionsfnic_trace_buf_init()andfnic_fc_trace_init().Remove unnecessary unsigned long cast.
Compile-tested only.
Cc Johannes Thumshirn <[email protected]>Signed-off-by Thorsten Blum <[email protected]>---
Changes in v2:
- Remove unsigned long cast as suggested by Johannes Thumshirn
- Link to v1: https://lore.kernel.org/linux-kernel/[email protected]/--- drivers/scsi/fnic/fnic_trace.c | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-)drivers/scsi/fnic/fnic_trace.c +0
-0@@ -485,7 +485,7 @@ int fnic_trace_buf_init(void) }
Quoted 7 lines
drivers/scsi/fnic/fnic_trace.c int fnic_trace_buf_init(void) · line 489
Quoted 4 lines
drivers/scsi/fnic/fnic_trace.c +1
-1fnic_trace_entries.page_offset = -vmalloc (array_size (fnic_max_trace_entries, +vzalloc (array_size (fnic_max_trace_entries,sizeof (unsigned long )));Sorry for not having spotted it earlier, but all those
vzalloc(array_size(foo, bar)); calls can be turned intovcalloc(foo, bar);
No worries, but removing the unsigned long casts actually doesn't work:
drivers/scsi/fnic/fnic_trace.c:559:27: error: incompatible pointer to integer conversion assigning to 'unsigned long' from 'typeof (vzalloc_noprof(size_mul(((1UL) << 12), fnic_fc_trace_max_pages)))' (aka 'void *') [-Wint-conversion]
559 | fnic_fc_ctlr_trace_buf_p =
| ^
560 | vzalloc(array_size(PAGE_SIZE, fnic_fc_trace_max_pages));
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~1 error generated.
I'll submit a v3.
Thanks,
Thorsten
kernel test robot
build botkernel test robot noticed the following build errors:
Hi Thorsten,
kernel test robot noticed the following build errors:
[auto build test ERROR on jejb-scsi/for-next]
[also build test ERROR on mkp-scsi/for-next linus/master v6.12-rc2 next-20241008] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Thorsten-Blum/scsi-fnic-Use-vzalloc-instead-of-vmalloc-and-memset-0/20241008-175453 base: https://git.kernel.org/pub/scm/linux/kernel/git/jejb/scsi.git for-next patch link: https://lore.kernel.org/r/20241008095152.1831-2-thorsten.blum%40linux.dev patch subject: [PATCH v2] scsi: fnic: Use vzalloc() instead of vmalloc() and memset(0) config: x86_64-allyesconfig (https://download.01.org/0day-ci/archive/20241009/[email protected]/config) compiler: clang version 18.1.8 (https://github.com/llvm/llvm-project 3b5b5c1ec4a3095ab096dd780e84d7ab81f3d7ff) reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20241009/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All errors (new ones prefixed by >>):
>> drivers/scsi/fnic/fnic_trace.c:559:27: error: incompatible pointer to integer conversion assigning to 'unsigned long' from 'typeof (vzalloc_noprof(size_mul(((1UL) << 12), fnic_fc_trace_max_pages)))' (aka 'void *') [-Wint-conversion]
559 | fnic_fc_ctlr_trace_buf_p =
| ^
560 | vzalloc(array_size(PAGE_SIZE, fnic_fc_trace_max_pages));
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~1 error generated.
Kconfig warnings: (for reference only)
WARNING: unmet direct dependencies detected for MODVERSIONS
Depends on [n]: MODULES [=y] && !COMPILE_TEST [=y]
Selected by [y]:
- RANDSTRUCT_FULL [=y] && (CC_HAS_RANDSTRUCT [=y] || GCC_PLUGINS [=n]) && MODULES [=y]
vim +559 drivers/scsi/fnic/fnic_trace.c
abb14148c0f850 Hiral Shah 2014-04-18 537
abb14148c0f850 Hiral Shah 2014-04-18 538 /*
abb14148c0f850 Hiral Shah 2014-04-18 539 * fnic_fc_ctlr_trace_buf_init -
abb14148c0f850 Hiral Shah 2014-04-18 540 * Initialize trace buffer to log fnic control frames
abb14148c0f850 Hiral Shah 2014-04-18 541 * Description:
abb14148c0f850 Hiral Shah 2014-04-18 542 * Initialize trace buffer data structure by allocating
abb14148c0f850 Hiral Shah 2014-04-18 543 * required memory for trace data as well as for Indexes.
abb14148c0f850 Hiral Shah 2014-04-18 544 * Frame size is 256 bytes and
abb14148c0f850 Hiral Shah 2014-04-18 545 * memory is allocated for 1024 entries of 256 bytes.
abb14148c0f850 Hiral Shah 2014-04-18 546 * Page_offset(Index) is set to the address of trace entry
abb14148c0f850 Hiral Shah 2014-04-18 547 * and page_offset is initialized by adding frame size
abb14148c0f850 Hiral Shah 2014-04-18 548 * to the previous page_offset entry.
abb14148c0f850 Hiral Shah 2014-04-18 549 */
abb14148c0f850 Hiral Shah 2014-04-18 550
abb14148c0f850 Hiral Shah 2014-04-18 551 int fnic_fc_trace_init(void)
abb14148c0f850 Hiral Shah 2014-04-18 552 {
abb14148c0f850 Hiral Shah 2014-04-18 553 unsigned long fc_trace_buf_head;
abb14148c0f850 Hiral Shah 2014-04-18 554 int err = 0;
abb14148c0f850 Hiral Shah 2014-04-18 555 int i;
abb14148c0f850 Hiral Shah 2014-04-18 556
abb14148c0f850 Hiral Shah 2014-04-18 557 fc_trace_max_entries = (fnic_fc_trace_max_pages * PAGE_SIZE)/
abb14148c0f850 Hiral Shah 2014-04-18 558 FC_TRC_SIZE_BYTES;
42bc47b35320e0 Kees Cook 2018-06-12 @559 fnic_fc_ctlr_trace_buf_p =
c9ff42f1a76c7b Thorsten Blum 2024-10-08 560 vzalloc(array_size(PAGE_SIZE, fnic_fc_trace_max_pages));
abb14148c0f850 Hiral Shah 2014-04-18 561 if (!fnic_fc_ctlr_trace_buf_p) {
abb14148c0f850 Hiral Shah 2014-04-18 562 pr_err("fnic: Failed to allocate memory for "
abb14148c0f850 Hiral Shah 2014-04-18 563 "FC Control Trace Buf\n");
abb14148c0f850 Hiral Shah 2014-04-18 564 err = -ENOMEM;
abb14148c0f850 Hiral Shah 2014-04-18 565 goto err_fnic_fc_ctlr_trace_buf_init;
abb14148c0f850 Hiral Shah 2014-04-18 566 }
abb14148c0f850 Hiral Shah 2014-04-18 567
abb14148c0f850 Hiral Shah 2014-04-18 568 /* Allocate memory for page offset */
42bc47b35320e0 Kees Cook 2018-06-12 569 fc_trace_entries.page_offset =
c9ff42f1a76c7b Thorsten Blum 2024-10-08 570 vzalloc(array_size(fc_trace_max_entries,
42bc47b35320e0 Kees Cook 2018-06-12 571 sizeof(unsigned long)));
abb14148c0f850 Hiral Shah 2014-04-18 572 if (!fc_trace_entries.page_offset) {
abb14148c0f850 Hiral Shah 2014-04-18 573 pr_err("fnic:Failed to allocate memory for page_offset\n");
abb14148c0f850 Hiral Shah 2014-04-18 574 if (fnic_fc_ctlr_trace_buf_p) {
abb14148c0f850 Hiral Shah 2014-04-18 575 pr_err("fnic: Freeing FC Control Trace Buf\n");
abb14148c0f850 Hiral Shah 2014-04-18 576 vfree((void *)fnic_fc_ctlr_trace_buf_p);
abb14148c0f850 Hiral Shah 2014-04-18 577 fnic_fc_ctlr_trace_buf_p = 0;
abb14148c0f850 Hiral Shah 2014-04-18 578 }
abb14148c0f850 Hiral Shah 2014-04-18 579 err = -ENOMEM;
abb14148c0f850 Hiral Shah 2014-04-18 580 goto err_fnic_fc_ctlr_trace_buf_init;
abb14148c0f850 Hiral Shah 2014-04-18 581 }
abb14148c0f850 Hiral Shah 2014-04-18 582
abb14148c0f850 Hiral Shah 2014-04-18 583 fc_trace_entries.rd_idx = fc_trace_entries.wr_idx = 0;
abb14148c0f850 Hiral Shah 2014-04-18 584 fc_trace_buf_head = fnic_fc_ctlr_trace_buf_p;
abb14148c0f850 Hiral Shah 2014-04-18 585
abb14148c0f850 Hiral Shah 2014-04-18 586 /*
abb14148c0f850 Hiral Shah 2014-04-18 587 * Set up fc_trace_entries.page_offset field with memory location
abb14148c0f850 Hiral Shah 2014-04-18 588 * for every trace entry
abb14148c0f850 Hiral Shah 2014-04-18 589 */
abb14148c0f850 Hiral Shah 2014-04-18 590 for (i = 0; i < fc_trace_max_entries; i++) {
abb14148c0f850 Hiral Shah 2014-04-18 591 fc_trace_entries.page_offset[i] = fc_trace_buf_head;
abb14148c0f850 Hiral Shah 2014-04-18 592 fc_trace_buf_head += FC_TRC_SIZE_BYTES;
abb14148c0f850 Hiral Shah 2014-04-18 593 }
1dbaa379a41934 Greg Kroah-Hartman 2019-01-22 594 fnic_fc_trace_debugfs_init();
abb14148c0f850 Hiral Shah 2014-04-18 595 pr_info("fnic: Successfully Initialized FC_CTLR Trace Buffer\n");
abb14148c0f850 Hiral Shah 2014-04-18 596 return err;
abb14148c0f850 Hiral Shah 2014-04-18 597
abb14148c0f850 Hiral Shah 2014-04-18 598 err_fnic_fc_ctlr_trace_buf_init:
abb14148c0f850 Hiral Shah 2014-04-18 599 return err;
abb14148c0f850 Hiral Shah 2014-04-18 600 }
abb14148c0f850 Hiral Shah 2014-04-18 601 Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
kernel test robot
build botkernel test robot noticed the following build warnings:
Hi Thorsten,
kernel test robot noticed the following build warnings:
[auto build test WARNING on jejb-scsi/for-next]
[also build test WARNING on mkp-scsi/for-next linus/master v6.12-rc2 next-20241008] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Thorsten-Blum/scsi-fnic-Use-vzalloc-instead-of-vmalloc-and-memset-0/20241008-175453 base: https://git.kernel.org/pub/scm/linux/kernel/git/jejb/scsi.git for-next patch link: https://lore.kernel.org/r/20241008095152.1831-2-thorsten.blum%40linux.dev patch subject: [PATCH v2] scsi: fnic: Use vzalloc() instead of vmalloc() and memset(0) config: i386-randconfig-003-20241009 (https://download.01.org/0day-ci/archive/20241009/[email protected]/config) compiler: gcc-12 (Debian 12.2.0-14) 12.2.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20241009/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All warnings (new ones prefixed by >>):
drivers/scsi/fnic/fnic_trace.c: In function 'fnic_fc_trace_init':
>> drivers/scsi/fnic/fnic_trace.c:559:34: warning: assignment to 'long unsigned int' from 'void *' makes integer from pointer without a cast [-Wint-conversion]
559 | fnic_fc_ctlr_trace_buf_p =
| ^
vim +559 drivers/scsi/fnic/fnic_trace.c
abb14148c0f850 Hiral Shah 2014-04-18 537
abb14148c0f850 Hiral Shah 2014-04-18 538 /*
abb14148c0f850 Hiral Shah 2014-04-18 539 * fnic_fc_ctlr_trace_buf_init -
abb14148c0f850 Hiral Shah 2014-04-18 540 * Initialize trace buffer to log fnic control frames
abb14148c0f850 Hiral Shah 2014-04-18 541 * Description:
abb14148c0f850 Hiral Shah 2014-04-18 542 * Initialize trace buffer data structure by allocating
abb14148c0f850 Hiral Shah 2014-04-18 543 * required memory for trace data as well as for Indexes.
abb14148c0f850 Hiral Shah 2014-04-18 544 * Frame size is 256 bytes and
abb14148c0f850 Hiral Shah 2014-04-18 545 * memory is allocated for 1024 entries of 256 bytes.
abb14148c0f850 Hiral Shah 2014-04-18 546 * Page_offset(Index) is set to the address of trace entry
abb14148c0f850 Hiral Shah 2014-04-18 547 * and page_offset is initialized by adding frame size
abb14148c0f850 Hiral Shah 2014-04-18 548 * to the previous page_offset entry.
abb14148c0f850 Hiral Shah 2014-04-18 549 */
abb14148c0f850 Hiral Shah 2014-04-18 550
abb14148c0f850 Hiral Shah 2014-04-18 551 int fnic_fc_trace_init(void)
abb14148c0f850 Hiral Shah 2014-04-18 552 {
abb14148c0f850 Hiral Shah 2014-04-18 553 unsigned long fc_trace_buf_head;
abb14148c0f850 Hiral Shah 2014-04-18 554 int err = 0;
abb14148c0f850 Hiral Shah 2014-04-18 555 int i;
abb14148c0f850 Hiral Shah 2014-04-18 556
abb14148c0f850 Hiral Shah 2014-04-18 557 fc_trace_max_entries = (fnic_fc_trace_max_pages * PAGE_SIZE)/
abb14148c0f850 Hiral Shah 2014-04-18 558 FC_TRC_SIZE_BYTES;
42bc47b35320e0 Kees Cook 2018-06-12 @559 fnic_fc_ctlr_trace_buf_p =
c9ff42f1a76c7b Thorsten Blum 2024-10-08 560 vzalloc(array_size(PAGE_SIZE, fnic_fc_trace_max_pages));
abb14148c0f850 Hiral Shah 2014-04-18 561 if (!fnic_fc_ctlr_trace_buf_p) {
abb14148c0f850 Hiral Shah 2014-04-18 562 pr_err("fnic: Failed to allocate memory for "
abb14148c0f850 Hiral Shah 2014-04-18 563 "FC Control Trace Buf\n");
abb14148c0f850 Hiral Shah 2014-04-18 564 err = -ENOMEM;
abb14148c0f850 Hiral Shah 2014-04-18 565 goto err_fnic_fc_ctlr_trace_buf_init;
abb14148c0f850 Hiral Shah 2014-04-18 566 }
abb14148c0f850 Hiral Shah 2014-04-18 567
abb14148c0f850 Hiral Shah 2014-04-18 568 /* Allocate memory for page offset */
42bc47b35320e0 Kees Cook 2018-06-12 569 fc_trace_entries.page_offset =
c9ff42f1a76c7b Thorsten Blum 2024-10-08 570 vzalloc(array_size(fc_trace_max_entries,
42bc47b35320e0 Kees Cook 2018-06-12 571 sizeof(unsigned long)));
abb14148c0f850 Hiral Shah 2014-04-18 572 if (!fc_trace_entries.page_offset) {
abb14148c0f850 Hiral Shah 2014-04-18 573 pr_err("fnic:Failed to allocate memory for page_offset\n");
abb14148c0f850 Hiral Shah 2014-04-18 574 if (fnic_fc_ctlr_trace_buf_p) {
abb14148c0f850 Hiral Shah 2014-04-18 575 pr_err("fnic: Freeing FC Control Trace Buf\n");
abb14148c0f850 Hiral Shah 2014-04-18 576 vfree((void *)fnic_fc_ctlr_trace_buf_p);
abb14148c0f850 Hiral Shah 2014-04-18 577 fnic_fc_ctlr_trace_buf_p = 0;
abb14148c0f850 Hiral Shah 2014-04-18 578 }
abb14148c0f850 Hiral Shah 2014-04-18 579 err = -ENOMEM;
abb14148c0f850 Hiral Shah 2014-04-18 580 goto err_fnic_fc_ctlr_trace_buf_init;
abb14148c0f850 Hiral Shah 2014-04-18 581 }
abb14148c0f850 Hiral Shah 2014-04-18 582
abb14148c0f850 Hiral Shah 2014-04-18 583 fc_trace_entries.rd_idx = fc_trace_entries.wr_idx = 0;
abb14148c0f850 Hiral Shah 2014-04-18 584 fc_trace_buf_head = fnic_fc_ctlr_trace_buf_p;
abb14148c0f850 Hiral Shah 2014-04-18 585
abb14148c0f850 Hiral Shah 2014-04-18 586 /*
abb14148c0f850 Hiral Shah 2014-04-18 587 * Set up fc_trace_entries.page_offset field with memory location
abb14148c0f850 Hiral Shah 2014-04-18 588 * for every trace entry
abb14148c0f850 Hiral Shah 2014-04-18 589 */
abb14148c0f850 Hiral Shah 2014-04-18 590 for (i = 0; i < fc_trace_max_entries; i++) {
abb14148c0f850 Hiral Shah 2014-04-18 591 fc_trace_entries.page_offset[i] = fc_trace_buf_head;
abb14148c0f850 Hiral Shah 2014-04-18 592 fc_trace_buf_head += FC_TRC_SIZE_BYTES;
abb14148c0f850 Hiral Shah 2014-04-18 593 }
1dbaa379a41934 Greg Kroah-Hartman 2019-01-22 594 fnic_fc_trace_debugfs_init();
abb14148c0f850 Hiral Shah 2014-04-18 595 pr_info("fnic: Successfully Initialized FC_CTLR Trace Buffer\n");
abb14148c0f850 Hiral Shah 2014-04-18 596 return err;
abb14148c0f850 Hiral Shah 2014-04-18 597
abb14148c0f850 Hiral Shah 2014-04-18 598 err_fnic_fc_ctlr_trace_buf_init:
abb14148c0f850 Hiral Shah 2014-04-18 599 return err;
abb14148c0f850 Hiral Shah 2014-04-18 600 }
abb14148c0f850 Hiral Shah 2014-04-18 601 Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki