From: Rosen Penev <rosenp@gmail.com>
To: platform-driver-x86@vger.kernel.org
Cc: "Srinivas Pandruvada" <srinivas.pandruvada@linux.intel.com>,
"Hans de Goede" <hansg@kernel.org>,
"Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>,
"Kees Cook" <kees@kernel.org>,
"Gustavo A. R. Silva" <gustavoars@kernel.org>,
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] platform/x86/intel/tpmi: allocate tpmi_features with tpmi_info
Date: Thu, 30 Apr 2026 15:26:39 -0700 [thread overview]
Message-ID: <20260430222639.95622-1-rosenp@gmail.com> (raw)
Combine allocations with a flexible array member to simplify the whole
thing.
Add __counted_by for extra runtime analysis. Move assignment of counting
variable to after allocation as this is already done by kzalloc_flex and
will be done by its devm variant when introduced for GCC 15 and above.
Signed-off-by: Rosen Penev <rosenp@gmail.com>
---
drivers/platform/x86/intel/vsec_tpmi.c | 14 +++++---------
1 file changed, 5 insertions(+), 9 deletions(-)
diff --git a/drivers/platform/x86/intel/vsec_tpmi.c b/drivers/platform/x86/intel/vsec_tpmi.c
index 7fc6ff8d1040..79c0cbea2dee 100644
--- a/drivers/platform/x86/intel/vsec_tpmi.c
+++ b/drivers/platform/x86/intel/vsec_tpmi.c
@@ -113,13 +113,13 @@ struct intel_tpmi_pm_feature {
* Stores the information for all TPMI devices enumerated from a single PCI device.
*/
struct intel_tpmi_info {
- struct intel_tpmi_pm_feature *tpmi_features;
struct intel_vsec_device *vsec_dev;
int feature_count;
u64 pfs_start;
struct oobmsm_plat_info plat_info;
void __iomem *tpmi_control_mem;
struct dentry *dbgfs_dir;
+ struct intel_tpmi_pm_feature tpmi_features[] __counted_by(feature_count);
};
/**
@@ -751,20 +751,16 @@ static int intel_vsec_tpmi_init(struct auxiliary_device *auxdev)
u64 pfs_start = 0;
int ret, i;
- tpmi_info = devm_kzalloc(&auxdev->dev, sizeof(*tpmi_info), GFP_KERNEL);
+ tpmi_info = devm_kzalloc(&auxdev->dev,
+ struct_size(tpmi_info, tpmi_features, vsec_dev->num_resources),
+ GFP_KERNEL);
if (!tpmi_info)
return -ENOMEM;
- tpmi_info->vsec_dev = vsec_dev;
tpmi_info->feature_count = vsec_dev->num_resources;
+ tpmi_info->vsec_dev = vsec_dev;
tpmi_info->plat_info.bus_number = pci_dev->bus->number;
- tpmi_info->tpmi_features = devm_kcalloc(&auxdev->dev, vsec_dev->num_resources,
- sizeof(*tpmi_info->tpmi_features),
- GFP_KERNEL);
- if (!tpmi_info->tpmi_features)
- return -ENOMEM;
-
for (i = 0; i < vsec_dev->num_resources; i++) {
struct intel_tpmi_pm_feature *pfs;
struct resource *res;
--
2.54.0
reply other threads:[~2026-04-30 22:26 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260430222639.95622-1-rosenp@gmail.com \
--to=rosenp@gmail.com \
--cc=gustavoars@kernel.org \
--cc=hansg@kernel.org \
--cc=ilpo.jarvinen@linux.intel.com \
--cc=kees@kernel.org \
--cc=linux-hardening@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=platform-driver-x86@vger.kernel.org \
--cc=srinivas.pandruvada@linux.intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox