From nobody Sun Jun 14 08:17:03 2026 Received: from mail-dl1-f46.google.com (mail-dl1-f46.google.com [74.125.82.46]) (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 BB96DEEC3 for ; Thu, 2 Apr 2026 00:17:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.46 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775089060; cv=none; b=kU/W85M/wr6K8Ma0BcmPmmiLQfRTCfbyagTAv3Skc6p94oJpfqBNiMf0BnfsCdU/N9ZsEU8ygpUC0QdatG4xmCKuI1J6j/AgCnTAPmZBgxQmjH3PubXLk+hf52X1ZV4YOS6wU1w5OtFpTINNuB/4KydMYiFMeatCJTMaPPFyMv0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775089060; c=relaxed/simple; bh=ADra3ClgKePAN13xTmcp15IadPDVNykpNzwZxAQS2OY=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=buZ3xQMBoBaJU8OyEZfXVyORhT+88aUGpgE8OB2h88/e5vuhGaRWsXgh3J4Fr0KwzKZ5TLWGH5q7GXmmtMJeIg9k9qFSTL6gKX0mwhCrwxHlisFOW6srCeqC5PCo3nMTDahetcdxjbdTUV++httEK6N3lleo6iCXC+RbduNLjOo= 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=hIwXTD00; arc=none smtp.client-ip=74.125.82.46 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="hIwXTD00" Received: by mail-dl1-f46.google.com with SMTP id a92af1059eb24-12776bebe9fso858150c88.1 for ; Wed, 01 Apr 2026 17:17:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1775089058; x=1775693858; 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=7TYE2yKc9g4jf7Hen57MTVK0lC7jGmTkJLhyUc8vkKU=; b=hIwXTD00NNh5mq0HZJE6XyMHEm4RiBbA1RPrcaAo1FE2EZFb++nz0FnbglquWpXu0q cqXJoAcUiKySnrzFuMZRblDJMDvX8KFPDEW0WLVb9X9WM1mIpH17rt0o6gBtROcx3VOs p9hOB2kZ40tftkPfidP1tuNDy4W8ci7w68f+vv6AWZ4EyXOXnq9vM2id2iO8JAIeMDlR Qnx8Vxf12Kd1jGCcAe7qn118UFvXJLJX24XwAdPZRQMgg3/9GI4qFUdWBhIlmqRR4Rvg WSmSuoI14LqHdbWWZTwMac0kBhZOLlI/5Q5V2JzZEuDHcK2t5tMs437OAn0+xiYWf1j1 V/ew== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1775089058; x=1775693858; 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=7TYE2yKc9g4jf7Hen57MTVK0lC7jGmTkJLhyUc8vkKU=; b=Ti0PQzS1+sgK1UuOlJegsXZ7l25GfYmbuHw+gdCNIztJTrMeV2AM1LZjnc6yDWkzCS 5kpmxhhSBUdGT3LBtzFjU3uPyBQGxs19F3fYxHCLd9ZOvwmE1ifmZXE1c0BfV5bBDrQ0 7RTbfPVTnJkKjUKaF//oWBoIIpPj/8WtTJjMNQfRukgZzIOlDoUxXB+wBL0OPjLYiaw8 ktqJV9NTkCFyMwZ5/2IpqhZ/qKiZsjw/JFfaHYLEGUYbp6MpZEK6WvvaJRwBmAEuzNz3 GCKbeXY2RJimYV0A+ok1LFcgkzK8NBdoSTjRZt79gUwHJiMcyU52CevO4XaTiTIecEHl xCsg== X-Forwarded-Encrypted: i=1; AJvYcCVqFWokuxchJFyVkmwwfow8omLkinIZvPl9MH7PPccR5TUZDmp6S0riQZAMCpTJmaX77rfewrMGZKumQi4=@vger.kernel.org X-Gm-Message-State: AOJu0Yw7lRy/F2FoGmk5mvq0ZT/KGnmOtxpSG5D6PXDkVt2CNXPrKy+a 9k5/17O5YfcSajXrlvoyFT43NKnmccl9MUBV2VFa4chMJc7b3Ub/w0ad X-Gm-Gg: ATEYQzwCFp3popLQWHEtDMW94c4/Yb1RWo5jrn0EMr9YNNly7lAZbTbIKdOQ0/OiQkO dLklD0+GjcqLs2AqqWBwBqo+SbCat6Ebetxnfr34Fl2xdteTpitRy5crnz0niLyb1s3SFsaHB9+ Q4JsMP0orVjembAlOwZjofXrCq6ByhvKY2WLCzlls5IXHgkyGa43nR48KPkDfYubWOwNXTK2N56 cshoyJKrIcxXlMWkdC7l6P1m1Xti3OV4Yny4afZY4z+BUeXYElScru97ttI69TV0/XTcW/qKUlY OBRvh4B/GD8iVA2/T/anZegJ9JX3AKS8nB7dzw+WFfNF/5n8+FYvuqDSkvbXURkpszuMT2HDpZr T8M/ICwAVlilCvqiOY07g64zS5qxHBLULj2HSCK7s2Mqj8boTUgV8xFmYzr0uc2DqEYBJadoB2/ atoHI4Zk+ulxfII1Y8/XbmEqdi07ASfNHgYuQ56ARs+Coyjvz1EV65xtWHxgW4lFy93w== X-Received: by 2002:a05:7022:1605:b0:12a:6902:ddc6 with SMTP id a92af1059eb24-12be62edb08mr3514362c88.0.1775089057784; Wed, 01 Apr 2026 17:17:37 -0700 (PDT) Received: from ryzen ([2601:644:8000:5b5d::8bd]) by smtp.gmail.com with ESMTPSA id a92af1059eb24-12bede7f004sm1049731c88.13.2026.04.01.17.17.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Apr 2026 17:17:37 -0700 (PDT) From: Rosen Penev To: mpi3mr-linuxdrv.pdl@broadcom.com Cc: Sathya Prakash Veerichetty , Kashyap Desai , Sumit Saxena , Sreekanth Reddy , "James E.J. Bottomley" , "Martin K. Petersen" , linux-scsi@vger.kernel.org (open list:BROADCOM MPI3 STORAGE CONTROLLER DRIVER), linux-kernel@vger.kernel.org (open list) Subject: [PATCH] scsi: mpi3mr: convert offsetof to struct_size Date: Wed, 1 Apr 2026 17:17:19 -0700 Message-ID: <20260402001719.72691-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" A lot more readable and clarifies we're dealing with flexible array members. Signed-off-by: Rosen Penev --- drivers/scsi/mpi3mr/mpi3mr_transport.c | 27 ++++++++------------------ 1 file changed, 8 insertions(+), 19 deletions(-) diff --git a/drivers/scsi/mpi3mr/mpi3mr_transport.c b/drivers/scsi/mpi3mr/m= pi3mr_transport.c index 240f67a8e2e3..7a5ba05abe28 100644 --- a/drivers/scsi/mpi3mr/mpi3mr_transport.c +++ b/drivers/scsi/mpi3mr/mpi3mr_transport.c @@ -1139,9 +1139,7 @@ void mpi3mr_sas_host_refresh(struct mpi3mr_ioc *mrioc) "updating handles for sas_host(0x%016llx)\n", (unsigned long long)mrioc->sas_hba.sas_address); =20 - sz =3D offsetof(struct mpi3_sas_io_unit_page0, phy_data) + - (mrioc->sas_hba.num_phys * - sizeof(struct mpi3_sas_io_unit0_phy_data)); + sz =3D struct_size(sas_io_unit_pg0, phy_data, mrioc->sas_hba.num_phys); sas_io_unit_pg0 =3D kzalloc(sz, GFP_KERNEL); if (!sas_io_unit_pg0) return; @@ -1203,8 +1201,7 @@ void mpi3mr_sas_host_add(struct mpi3mr_ioc *mrioc) struct mpi3_enclosure_page0 encl_pg0; struct mpi3_device0_sas_sata_format *sasinf; =20 - sz =3D offsetof(struct mpi3_sas_io_unit_page0, phy_data) + - (num_phys * sizeof(struct mpi3_sas_io_unit0_phy_data)); + sz =3D struct_size(sas_io_unit_pg0, phy_data, num_phys); sas_io_unit_pg0 =3D kzalloc(sz, GFP_KERNEL); if (!sas_io_unit_pg0) return; @@ -1226,8 +1223,7 @@ void mpi3mr_sas_host_add(struct mpi3mr_ioc *mrioc) =20 mrioc->sas_hba.num_phys =3D num_phys; =20 - sz =3D offsetof(struct mpi3_sas_io_unit_page0, phy_data) + - (num_phys * sizeof(struct mpi3_sas_io_unit0_phy_data)); + sz =3D struct_size(sas_io_unit_pg0, phy_data, num_phys); sas_io_unit_pg0 =3D kzalloc(sz, GFP_KERNEL); if (!sas_io_unit_pg0) return; @@ -1713,12 +1709,11 @@ mpi3mr_refresh_sas_ports(struct mpi3mr_ioc *mrioc) struct mpi3_device0_sas_sata_format *sasinf; struct mpi3mr_sas_port *mr_sas_port; =20 - sz =3D offsetof(struct mpi3_sas_io_unit_page0, phy_data) + - (mrioc->sas_hba.num_phys * - sizeof(struct mpi3_sas_io_unit0_phy_data)); + sz =3D struct_size(sas_io_unit_pg0, phy_data, mrioc->sas_hba.num_phys); sas_io_unit_pg0 =3D kzalloc(sz, GFP_KERNEL); if (!sas_io_unit_pg0) return; + h_port =3D kzalloc_objs(struct host_port, 64); if (!h_port) goto out; @@ -3014,9 +3009,7 @@ mpi3mr_transport_phy_enable(struct sas_phy *phy, int = enable) SMP_PHY_CONTROL_DISABLE); =20 /* handle hba phys */ - sz =3D offsetof(struct mpi3_sas_io_unit_page0, phy_data) + - (mrioc->sas_hba.num_phys * - sizeof(struct mpi3_sas_io_unit0_phy_data)); + sz =3D struct_size(sas_io_unit_pg0, phy_data, mrioc->sas_hba.num_phys); sas_io_unit_pg0 =3D kzalloc(sz, GFP_KERNEL); if (!sas_io_unit_pg0) { rc =3D -ENOMEM; @@ -3056,9 +3049,7 @@ mpi3mr_transport_phy_enable(struct sas_phy *phy, int = enable) } =20 /* read sas_iounit page 1 */ - sz =3D offsetof(struct mpi3_sas_io_unit_page1, phy_data) + - (mrioc->sas_hba.num_phys * - sizeof(struct mpi3_sas_io_unit1_phy_data)); + sz =3D struct_size(sas_io_unit_pg1, phy_data, mrioc->sas_hba.num_phys); sas_io_unit_pg1 =3D kzalloc(sz, GFP_KERNEL); if (!sas_io_unit_pg1) { rc =3D -ENOMEM; @@ -3134,9 +3125,7 @@ mpi3mr_transport_phy_speed(struct sas_phy *phy, struc= t sas_phy_linkrates *rates) } =20 /* handle hba phys */ - sz =3D offsetof(struct mpi3_sas_io_unit_page1, phy_data) + - (mrioc->sas_hba.num_phys * - sizeof(struct mpi3_sas_io_unit1_phy_data)); + sz =3D struct_size(sas_io_unit_pg1, phy_data, mrioc->sas_hba.num_phys); sas_io_unit_pg1 =3D kzalloc(sz, GFP_KERNEL); if (!sas_io_unit_pg1) { rc =3D -ENOMEM; --=20 2.53.0