From nobody Mon Apr 6 09:09:54 2026 Received: from mail-yw1-f179.google.com (mail-yw1-f179.google.com [209.85.128.179]) (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 0B709271A71 for ; Fri, 20 Mar 2026 01:10:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.179 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773969018; cv=none; b=fGWyokNM405RrUkB5rGQEQipbThuAnYLn0A25NiHBUqttKV3vEXFmDlah6WWXYVJkU2V6H2KyTp3F15aXiN+dxMGwYqDSfJlwWfR8NsgGNcEIqLVXQLFztFBh+9RAiMaFgeAgY8Tr5m2/699Dgw6lgfEpw0teAnTHyZA7OeqcOE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773969018; c=relaxed/simple; bh=27JPzjJMDDgjf2qMis3eedxFTyNiAGX6kPcAnzP2/20=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=OlIcH6cWKezBQEt3zIOm7C1+LfgifL6WEGjjO8DYx5+mxAIGXjzN/lp/puQqvAB3k5NqBm36vzlZ0E1kGFoiQAJChjkE/6PudkeJFPuOGnVjBxedjGTDZcCG1L8Be2gQ3zSBDpEw0o673p6AiEo9nWlhM24RmS7WxPbVerXoMfA= 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=kmZlfiPd; arc=none smtp.client-ip=209.85.128.179 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="kmZlfiPd" Received: by mail-yw1-f179.google.com with SMTP id 00721157ae682-798374d0f44so38907527b3.0 for ; Thu, 19 Mar 2026 18:10:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1773969016; x=1774573816; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=qdP8K3+cAzx0ganXl8vq/PIp0ujTWW+NWr7suf1Oel0=; b=kmZlfiPdODOCvSU3eIci9NvNQzSPXDG0VOJinngreh/sycfaobk1/gN6c24bKbGk59 GUuCkxe3zL7On+7dEWrf/kgfgxgbVJOvh1PLekF8opDHCRhWvsw6V7PRMrC9w8t01cbl q2lgoNCY9ajBXG3WXser4o4KH59xPbwJA9wG5bbKnXfA0XFbJ+5zEe07frfc8jFm2D6z p4i5XPyruwbw2Td57o4542JOnEmIDemPdV+/IVrenwmFl3q9JqZ8eCYdjicmEJLKHN97 51p6oHqHs9sTno4SypOBM1ozb6vw70B6Ns8+bT1rJIQuNvH+dfZYDAkVO/NsdvqVHiyn bf/w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1773969016; x=1774573816; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=qdP8K3+cAzx0ganXl8vq/PIp0ujTWW+NWr7suf1Oel0=; b=mMNvPH3+eQw1TkGGLZS0suwc7loxYItzXzOL/WtDRcy0Bjx4iNwx3ok1EQyXzYYa9x f2ZMXKuAxYtkncM59zE7TkUjTmSQTbeX3Qkbjodb+ZJlkTT+n9s6lC75Mf5b82N8NcNf OPEUQZV69t0mRW3DakEIEZz6MKIxG7Vlm9jKrpR/7vPFafq995FjtHR+AA72A/CYB4It 3j+7UdDeEd47iEIDKmJatgt4fSmKXpCCciyMhnWXUAigFxLqBjvEp18N17Z+v2gftUag fWcmtirf6TNd5xocBdEDkDkW5JgvAMBceWii4SoJxaLxF4TxDwxXM6h+xW7mxK3r47z+ lT5A== X-Forwarded-Encrypted: i=1; AJvYcCXxyucA+pwjB+wk4AZzBIhE/KB37DA8WeTmifqE+o3daogwgGVABpYYuVV4HEpsGD2PaaAKzYcv31tm06w=@vger.kernel.org X-Gm-Message-State: AOJu0YyHQkVCzA28SxF1cyiC8Z/c6zz6L7jRZ/eeSaTNKgjs9msl/R3k /mQUKRQsW/lslQj/UO6mVOxs010WjTK78RafvQvlIpP4AubmY9ySjJYn X-Gm-Gg: ATEYQzxKGyYyXIOqYjHHFDJA0dII55IieVFr9rhcAqyl0S7AcnqNg4UoSCRr7Ri0Vk1 CRLEtjJKL8jDiq5jTQQaJ2yVK9SrwwNxhrM+XlrY2N4UWNDPEQVTe7AUJH3nTz+VeTFfK6THpvV yVFODodebyL7bpHODE0aNW8tpr5mtp3/eNY9XBDqp1AKtHXH0B2W5haYzwUoDwfpyWDsoB0ch8K pQGNgqSHA4sX14AmN2GxT8hxTpyGzlTfUzXXce2PrT48NREn18WzLkZA6ZbccS2GaC0zPZfVpo/ vMf3Jp6q2ZqwxcSulBGzh5I4Vt/gayD3c7N+Dk1bE4wCmM8ApB44JNutnDdIhil8CYRoclk4QHX RI9WEJRxdmDuF89sf3SrzVZZp5Q3iXMlC3eG7YVKfLduEkdXJBIICGBRk+SlWOtSFOfZib0efkK PpxwTtl7YNdF3PPS15VLfiVnYnV2SQQ6CSGOpyXl75UF4UhhdlM29s45w= X-Received: by 2002:a05:690e:e11:b0:64a:db29:5e61 with SMTP id 956f58d0204a3-64eaacd241fmr1049059d50.32.1773969016093; Thu, 19 Mar 2026 18:10:16 -0700 (PDT) Received: from ryzen ([2601:644:8000:5b5d::8bd]) by smtp.gmail.com with ESMTPSA id 956f58d0204a3-64eabd44121sm515493d50.1.2026.03.19.18.10.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Mar 2026 18:10:15 -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] scsi: be2iscsi: kzalloc + kcalloc to kzalloc_flex Date: Thu, 19 Mar 2026 18:09:57 -0700 Message-ID: <20260320010957.32355-1-rosenp@gmail.com> X-Mailer: git-send-email 2.53.0 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" Simplifies allocation by using a flexible array member Added __counted_by for extra runtime analysis. Signed-off-by: Rosen Penev --- 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_mai= n.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 *ph= ba) 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; - } =20 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 +2486,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; } @@ -3992,25 +3984,12 @@ 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)); 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 +4040,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 +4153,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..77c9b1a1a488 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" @@ -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