* [PATCH] platform/x86/intel/tpmi: allocate tpmi_features with tpmi_info
@ 2026-04-30 22:26 Rosen Penev
0 siblings, 0 replies; only message in thread
From: Rosen Penev @ 2026-04-30 22:26 UTC (permalink / raw)
To: platform-driver-x86
Cc: Srinivas Pandruvada, Hans de Goede, Ilpo Järvinen, Kees Cook,
Gustavo A. R. Silva, open list,
open list:KERNEL HARDENING (not covered by other areas):Keyword:b__counted_by(_le|_be)?b
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
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2026-04-30 22:26 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-30 22:26 [PATCH] platform/x86/intel/tpmi: allocate tpmi_features with tpmi_info Rosen Penev
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox