public inbox for linux-scsi@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] scsi: be2iscsi: kzalloc + kcalloc to kzalloc_flex
@ 2026-03-20  1:09 Rosen Penev
  2026-03-20 18:44 ` Kees Cook
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Rosen Penev @ 2026-03-20  1:09 UTC (permalink / raw)
  To: linux-scsi
  Cc: Ketan Mukadam, James E.J. Bottomley, Martin K. Petersen,
	Kees Cook, Gustavo A. R. Silva, open list,
	open list:KERNEL HARDENING (not covered by other areas):Keyword:b__counted_by(_le|_be)?b

Simplifies allocation by using a flexible array member

Added __counted_by for extra runtime analysis.

Signed-off-by: Rosen Penev <rosenp@gmail.com>
---
 drivers/scsi/be2iscsi/be_main.c | 27 ++-------------------------
 drivers/scsi/be2iscsi/be_main.h |  4 ++--
 2 files changed, 4 insertions(+), 27 deletions(-)

diff --git a/drivers/scsi/be2iscsi/be_main.c b/drivers/scsi/be2iscsi/be_main.c
index fd18d4d3d219..782a21af01a3 100644
--- a/drivers/scsi/be2iscsi/be_main.c
+++ b/drivers/scsi/be2iscsi/be_main.c
@@ -2470,22 +2470,15 @@ static int beiscsi_alloc_mem(struct beiscsi_hba *phba)
 	struct mem_array *mem_arr, *mem_arr_orig;
 	unsigned int i, j, alloc_size, curr_alloc_size;
 
-	phba->phwi_ctrlr = kzalloc(phba->params.hwi_ws_sz, GFP_KERNEL);
+	phba->phwi_ctrlr = kzalloc_flex(*phba->phwi_ctrlr, wrb_context, phba->params.cxns_per_ctrl);
 	if (!phba->phwi_ctrlr)
 		return -ENOMEM;
 
 	/* Allocate memory for wrb_context */
 	phwi_ctrlr = phba->phwi_ctrlr;
-	phwi_ctrlr->wrb_context = kzalloc_objs(struct hwi_wrb_context,
-					       phba->params.cxns_per_ctrl);
-	if (!phwi_ctrlr->wrb_context) {
-		kfree(phba->phwi_ctrlr);
-		return -ENOMEM;
-	}
 
 	phba->init_mem = kzalloc_objs(*mem_descr, SE_MEM_MAX);
 	if (!phba->init_mem) {
-		kfree(phwi_ctrlr->wrb_context);
 		kfree(phba->phwi_ctrlr);
 		return -ENOMEM;
 	}
@@ -2493,7 +2486,6 @@ static int beiscsi_alloc_mem(struct beiscsi_hba *phba)
 	mem_arr_orig = kmalloc_objs(*mem_arr_orig, BEISCSI_MAX_FRAGS_INIT);
 	if (!mem_arr_orig) {
 		kfree(phba->init_mem);
-		kfree(phwi_ctrlr->wrb_context);
 		kfree(phba->phwi_ctrlr);
 		return -ENOMEM;
 	}
@@ -3992,25 +3984,12 @@ static int hba_setup_cid_tbls(struct beiscsi_hba *phba)
 
 	for (ulp_num = 0; ulp_num < BEISCSI_ULP_COUNT; ulp_num++) {
 		if (test_bit(ulp_num, (void *)&phba->fw_config.ulp_supported)) {
-			ptr_cid_info = kzalloc_obj(struct ulp_cid_info);
-
+			ptr_cid_info = kzalloc_flex(*ptr_cid_info, cid_array, BEISCSI_GET_CID_COUNT(phba, ulp_num));
 			if (!ptr_cid_info) {
 				ret = -ENOMEM;
 				goto free_memory;
 			}
 
-			/* Allocate memory for CID array */
-			ptr_cid_info->cid_array =
-				kcalloc(BEISCSI_GET_CID_COUNT(phba, ulp_num),
-					sizeof(*ptr_cid_info->cid_array),
-					GFP_KERNEL);
-			if (!ptr_cid_info->cid_array) {
-				kfree(ptr_cid_info);
-				ptr_cid_info = NULL;
-				ret = -ENOMEM;
-
-				goto free_memory;
-			}
 			ptr_cid_info->avlbl_cids = BEISCSI_GET_CID_COUNT(
 						   phba, ulp_num);
 
@@ -4061,7 +4040,6 @@ static int hba_setup_cid_tbls(struct beiscsi_hba *phba)
 			ptr_cid_info = phba->cid_array_info[ulp_num];
 
 			if (ptr_cid_info) {
-				kfree(ptr_cid_info->cid_array);
 				kfree(ptr_cid_info);
 				phba->cid_array_info[ulp_num] = NULL;
 			}
@@ -4175,7 +4153,6 @@ static void beiscsi_cleanup_port(struct beiscsi_hba *phba)
 			ptr_cid_info = phba->cid_array_info[ulp_num];
 
 			if (ptr_cid_info) {
-				kfree(ptr_cid_info->cid_array);
 				kfree(ptr_cid_info);
 				phba->cid_array_info[ulp_num] = NULL;
 			}
diff --git a/drivers/scsi/be2iscsi/be_main.h b/drivers/scsi/be2iscsi/be_main.h
index 71c95d144560..77c9b1a1a488 100644
--- a/drivers/scsi/be2iscsi/be_main.h
+++ b/drivers/scsi/be2iscsi/be_main.h
@@ -241,10 +241,10 @@ struct hwi_wrb_context {
 };
 
 struct ulp_cid_info {
-	unsigned short *cid_array;
 	unsigned short avlbl_cids;
 	unsigned short cid_alloc;
 	unsigned short cid_free;
+	unsigned short cid_array[] __counted_by(avlbl_cids);
 };
 
 #include "be.h"
@@ -968,10 +968,10 @@ struct be_ring {
 };
 
 struct hwi_controller {
-	struct hwi_wrb_context *wrb_context;
 	struct be_ring default_pdu_hdr[BEISCSI_ULP_COUNT];
 	struct be_ring default_pdu_data[BEISCSI_ULP_COUNT];
 	struct hwi_context_memory *phwi_ctxt;
+	struct hwi_wrb_context wrb_context[];
 };
 
 enum hwh_type_enum {
-- 
2.53.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] scsi: be2iscsi: kzalloc + kcalloc to kzalloc_flex
  2026-03-20  1:09 [PATCH] scsi: be2iscsi: kzalloc + kcalloc to kzalloc_flex Rosen Penev
@ 2026-03-20 18:44 ` Kees Cook
  2026-03-21 11:50 ` kernel test robot
  2026-03-21 16:27 ` kernel test robot
  2 siblings, 0 replies; 4+ messages in thread
From: Kees Cook @ 2026-03-20 18:44 UTC (permalink / raw)
  To: Rosen Penev
  Cc: linux-scsi, Ketan Mukadam, James E.J. Bottomley,
	Martin K. Petersen, Gustavo A. R. Silva, open list,
	open list:KERNEL HARDENING (not covered by other areas):Keyword:b__counted_by(_le|_be)?b

On Thu, Mar 19, 2026 at 06:09:57PM -0700, Rosen Penev wrote:
> Simplifies allocation by using a flexible array member
> 
> Added __counted_by for extra runtime analysis.

This is make changes to 2 structs. For easier review, I'd split this
patch up. For the wrb_context change, perhaps explain why a __counted_by
is not added.

-Kees

> 
> Signed-off-by: Rosen Penev <rosenp@gmail.com>
> ---
>  drivers/scsi/be2iscsi/be_main.c | 27 ++-------------------------
>  drivers/scsi/be2iscsi/be_main.h |  4 ++--
>  2 files changed, 4 insertions(+), 27 deletions(-)
> 
> diff --git a/drivers/scsi/be2iscsi/be_main.c b/drivers/scsi/be2iscsi/be_main.c
> index fd18d4d3d219..782a21af01a3 100644
> --- a/drivers/scsi/be2iscsi/be_main.c
> +++ b/drivers/scsi/be2iscsi/be_main.c
> @@ -2470,22 +2470,15 @@ static int beiscsi_alloc_mem(struct beiscsi_hba *phba)
>  	struct mem_array *mem_arr, *mem_arr_orig;
>  	unsigned int i, j, alloc_size, curr_alloc_size;
>  
> -	phba->phwi_ctrlr = kzalloc(phba->params.hwi_ws_sz, GFP_KERNEL);
> +	phba->phwi_ctrlr = kzalloc_flex(*phba->phwi_ctrlr, wrb_context, phba->params.cxns_per_ctrl);
>  	if (!phba->phwi_ctrlr)
>  		return -ENOMEM;
>  
>  	/* Allocate memory for wrb_context */
>  	phwi_ctrlr = phba->phwi_ctrlr;
> -	phwi_ctrlr->wrb_context = kzalloc_objs(struct hwi_wrb_context,
> -					       phba->params.cxns_per_ctrl);
> -	if (!phwi_ctrlr->wrb_context) {
> -		kfree(phba->phwi_ctrlr);
> -		return -ENOMEM;
> -	}
>  
>  	phba->init_mem = kzalloc_objs(*mem_descr, SE_MEM_MAX);
>  	if (!phba->init_mem) {
> -		kfree(phwi_ctrlr->wrb_context);
>  		kfree(phba->phwi_ctrlr);
>  		return -ENOMEM;
>  	}
> @@ -2493,7 +2486,6 @@ static int beiscsi_alloc_mem(struct beiscsi_hba *phba)
>  	mem_arr_orig = kmalloc_objs(*mem_arr_orig, BEISCSI_MAX_FRAGS_INIT);
>  	if (!mem_arr_orig) {
>  		kfree(phba->init_mem);
> -		kfree(phwi_ctrlr->wrb_context);
>  		kfree(phba->phwi_ctrlr);
>  		return -ENOMEM;
>  	}
> @@ -3992,25 +3984,12 @@ static int hba_setup_cid_tbls(struct beiscsi_hba *phba)
>  
>  	for (ulp_num = 0; ulp_num < BEISCSI_ULP_COUNT; ulp_num++) {
>  		if (test_bit(ulp_num, (void *)&phba->fw_config.ulp_supported)) {
> -			ptr_cid_info = kzalloc_obj(struct ulp_cid_info);
> -
> +			ptr_cid_info = kzalloc_flex(*ptr_cid_info, cid_array, BEISCSI_GET_CID_COUNT(phba, ulp_num));
>  			if (!ptr_cid_info) {
>  				ret = -ENOMEM;
>  				goto free_memory;
>  			}
>  
> -			/* Allocate memory for CID array */
> -			ptr_cid_info->cid_array =
> -				kcalloc(BEISCSI_GET_CID_COUNT(phba, ulp_num),
> -					sizeof(*ptr_cid_info->cid_array),
> -					GFP_KERNEL);
> -			if (!ptr_cid_info->cid_array) {
> -				kfree(ptr_cid_info);
> -				ptr_cid_info = NULL;
> -				ret = -ENOMEM;
> -
> -				goto free_memory;
> -			}
>  			ptr_cid_info->avlbl_cids = BEISCSI_GET_CID_COUNT(
>  						   phba, ulp_num);
>  
> @@ -4061,7 +4040,6 @@ static int hba_setup_cid_tbls(struct beiscsi_hba *phba)
>  			ptr_cid_info = phba->cid_array_info[ulp_num];
>  
>  			if (ptr_cid_info) {
> -				kfree(ptr_cid_info->cid_array);
>  				kfree(ptr_cid_info);
>  				phba->cid_array_info[ulp_num] = NULL;
>  			}
> @@ -4175,7 +4153,6 @@ static void beiscsi_cleanup_port(struct beiscsi_hba *phba)
>  			ptr_cid_info = phba->cid_array_info[ulp_num];
>  
>  			if (ptr_cid_info) {
> -				kfree(ptr_cid_info->cid_array);
>  				kfree(ptr_cid_info);
>  				phba->cid_array_info[ulp_num] = NULL;
>  			}
> diff --git a/drivers/scsi/be2iscsi/be_main.h b/drivers/scsi/be2iscsi/be_main.h
> index 71c95d144560..77c9b1a1a488 100644
> --- a/drivers/scsi/be2iscsi/be_main.h
> +++ b/drivers/scsi/be2iscsi/be_main.h
> @@ -241,10 +241,10 @@ struct hwi_wrb_context {
>  };
>  
>  struct ulp_cid_info {
> -	unsigned short *cid_array;
>  	unsigned short avlbl_cids;
>  	unsigned short cid_alloc;
>  	unsigned short cid_free;
> +	unsigned short cid_array[] __counted_by(avlbl_cids);
>  };
>  
>  #include "be.h"
> @@ -968,10 +968,10 @@ struct be_ring {
>  };
>  
>  struct hwi_controller {
> -	struct hwi_wrb_context *wrb_context;
>  	struct be_ring default_pdu_hdr[BEISCSI_ULP_COUNT];
>  	struct be_ring default_pdu_data[BEISCSI_ULP_COUNT];
>  	struct hwi_context_memory *phwi_ctxt;
> +	struct hwi_wrb_context wrb_context[];
>  };
>  
>  enum hwh_type_enum {
> -- 
> 2.53.0
> 

-- 
Kees Cook

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] scsi: be2iscsi: kzalloc + kcalloc to kzalloc_flex
  2026-03-20  1:09 [PATCH] scsi: be2iscsi: kzalloc + kcalloc to kzalloc_flex Rosen Penev
  2026-03-20 18:44 ` Kees Cook
@ 2026-03-21 11:50 ` kernel test robot
  2026-03-21 16:27 ` kernel test robot
  2 siblings, 0 replies; 4+ messages in thread
From: kernel test robot @ 2026-03-21 11:50 UTC (permalink / raw)
  To: Rosen Penev, linux-scsi

Hi Rosen,

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 next-20260320]
[cannot apply to linus/master v6.16-rc1]
[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/Rosen-Penev/scsi-be2iscsi-kzalloc-kcalloc-to-kzalloc_flex/20260321-145321
base:   https://git.kernel.org/pub/scm/linux/kernel/git/jejb/scsi.git for-next
patch link:    https://lore.kernel.org/r/20260320010957.32355-1-rosenp%40gmail.com
patch subject: [PATCH] scsi: be2iscsi: kzalloc + kcalloc to kzalloc_flex
config: x86_64-kexec (https://download.01.org/0day-ci/archive/20260321/202603211230.849vqwiI-lkp@intel.com/config)
compiler: clang version 20.1.8 (https://github.com/llvm/llvm-project 87f0227cb60147a26a1eeb4fb06e3b505e9c7261)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260321/202603211230.849vqwiI-lkp@intel.com/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 <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202603211230.849vqwiI-lkp@intel.com/

All warnings (new ones prefixed by >>):

>> drivers/scsi/be2iscsi/be_main.c:2468:25: warning: variable 'phwi_ctrlr' set but not used [-Wunused-but-set-variable]
    2468 |         struct hwi_controller *phwi_ctrlr;
         |                                ^
   1 warning generated.


vim +/phwi_ctrlr +2468 drivers/scsi/be2iscsi/be_main.c

6733b39a1301b0 Jayamohan Kallickal 2009-09-05  2464  
6733b39a1301b0 Jayamohan Kallickal 2009-09-05  2465  static int beiscsi_alloc_mem(struct beiscsi_hba *phba)
6733b39a1301b0 Jayamohan Kallickal 2009-09-05  2466  {
6733b39a1301b0 Jayamohan Kallickal 2009-09-05  2467  	dma_addr_t bus_add;
a7909b396ba79a Jayamohan Kallickal 2013-04-05 @2468  	struct hwi_controller *phwi_ctrlr;
a7909b396ba79a Jayamohan Kallickal 2013-04-05  2469  	struct be_mem_descriptor *mem_descr;
6733b39a1301b0 Jayamohan Kallickal 2009-09-05  2470  	struct mem_array *mem_arr, *mem_arr_orig;
6733b39a1301b0 Jayamohan Kallickal 2009-09-05  2471  	unsigned int i, j, alloc_size, curr_alloc_size;
6733b39a1301b0 Jayamohan Kallickal 2009-09-05  2472  
7051e9804743be Rosen Penev         2026-03-19  2473  	phba->phwi_ctrlr = kzalloc_flex(*phba->phwi_ctrlr, wrb_context, phba->params.cxns_per_ctrl);
6733b39a1301b0 Jayamohan Kallickal 2009-09-05  2474  	if (!phba->phwi_ctrlr)
6733b39a1301b0 Jayamohan Kallickal 2009-09-05  2475  		return -ENOMEM;
6733b39a1301b0 Jayamohan Kallickal 2009-09-05  2476  
a7909b396ba79a Jayamohan Kallickal 2013-04-05  2477  	/* Allocate memory for wrb_context */
a7909b396ba79a Jayamohan Kallickal 2013-04-05  2478  	phwi_ctrlr = phba->phwi_ctrlr;
a7909b396ba79a Jayamohan Kallickal 2013-04-05  2479  
bf4afc53b77aea Linus Torvalds      2026-02-21  2480  	phba->init_mem = kzalloc_objs(*mem_descr, SE_MEM_MAX);
6733b39a1301b0 Jayamohan Kallickal 2009-09-05  2481  	if (!phba->init_mem) {
6733b39a1301b0 Jayamohan Kallickal 2009-09-05  2482  		kfree(phba->phwi_ctrlr);
6733b39a1301b0 Jayamohan Kallickal 2009-09-05  2483  		return -ENOMEM;
6733b39a1301b0 Jayamohan Kallickal 2009-09-05  2484  	}
6733b39a1301b0 Jayamohan Kallickal 2009-09-05  2485  
32a92f8c893269 Linus Torvalds      2026-02-21  2486  	mem_arr_orig = kmalloc_objs(*mem_arr_orig, BEISCSI_MAX_FRAGS_INIT);
6733b39a1301b0 Jayamohan Kallickal 2009-09-05  2487  	if (!mem_arr_orig) {
6733b39a1301b0 Jayamohan Kallickal 2009-09-05  2488  		kfree(phba->init_mem);
6733b39a1301b0 Jayamohan Kallickal 2009-09-05  2489  		kfree(phba->phwi_ctrlr);
6733b39a1301b0 Jayamohan Kallickal 2009-09-05  2490  		return -ENOMEM;
6733b39a1301b0 Jayamohan Kallickal 2009-09-05  2491  	}
6733b39a1301b0 Jayamohan Kallickal 2009-09-05  2492  
6733b39a1301b0 Jayamohan Kallickal 2009-09-05  2493  	mem_descr = phba->init_mem;
6733b39a1301b0 Jayamohan Kallickal 2009-09-05  2494  	for (i = 0; i < SE_MEM_MAX; i++) {
8a86e8336f37fd Jayamohan Kallickal 2013-09-28  2495  		if (!phba->mem_req[i]) {
8a86e8336f37fd Jayamohan Kallickal 2013-09-28  2496  			mem_descr->mem_array = NULL;
8a86e8336f37fd Jayamohan Kallickal 2013-09-28  2497  			mem_descr++;
8a86e8336f37fd Jayamohan Kallickal 2013-09-28  2498  			continue;
8a86e8336f37fd Jayamohan Kallickal 2013-09-28  2499  		}
8a86e8336f37fd Jayamohan Kallickal 2013-09-28  2500  
6733b39a1301b0 Jayamohan Kallickal 2009-09-05  2501  		j = 0;
6733b39a1301b0 Jayamohan Kallickal 2009-09-05  2502  		mem_arr = mem_arr_orig;
6733b39a1301b0 Jayamohan Kallickal 2009-09-05  2503  		alloc_size = phba->mem_req[i];
6733b39a1301b0 Jayamohan Kallickal 2009-09-05  2504  		memset(mem_arr, 0, sizeof(struct mem_array) *
6733b39a1301b0 Jayamohan Kallickal 2009-09-05  2505  		       BEISCSI_MAX_FRAGS_INIT);
6733b39a1301b0 Jayamohan Kallickal 2009-09-05  2506  		curr_alloc_size = min(be_max_phys_size * 1024, alloc_size);
6733b39a1301b0 Jayamohan Kallickal 2009-09-05  2507  		do {
26a4c991af99f1 Christoph Hellwig   2018-10-10  2508  			mem_arr->virtual_address =
26a4c991af99f1 Christoph Hellwig   2018-10-10  2509  				dma_alloc_coherent(&phba->pcidev->dev,
26a4c991af99f1 Christoph Hellwig   2018-10-10  2510  					curr_alloc_size, &bus_add, GFP_KERNEL);
6733b39a1301b0 Jayamohan Kallickal 2009-09-05  2511  			if (!mem_arr->virtual_address) {
6733b39a1301b0 Jayamohan Kallickal 2009-09-05  2512  				if (curr_alloc_size <= BE_MIN_MEM_SIZE)
6733b39a1301b0 Jayamohan Kallickal 2009-09-05  2513  					goto free_mem;
6733b39a1301b0 Jayamohan Kallickal 2009-09-05  2514  				if (curr_alloc_size -
6733b39a1301b0 Jayamohan Kallickal 2009-09-05  2515  					rounddown_pow_of_two(curr_alloc_size))
6733b39a1301b0 Jayamohan Kallickal 2009-09-05  2516  					curr_alloc_size = rounddown_pow_of_two
6733b39a1301b0 Jayamohan Kallickal 2009-09-05  2517  							     (curr_alloc_size);
6733b39a1301b0 Jayamohan Kallickal 2009-09-05  2518  				else
6733b39a1301b0 Jayamohan Kallickal 2009-09-05  2519  					curr_alloc_size = curr_alloc_size / 2;
6733b39a1301b0 Jayamohan Kallickal 2009-09-05  2520  			} else {
6733b39a1301b0 Jayamohan Kallickal 2009-09-05  2521  				mem_arr->bus_address.u.
6733b39a1301b0 Jayamohan Kallickal 2009-09-05  2522  				    a64.address = (__u64) bus_add;
6733b39a1301b0 Jayamohan Kallickal 2009-09-05  2523  				mem_arr->size = curr_alloc_size;
6733b39a1301b0 Jayamohan Kallickal 2009-09-05  2524  				alloc_size -= curr_alloc_size;
6733b39a1301b0 Jayamohan Kallickal 2009-09-05  2525  				curr_alloc_size = min(be_max_phys_size *
6733b39a1301b0 Jayamohan Kallickal 2009-09-05  2526  						      1024, alloc_size);
6733b39a1301b0 Jayamohan Kallickal 2009-09-05  2527  				j++;
6733b39a1301b0 Jayamohan Kallickal 2009-09-05  2528  				mem_arr++;
6733b39a1301b0 Jayamohan Kallickal 2009-09-05  2529  			}
6733b39a1301b0 Jayamohan Kallickal 2009-09-05  2530  		} while (alloc_size);
6733b39a1301b0 Jayamohan Kallickal 2009-09-05  2531  		mem_descr->num_elements = j;
6733b39a1301b0 Jayamohan Kallickal 2009-09-05  2532  		mem_descr->size_in_bytes = phba->mem_req[i];
bf4afc53b77aea Linus Torvalds      2026-02-21  2533  		mem_descr->mem_array = kmalloc_objs(*mem_arr, j);
6733b39a1301b0 Jayamohan Kallickal 2009-09-05  2534  		if (!mem_descr->mem_array)
6733b39a1301b0 Jayamohan Kallickal 2009-09-05  2535  			goto free_mem;
6733b39a1301b0 Jayamohan Kallickal 2009-09-05  2536  
6733b39a1301b0 Jayamohan Kallickal 2009-09-05  2537  		memcpy(mem_descr->mem_array, mem_arr_orig,
6733b39a1301b0 Jayamohan Kallickal 2009-09-05  2538  		       sizeof(struct mem_array) * j);
6733b39a1301b0 Jayamohan Kallickal 2009-09-05  2539  		mem_descr++;
6733b39a1301b0 Jayamohan Kallickal 2009-09-05  2540  	}
6733b39a1301b0 Jayamohan Kallickal 2009-09-05  2541  	kfree(mem_arr_orig);
6733b39a1301b0 Jayamohan Kallickal 2009-09-05  2542  	return 0;
6733b39a1301b0 Jayamohan Kallickal 2009-09-05  2543  free_mem:
6733b39a1301b0 Jayamohan Kallickal 2009-09-05  2544  	mem_descr->num_elements = j;
6733b39a1301b0 Jayamohan Kallickal 2009-09-05  2545  	while ((i) || (j)) {
6733b39a1301b0 Jayamohan Kallickal 2009-09-05  2546  		for (j = mem_descr->num_elements; j > 0; j--) {
26a4c991af99f1 Christoph Hellwig   2018-10-10  2547  			dma_free_coherent(&phba->pcidev->dev,
6733b39a1301b0 Jayamohan Kallickal 2009-09-05  2548  					    mem_descr->mem_array[j - 1].size,
6733b39a1301b0 Jayamohan Kallickal 2009-09-05  2549  					    mem_descr->mem_array[j - 1].
6733b39a1301b0 Jayamohan Kallickal 2009-09-05  2550  					    virtual_address,
457ff3b7dc3796 Jayamohan Kallickal 2010-07-22  2551  					    (unsigned long)mem_descr->
457ff3b7dc3796 Jayamohan Kallickal 2010-07-22  2552  					    mem_array[j - 1].
6733b39a1301b0 Jayamohan Kallickal 2009-09-05  2553  					    bus_address.u.a64.address);
6733b39a1301b0 Jayamohan Kallickal 2009-09-05  2554  		}
6733b39a1301b0 Jayamohan Kallickal 2009-09-05  2555  		if (i) {
6733b39a1301b0 Jayamohan Kallickal 2009-09-05  2556  			i--;
6733b39a1301b0 Jayamohan Kallickal 2009-09-05  2557  			kfree(mem_descr->mem_array);
6733b39a1301b0 Jayamohan Kallickal 2009-09-05  2558  			mem_descr--;
6733b39a1301b0 Jayamohan Kallickal 2009-09-05  2559  		}
6733b39a1301b0 Jayamohan Kallickal 2009-09-05  2560  	}
6733b39a1301b0 Jayamohan Kallickal 2009-09-05  2561  	kfree(mem_arr_orig);
6733b39a1301b0 Jayamohan Kallickal 2009-09-05  2562  	kfree(phba->init_mem);
a7909b396ba79a Jayamohan Kallickal 2013-04-05  2563  	kfree(phba->phwi_ctrlr->wrb_context);
6733b39a1301b0 Jayamohan Kallickal 2009-09-05  2564  	kfree(phba->phwi_ctrlr);
6733b39a1301b0 Jayamohan Kallickal 2009-09-05  2565  	return -ENOMEM;
6733b39a1301b0 Jayamohan Kallickal 2009-09-05  2566  }
6733b39a1301b0 Jayamohan Kallickal 2009-09-05  2567  

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] scsi: be2iscsi: kzalloc + kcalloc to kzalloc_flex
  2026-03-20  1:09 [PATCH] scsi: be2iscsi: kzalloc + kcalloc to kzalloc_flex Rosen Penev
  2026-03-20 18:44 ` Kees Cook
  2026-03-21 11:50 ` kernel test robot
@ 2026-03-21 16:27 ` kernel test robot
  2 siblings, 0 replies; 4+ messages in thread
From: kernel test robot @ 2026-03-21 16:27 UTC (permalink / raw)
  To: Rosen Penev, linux-scsi

Hi Rosen,

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 v7.0-rc4 next-20260320]
[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/Rosen-Penev/scsi-be2iscsi-kzalloc-kcalloc-to-kzalloc_flex/20260321-145321
base:   https://git.kernel.org/pub/scm/linux/kernel/git/jejb/scsi.git for-next
patch link:    https://lore.kernel.org/r/20260320010957.32355-1-rosenp%40gmail.com
patch subject: [PATCH] scsi: be2iscsi: kzalloc + kcalloc to kzalloc_flex
config: x86_64-rhel-9.4-ltp (https://download.01.org/0day-ci/archive/20260322/202603220006.d4ATnciA-lkp@intel.com/config)
compiler: gcc-14 (Debian 14.2.0-19) 14.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260322/202603220006.d4ATnciA-lkp@intel.com/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 <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202603220006.d4ATnciA-lkp@intel.com/

All warnings (new ones prefixed by >>):

   drivers/scsi/be2iscsi/be_main.c: In function 'beiscsi_alloc_mem':
>> drivers/scsi/be2iscsi/be_main.c:2468:32: warning: variable 'phwi_ctrlr' set but not used [-Wunused-but-set-variable]
    2468 |         struct hwi_controller *phwi_ctrlr;
         |                                ^~~~~~~~~~


vim +/phwi_ctrlr +2468 drivers/scsi/be2iscsi/be_main.c

6733b39a1301b0 Jayamohan Kallickal 2009-09-05  2464  
6733b39a1301b0 Jayamohan Kallickal 2009-09-05  2465  static int beiscsi_alloc_mem(struct beiscsi_hba *phba)
6733b39a1301b0 Jayamohan Kallickal 2009-09-05  2466  {
6733b39a1301b0 Jayamohan Kallickal 2009-09-05  2467  	dma_addr_t bus_add;
a7909b396ba79a Jayamohan Kallickal 2013-04-05 @2468  	struct hwi_controller *phwi_ctrlr;
a7909b396ba79a Jayamohan Kallickal 2013-04-05  2469  	struct be_mem_descriptor *mem_descr;
6733b39a1301b0 Jayamohan Kallickal 2009-09-05  2470  	struct mem_array *mem_arr, *mem_arr_orig;
6733b39a1301b0 Jayamohan Kallickal 2009-09-05  2471  	unsigned int i, j, alloc_size, curr_alloc_size;
6733b39a1301b0 Jayamohan Kallickal 2009-09-05  2472  
7051e9804743be Rosen Penev         2026-03-19  2473  	phba->phwi_ctrlr = kzalloc_flex(*phba->phwi_ctrlr, wrb_context, phba->params.cxns_per_ctrl);
6733b39a1301b0 Jayamohan Kallickal 2009-09-05  2474  	if (!phba->phwi_ctrlr)
6733b39a1301b0 Jayamohan Kallickal 2009-09-05  2475  		return -ENOMEM;
6733b39a1301b0 Jayamohan Kallickal 2009-09-05  2476  
a7909b396ba79a Jayamohan Kallickal 2013-04-05  2477  	/* Allocate memory for wrb_context */
a7909b396ba79a Jayamohan Kallickal 2013-04-05  2478  	phwi_ctrlr = phba->phwi_ctrlr;
a7909b396ba79a Jayamohan Kallickal 2013-04-05  2479  
bf4afc53b77aea Linus Torvalds      2026-02-21  2480  	phba->init_mem = kzalloc_objs(*mem_descr, SE_MEM_MAX);
6733b39a1301b0 Jayamohan Kallickal 2009-09-05  2481  	if (!phba->init_mem) {
6733b39a1301b0 Jayamohan Kallickal 2009-09-05  2482  		kfree(phba->phwi_ctrlr);
6733b39a1301b0 Jayamohan Kallickal 2009-09-05  2483  		return -ENOMEM;
6733b39a1301b0 Jayamohan Kallickal 2009-09-05  2484  	}
6733b39a1301b0 Jayamohan Kallickal 2009-09-05  2485  
32a92f8c893269 Linus Torvalds      2026-02-21  2486  	mem_arr_orig = kmalloc_objs(*mem_arr_orig, BEISCSI_MAX_FRAGS_INIT);
6733b39a1301b0 Jayamohan Kallickal 2009-09-05  2487  	if (!mem_arr_orig) {
6733b39a1301b0 Jayamohan Kallickal 2009-09-05  2488  		kfree(phba->init_mem);
6733b39a1301b0 Jayamohan Kallickal 2009-09-05  2489  		kfree(phba->phwi_ctrlr);
6733b39a1301b0 Jayamohan Kallickal 2009-09-05  2490  		return -ENOMEM;
6733b39a1301b0 Jayamohan Kallickal 2009-09-05  2491  	}
6733b39a1301b0 Jayamohan Kallickal 2009-09-05  2492  
6733b39a1301b0 Jayamohan Kallickal 2009-09-05  2493  	mem_descr = phba->init_mem;
6733b39a1301b0 Jayamohan Kallickal 2009-09-05  2494  	for (i = 0; i < SE_MEM_MAX; i++) {
8a86e8336f37fd Jayamohan Kallickal 2013-09-28  2495  		if (!phba->mem_req[i]) {
8a86e8336f37fd Jayamohan Kallickal 2013-09-28  2496  			mem_descr->mem_array = NULL;
8a86e8336f37fd Jayamohan Kallickal 2013-09-28  2497  			mem_descr++;
8a86e8336f37fd Jayamohan Kallickal 2013-09-28  2498  			continue;
8a86e8336f37fd Jayamohan Kallickal 2013-09-28  2499  		}
8a86e8336f37fd Jayamohan Kallickal 2013-09-28  2500  
6733b39a1301b0 Jayamohan Kallickal 2009-09-05  2501  		j = 0;
6733b39a1301b0 Jayamohan Kallickal 2009-09-05  2502  		mem_arr = mem_arr_orig;
6733b39a1301b0 Jayamohan Kallickal 2009-09-05  2503  		alloc_size = phba->mem_req[i];
6733b39a1301b0 Jayamohan Kallickal 2009-09-05  2504  		memset(mem_arr, 0, sizeof(struct mem_array) *
6733b39a1301b0 Jayamohan Kallickal 2009-09-05  2505  		       BEISCSI_MAX_FRAGS_INIT);
6733b39a1301b0 Jayamohan Kallickal 2009-09-05  2506  		curr_alloc_size = min(be_max_phys_size * 1024, alloc_size);
6733b39a1301b0 Jayamohan Kallickal 2009-09-05  2507  		do {
26a4c991af99f1 Christoph Hellwig   2018-10-10  2508  			mem_arr->virtual_address =
26a4c991af99f1 Christoph Hellwig   2018-10-10  2509  				dma_alloc_coherent(&phba->pcidev->dev,
26a4c991af99f1 Christoph Hellwig   2018-10-10  2510  					curr_alloc_size, &bus_add, GFP_KERNEL);
6733b39a1301b0 Jayamohan Kallickal 2009-09-05  2511  			if (!mem_arr->virtual_address) {
6733b39a1301b0 Jayamohan Kallickal 2009-09-05  2512  				if (curr_alloc_size <= BE_MIN_MEM_SIZE)
6733b39a1301b0 Jayamohan Kallickal 2009-09-05  2513  					goto free_mem;
6733b39a1301b0 Jayamohan Kallickal 2009-09-05  2514  				if (curr_alloc_size -
6733b39a1301b0 Jayamohan Kallickal 2009-09-05  2515  					rounddown_pow_of_two(curr_alloc_size))
6733b39a1301b0 Jayamohan Kallickal 2009-09-05  2516  					curr_alloc_size = rounddown_pow_of_two
6733b39a1301b0 Jayamohan Kallickal 2009-09-05  2517  							     (curr_alloc_size);
6733b39a1301b0 Jayamohan Kallickal 2009-09-05  2518  				else
6733b39a1301b0 Jayamohan Kallickal 2009-09-05  2519  					curr_alloc_size = curr_alloc_size / 2;
6733b39a1301b0 Jayamohan Kallickal 2009-09-05  2520  			} else {
6733b39a1301b0 Jayamohan Kallickal 2009-09-05  2521  				mem_arr->bus_address.u.
6733b39a1301b0 Jayamohan Kallickal 2009-09-05  2522  				    a64.address = (__u64) bus_add;
6733b39a1301b0 Jayamohan Kallickal 2009-09-05  2523  				mem_arr->size = curr_alloc_size;
6733b39a1301b0 Jayamohan Kallickal 2009-09-05  2524  				alloc_size -= curr_alloc_size;
6733b39a1301b0 Jayamohan Kallickal 2009-09-05  2525  				curr_alloc_size = min(be_max_phys_size *
6733b39a1301b0 Jayamohan Kallickal 2009-09-05  2526  						      1024, alloc_size);
6733b39a1301b0 Jayamohan Kallickal 2009-09-05  2527  				j++;
6733b39a1301b0 Jayamohan Kallickal 2009-09-05  2528  				mem_arr++;
6733b39a1301b0 Jayamohan Kallickal 2009-09-05  2529  			}
6733b39a1301b0 Jayamohan Kallickal 2009-09-05  2530  		} while (alloc_size);
6733b39a1301b0 Jayamohan Kallickal 2009-09-05  2531  		mem_descr->num_elements = j;
6733b39a1301b0 Jayamohan Kallickal 2009-09-05  2532  		mem_descr->size_in_bytes = phba->mem_req[i];
bf4afc53b77aea Linus Torvalds      2026-02-21  2533  		mem_descr->mem_array = kmalloc_objs(*mem_arr, j);
6733b39a1301b0 Jayamohan Kallickal 2009-09-05  2534  		if (!mem_descr->mem_array)
6733b39a1301b0 Jayamohan Kallickal 2009-09-05  2535  			goto free_mem;
6733b39a1301b0 Jayamohan Kallickal 2009-09-05  2536  
6733b39a1301b0 Jayamohan Kallickal 2009-09-05  2537  		memcpy(mem_descr->mem_array, mem_arr_orig,
6733b39a1301b0 Jayamohan Kallickal 2009-09-05  2538  		       sizeof(struct mem_array) * j);
6733b39a1301b0 Jayamohan Kallickal 2009-09-05  2539  		mem_descr++;
6733b39a1301b0 Jayamohan Kallickal 2009-09-05  2540  	}
6733b39a1301b0 Jayamohan Kallickal 2009-09-05  2541  	kfree(mem_arr_orig);
6733b39a1301b0 Jayamohan Kallickal 2009-09-05  2542  	return 0;
6733b39a1301b0 Jayamohan Kallickal 2009-09-05  2543  free_mem:
6733b39a1301b0 Jayamohan Kallickal 2009-09-05  2544  	mem_descr->num_elements = j;
6733b39a1301b0 Jayamohan Kallickal 2009-09-05  2545  	while ((i) || (j)) {
6733b39a1301b0 Jayamohan Kallickal 2009-09-05  2546  		for (j = mem_descr->num_elements; j > 0; j--) {
26a4c991af99f1 Christoph Hellwig   2018-10-10  2547  			dma_free_coherent(&phba->pcidev->dev,
6733b39a1301b0 Jayamohan Kallickal 2009-09-05  2548  					    mem_descr->mem_array[j - 1].size,
6733b39a1301b0 Jayamohan Kallickal 2009-09-05  2549  					    mem_descr->mem_array[j - 1].
6733b39a1301b0 Jayamohan Kallickal 2009-09-05  2550  					    virtual_address,
457ff3b7dc3796 Jayamohan Kallickal 2010-07-22  2551  					    (unsigned long)mem_descr->
457ff3b7dc3796 Jayamohan Kallickal 2010-07-22  2552  					    mem_array[j - 1].
6733b39a1301b0 Jayamohan Kallickal 2009-09-05  2553  					    bus_address.u.a64.address);
6733b39a1301b0 Jayamohan Kallickal 2009-09-05  2554  		}
6733b39a1301b0 Jayamohan Kallickal 2009-09-05  2555  		if (i) {
6733b39a1301b0 Jayamohan Kallickal 2009-09-05  2556  			i--;
6733b39a1301b0 Jayamohan Kallickal 2009-09-05  2557  			kfree(mem_descr->mem_array);
6733b39a1301b0 Jayamohan Kallickal 2009-09-05  2558  			mem_descr--;
6733b39a1301b0 Jayamohan Kallickal 2009-09-05  2559  		}
6733b39a1301b0 Jayamohan Kallickal 2009-09-05  2560  	}
6733b39a1301b0 Jayamohan Kallickal 2009-09-05  2561  	kfree(mem_arr_orig);
6733b39a1301b0 Jayamohan Kallickal 2009-09-05  2562  	kfree(phba->init_mem);
a7909b396ba79a Jayamohan Kallickal 2013-04-05  2563  	kfree(phba->phwi_ctrlr->wrb_context);
6733b39a1301b0 Jayamohan Kallickal 2009-09-05  2564  	kfree(phba->phwi_ctrlr);
6733b39a1301b0 Jayamohan Kallickal 2009-09-05  2565  	return -ENOMEM;
6733b39a1301b0 Jayamohan Kallickal 2009-09-05  2566  }
6733b39a1301b0 Jayamohan Kallickal 2009-09-05  2567  

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-03-21 16:28 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-20  1:09 [PATCH] scsi: be2iscsi: kzalloc + kcalloc to kzalloc_flex Rosen Penev
2026-03-20 18:44 ` Kees Cook
2026-03-21 11:50 ` kernel test robot
2026-03-21 16:27 ` kernel test robot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox