From nobody Sat Apr 4 00:07:10 2026 Received: from mail-pf1-f169.google.com (mail-pf1-f169.google.com [209.85.210.169]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7BC89313283 for ; Sat, 21 Mar 2026 19:17:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.169 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774120663; cv=none; b=qYbSgoySYDbyLtLLoYuwQT3IJ89fYrRxSflq0mQAJ+Yqiy5GV1Ls5MiHjoh5/5Siq7osswbMylOKrPBKQKWvbewFq7eSQ/2uaTAuPCkTyPGrGEMoNkal94prIMh/Zhf0yiHm99x7A0ElXgAi/8VxQXFu12L6YeEir8h1UrozWH4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774120663; c=relaxed/simple; bh=AQohWIPdx6o7olSCZG8FkfZL18WDcqfud6RonHxb344=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=lEa1W6UsTWfEKIR4y9WxtJm8e7mHmeGa1fF+wrVK+mrF04jlEaAwnYIP7DZnOIdfHzfCjLor9cfCe09U5KdpY7EnW1VU7dQyu21FK7zs9Yb3t2dfVlKnl3lpdhjyvwqpDcuuzFoV7nR+g4W9gUVVu/V7Mu+YhTrYRfsWZ3ieOdk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=DHWtSNRF; arc=none smtp.client-ip=209.85.210.169 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="DHWtSNRF" Received: by mail-pf1-f169.google.com with SMTP id d2e1a72fcca58-824c9da9928so3092207b3a.3 for ; Sat, 21 Mar 2026 12:17:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1774120662; x=1774725462; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=WfhTSNbMCa18G8KLItlOBWL7f74p2rCgKRxLJUa+eaQ=; b=DHWtSNRFHGjX50z+QniAoDPqz3RJHnWyX+fvi24jWqQoRdPJGeBV40JQeYmrEDIsJV hWhkr//qbZn4xVW1b1/NpSa9B76KJxMMGxtWvr8bPUPQPT2e2UEP/Jyk7RnOK2koETwe Yu6XxaFj5TzmgscUUDa/EMwflgYLz7hx/M8zYwkhUPFvBnsXwUqJtAnPpaTCP5V4t+rk hdvPXBXLNElww/zb48UEaugRRQHY+PrMfpW0FYawA+fVk0pHzKH5lqk7hgIGHVr9Ntx1 v4/WetbnMcPkWrexwDbEbkJxkshwCu7n13550/zVXzR5beBWDn5h9h052+5newXdGXNE B7UA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1774120662; x=1774725462; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=WfhTSNbMCa18G8KLItlOBWL7f74p2rCgKRxLJUa+eaQ=; b=AynMGz5D5CMqJWlRdd+INAu+pufLm9hdoxrZm3z+AASZxlT9SC4Ah0TQV++uw2m7px ReVPiT8OOzLQ+giVeWVEpcG5VJt/Wa6lPQxjBNhGKM8xul5K8lBuRpgW3sJF/Boku1Y2 yItL6Hn7d8Fvsp0vmjWTNhP0AopZMNXgpQvLXtU5Qp2cXH40C03ag5j5DM67X+iv1MZx v3h7/6nCodugtulYgoeuyovAzNkP2SqHwYSvsrBmenHBNA61/mnF2cmoRosmTVq+nQBr IsJjbrf/XX1PxDwQPyMQoyElxYGOKide741NBVDctqG/2fSBWKKetFS+JYpEpKmZLEYu sYFQ== X-Forwarded-Encrypted: i=1; AJvYcCX2SJEJdOrPbRJYOuTxiiJyjSLH+sXJnUaz8PDc/43Wu6dbIRFNKvG9BMt8C4EKLIKCqNTXSVLu8WWXJ8w=@vger.kernel.org X-Gm-Message-State: AOJu0YzFtwYuSjonfdF18qn3GCjB2/8yCIWl+SWySV3pLMCFHYO8ky2W GZRi/S65G9VtjjLeVgpgx4lL3zU3pZQNaBtuvmHMEnCWj61d59Y+limU X-Gm-Gg: ATEYQzw65BPOw4Hh56EHLAVgeh2D9P0eSJmLTH+5mrofEEAG4LIkG5EOYJ1jU/ZLAme zLMW4mMAFO547oa87rIIr9jdNzDKf8BNYpI5XDuN2+bwgKaCMPc0gsLpUrPA+MyxWbQNk3OjFHs qggS13RA+sPjNm4LbrMwXZM0GE2Jvqkco1mhD3QXqmllCOjeaK08aII4yr5t4K6a7HcNCIuBTzz cYIM0q9o5cNSzaOuCJesib7aJ9QOB3Bf2RZzht6eecRDWGcPtzxaKLXgMg57CHDGtrKELkhQt9E pgWysX2WrnxbVgtpHMnwD2tc/6yYhGfS4mM2ZhK16uUeomeoUTVHZs9AQFgpXVMFdTqneDrIebf 2rIjH4qv5fuRCk2+QdgfniYygYn6egTnUaw8HEgOwTlxOqAST9ycjEgPqZUx7SAr9CpQw9oVxaZ GBc4wg5Ov6vYKK4m/0vOOwvw86BuXDFjRy1o4sT0vzf6OLxKFItb2U0xI= X-Received: by 2002:a05:6a21:9981:b0:39b:c469:6c81 with SMTP id adf61e73a8af0-39bceb20ca0mr6375833637.33.1774120661821; Sat, 21 Mar 2026 12:17:41 -0700 (PDT) Received: from ryzen ([2601:644:8000:5b5d::8bd]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-c74443cc9edsm4319968a12.23.2026.03.21.12.17.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 21 Mar 2026 12:17:41 -0700 (PDT) From: Rosen Penev To: linux-scsi@vger.kernel.org Cc: Ketan Mukadam , "James E.J. Bottomley" , "Martin K. Petersen" , Kees Cook , "Gustavo A. R. Silva" , linux-kernel@vger.kernel.org (open list), linux-hardening@vger.kernel.org (open list:KERNEL HARDENING (not covered by other areas):Keyword:\b__counted_by(_le|_be)?\b) Subject: [PATCH 1/2] scsi: be2iscsi: simplify cid_array allocation Date: Sat, 21 Mar 2026 12:17:21 -0700 Message-ID: <20260321191722.19235-2-rosenp@gmail.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260321191722.19235-1-rosenp@gmail.com> References: <20260321191722.19235-1-rosenp@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Use kzalloc_flex to allocate cid_array to allocate cid_array as part of the overall struct. Add __counted_by for extra runtime analysis. Signed-off-by: Rosen Penev --- drivers/scsi/be2iscsi/be_main.c | 17 ++--------------- drivers/scsi/be2iscsi/be_main.h | 2 +- 2 files changed, 3 insertions(+), 16 deletions(-) diff --git a/drivers/scsi/be2iscsi/be_main.c b/drivers/scsi/be2iscsi/be_mai= n.c index fd18d4d3d219..aa5320535c1f 100644 --- a/drivers/scsi/be2iscsi/be_main.c +++ b/drivers/scsi/be2iscsi/be_main.c @@ -3992,25 +3992,14 @@ static int hba_setup_cid_tbls(struct beiscsi_hba *p= hba) =20 for (ulp_num =3D 0; ulp_num < BEISCSI_ULP_COUNT; ulp_num++) { if (test_bit(ulp_num, (void *)&phba->fw_config.ulp_supported)) { - ptr_cid_info =3D kzalloc_obj(struct ulp_cid_info); + ptr_cid_info =3D kzalloc_flex(*ptr_cid_info, cid_array, + BEISCSI_GET_CID_COUNT(phba, ulp_num)); =20 if (!ptr_cid_info) { ret =3D -ENOMEM; goto free_memory; } =20 - /* Allocate memory for CID array */ - ptr_cid_info->cid_array =3D - 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 =3D NULL; - ret =3D -ENOMEM; - - goto free_memory; - } ptr_cid_info->avlbl_cids =3D BEISCSI_GET_CID_COUNT( phba, ulp_num); =20 @@ -4061,7 +4050,6 @@ static int hba_setup_cid_tbls(struct beiscsi_hba *phb= a) ptr_cid_info =3D phba->cid_array_info[ulp_num]; =20 if (ptr_cid_info) { - kfree(ptr_cid_info->cid_array); kfree(ptr_cid_info); phba->cid_array_info[ulp_num] =3D NULL; } @@ -4175,7 +4163,6 @@ static void beiscsi_cleanup_port(struct beiscsi_hba *= phba) ptr_cid_info =3D phba->cid_array_info[ulp_num]; =20 if (ptr_cid_info) { - kfree(ptr_cid_info->cid_array); kfree(ptr_cid_info); phba->cid_array_info[ulp_num] =3D NULL; } diff --git a/drivers/scsi/be2iscsi/be_main.h b/drivers/scsi/be2iscsi/be_mai= n.h index 71c95d144560..b5f8e746deab 100644 --- a/drivers/scsi/be2iscsi/be_main.h +++ b/drivers/scsi/be2iscsi/be_main.h @@ -241,10 +241,10 @@ struct hwi_wrb_context { }; =20 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); }; =20 #include "be.h" --=20 2.53.0 From nobody Sat Apr 4 00:07:10 2026 Received: from mail-pf1-f177.google.com (mail-pf1-f177.google.com [209.85.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id ED20B3218B3 for ; Sat, 21 Mar 2026 19:17:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.177 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774120665; cv=none; b=SsQIl/KkD+FukwbBULrGnlzasrqf9Plmp+Mo9YTHlfVhab4S5d3SMz2A/PoTKHlpLle83n37Ni11paWK293DqFvyNBoOcJc9dJ4S8M3ne+BJPeM0OE8gBsrHEEN0xf2W++Q/7GGmnDrb8dgtm1mo5vJ8NE4YmuGXNuvlMoZ5r3o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774120665; c=relaxed/simple; bh=Tsse4Ly6NtzSSlkCNrQss5DdsY0MgmF7zlxq5rnNN2c=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=lTVrp0jX9sWP1nFXF2CEu/opvBM/Cu141cPgb3gya71ihNqb94csPRa8e+eV4GKZp07bFiV6KXIee3wrvPBlca4ZBJXQbmiWVBadH+UhRdf9FTYrAcwRyUFA3Wb7gST4t7sADxyVloqctlOgXVA6f5nyJfqMdiH5rzeuUcl3r8Y= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=UBueko6P; arc=none smtp.client-ip=209.85.210.177 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="UBueko6P" Received: by mail-pf1-f177.google.com with SMTP id d2e1a72fcca58-829ac4670c4so2177740b3a.0 for ; Sat, 21 Mar 2026 12:17:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1774120663; x=1774725463; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=UicmcSJjTDj6d4okbgLa8FdzILWgq4+BDig2MAnvOJo=; b=UBueko6P1cy2f+uu6nsD8Hict8QEqkxYZIbMk3BGpsfzSxiEGSc++IfyxRyZPnJpAl bvEJpBV3QCwzqeznbulR8liI60t6dY+ZgQH3c/wMe8LPZp0Yyarp9UXevxeJqWBt8li6 /+7xitXg1MbCKycfkipM+mw/GU6lw+JwIP8RWzNP2ISA1IAUJp1h+Oly8dKM12zjcRhf goHRIRtJ1fTChsYr/6/kXkWW8T0tNkNtCziqR7uwQQhQRLyfnEOlys2XjirNMkL9L3j3 xSZUlp/x79AX85QQz7M5U2VRme6xpVvITUnAHQXLksihMy+V0ZcePZlECwkKeM+0907S tZtQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1774120663; x=1774725463; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=UicmcSJjTDj6d4okbgLa8FdzILWgq4+BDig2MAnvOJo=; b=rP37l97mXzgQxTXVyNW0YdgbuhngagnARbNBcS3WW7ia7PK1xVxFdoggB/87YA8jEN Gq/Z5NO7UXls2BohK+v16UjyPBEyf20W5vDmL/1uBuSVsMgUT8A4zE1zodfi1xoW+7Fx Gkm9x6gKOyQo1tVJvdufK4iEOxZl6KvGKAQCtgyWsAwycNlag+Qfl/g2t0PHTr50thai CJjKpAg9r8J6JegT5OShkIdeYrYl9w8nxajAgdZU3Z0nORcS7VAEQE1XwREp+ncbPx6V HgMnxv6Xltq+q6NlehS3DZme5JxAY/lbq6xpJ2zDDCg99nEJOZgylSHqyCJdftt0P81M DPVg== X-Forwarded-Encrypted: i=1; AJvYcCWQTTJoUze4+aaD4o5Q7acj91plG2E1C5ZS5Gc0y2oLufCJjUFO/ylrwnVcndCtmMyZyyCmXY4EvGIxUac=@vger.kernel.org X-Gm-Message-State: AOJu0Yw1chngw/hfDFAEYs/fioCD2Yv4f2v+Ifq2j9QpPatcFU/Rm6Zm G/m0aW5WyCK63qkZ+6tVf4VuTa5wAg7X0kd7VumFeWFxGP3M3cMvGAl0 X-Gm-Gg: ATEYQzyjRYdXyPH7yh2QdCUK7N0PYo6st5qOiwv0Dw6SXSKGOW+iOGngc+pFU/69W0u bujinL+/CJTeqVzWbW5g3tk7kfiAvkAoNuljwEyJW4dxTi90IfzWxv25eHzim/m5nyh7YDjACSf 4sQC5D34eEu8gkh9+kWCka1MUs6nBbSh60rg6+Opd/uEpZt/H5FIXxHwPPd4pCBlvavXBWza6Cs zpTjdixl4GaMomh8qe8EfZyYBxcjs1tqx83Wif431M3kYcS0UhXVYipHcSzfHfRLZaT628Nhp2m 97XDSm3QskcrKzzpUFDscSXTLENRE2Qo4nf4MOx7ZOA/dUK7WxnndSHL3k0iedgX5ZVsz6X3XST KMvY3eu0hZaGvZYIJPdEwF5EP3B5yNVu0KvVkvTyiIdgcCjsXq4/N8SnFK1LlzgrhRYTKLwZLLA 2DUqS1L4f1J2iFx5H8RaXc2kJ5ncynPdCMTfyHc/VpFs5MxxwkCkGYP6Q= X-Received: by 2002:a05:6a20:1586:b0:398:9466:2ee8 with SMTP id adf61e73a8af0-39bce97c801mr6500384637.7.1774120663259; Sat, 21 Mar 2026 12:17:43 -0700 (PDT) Received: from ryzen ([2601:644:8000:5b5d::8bd]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-c74443cc9edsm4319968a12.23.2026.03.21.12.17.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 21 Mar 2026 12:17:42 -0700 (PDT) From: Rosen Penev To: linux-scsi@vger.kernel.org Cc: Ketan Mukadam , "James E.J. Bottomley" , "Martin K. Petersen" , Kees Cook , "Gustavo A. R. Silva" , linux-kernel@vger.kernel.org (open list), linux-hardening@vger.kernel.org (open list:KERNEL HARDENING (not covered by other areas):Keyword:\b__counted_by(_le|_be)?\b) Subject: [PATCH 2/2] scsi: be2iscsi: simplify hwi_controller allocation Date: Sat, 21 Mar 2026 12:17:22 -0700 Message-ID: <20260321191722.19235-3-rosenp@gmail.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260321191722.19235-1-rosenp@gmail.com> References: <20260321191722.19235-1-rosenp@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Use a flexible array member to allocate and free hwi_controller once using kzalloc_flex. Signed-off-by: Rosen Penev --- drivers/scsi/be2iscsi/be_main.c | 16 +--------------- drivers/scsi/be2iscsi/be_main.h | 2 +- 2 files changed, 2 insertions(+), 16 deletions(-) diff --git a/drivers/scsi/be2iscsi/be_main.c b/drivers/scsi/be2iscsi/be_mai= n.c index aa5320535c1f..799063000e77 100644 --- a/drivers/scsi/be2iscsi/be_main.c +++ b/drivers/scsi/be2iscsi/be_main.c @@ -2465,27 +2465,16 @@ static void beiscsi_find_mem_req(struct beiscsi_hba= *phba) static int beiscsi_alloc_mem(struct beiscsi_hba *phba) { dma_addr_t bus_add; - struct hwi_controller *phwi_ctrlr; struct be_mem_descriptor *mem_descr; struct mem_array *mem_arr, *mem_arr_orig; unsigned int i, j, alloc_size, curr_alloc_size; =20 - phba->phwi_ctrlr =3D kzalloc(phba->params.hwi_ws_sz, GFP_KERNEL); + phba->phwi_ctrlr =3D kzalloc_flex(*phba->phwi_ctrlr, wrb_context, phba->p= arams.cxns_per_ctrl); if (!phba->phwi_ctrlr) return -ENOMEM; =20 - /* Allocate memory for wrb_context */ - phwi_ctrlr =3D phba->phwi_ctrlr; - phwi_ctrlr->wrb_context =3D 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 =3D kzalloc_objs(*mem_descr, SE_MEM_MAX); if (!phba->init_mem) { - kfree(phwi_ctrlr->wrb_context); kfree(phba->phwi_ctrlr); return -ENOMEM; } @@ -2493,7 +2482,6 @@ static int beiscsi_alloc_mem(struct beiscsi_hba *phba) mem_arr_orig =3D 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; } @@ -2568,7 +2556,6 @@ static int beiscsi_alloc_mem(struct beiscsi_hba *phba) } kfree(mem_arr_orig); kfree(phba->init_mem); - kfree(phba->phwi_ctrlr->wrb_context); kfree(phba->phwi_ctrlr); return -ENOMEM; } @@ -3874,7 +3861,6 @@ static void beiscsi_free_mem(struct beiscsi_hba *phba) mem_descr++; } kfree(phba->init_mem); - kfree(phba->phwi_ctrlr->wrb_context); kfree(phba->phwi_ctrlr); } =20 diff --git a/drivers/scsi/be2iscsi/be_main.h b/drivers/scsi/be2iscsi/be_mai= n.h index b5f8e746deab..77c9b1a1a488 100644 --- a/drivers/scsi/be2iscsi/be_main.h +++ b/drivers/scsi/be2iscsi/be_main.h @@ -968,10 +968,10 @@ struct be_ring { }; =20 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[]; }; =20 enum hwh_type_enum { --=20 2.53.0