Skip to contentSkip to conversation

platform/x86/intel/tpmi/plr: allocate die_info with plr

PATCH Superseded Rosen Penev 2 participants 3 messages Apr 30 – May 12 x86 platform drivers

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 platform/x86/intel/tpmi/plr: allocate die_info with plr

Simplifies allocations slightly.

Add __counted_by for extra runtime analysis.

---
 drivers/platform/x86/intel/plr_tpmi.c | 9 ++-------
 1 file changed, 2 insertions(+), 7 deletions(-)
drivers/platform/x86/intel/plr_tpmi.c +2 -7
index 05727169f49c..2fd27e80bc1f 100644
@@ -57,9 +57,9 @@ struct tpmi_plr_die {
 
 struct tpmi_plr {
 	struct dentry *dbgfs_dir;
-	struct tpmi_plr_die *die_info;
 	int num_dies;
 	struct auxiliary_device *auxdev;
+	struct tpmi_plr_die die_info[] __counted_by(num_dies);
 };
 
 static const char * const plr_coarse_reasons[] = {
@@ -278,15 +278,10 @@ static int intel_plr_probe(struct auxiliary_device *auxdev, const struct auxilia
 	if (!num_resources)
 		return -EINVAL;
 
-	plr = devm_kzalloc(&auxdev->dev, sizeof(*plr), GFP_KERNEL);
+	plr = devm_kzalloc(&auxdev->dev, struct_size(plr, die_info, num_resources), GFP_KERNEL);
 	if (!plr)
 		return -ENOMEM;
 
-	plr->die_info = devm_kcalloc(&auxdev->dev, num_resources, sizeof(*plr->die_info),
-				     GFP_KERNEL);
-	if (!plr->die_info)
-		return -ENOMEM;
-
 	plr->num_dies = num_resources;
 	plr->dbgfs_dir = debugfs_create_dir("plr", dentry);
 	plr->auxdev = auxdev;
Signature · 1 line
2.54.0
maintainer
#1 lore raw
Quoted 25 lines · Rosen Penev

Simplifies allocations slightly.

Add __counted_by for extra runtime analysis.

---
 drivers/platform/x86/intel/plr_tpmi.c | 9 ++-------
 1 file changed, 2 insertions(+), 7 deletions(-)
drivers/platform/x86/intel/plr_tpmi.c +1 -1
index 05727169f49c..2fd27e80bc1f 100644
@@ -57,9 +57,9 @@ struct tpmi_plr_die {
 
 struct tpmi_plr {
 	struct dentry *dbgfs_dir;
-	struct tpmi_plr_die *die_info;
 	int num_dies;
 	struct auxiliary_device *auxdev;
+	struct tpmi_plr_die die_info[] __counted_by(num_dies);
 };
 
 static const char * const plr_coarse_reasons[] = {

drivers/platform/x86/intel/plr_tpmi.c static int intel_plr_probe(struct auxiliary_device *auxdev, const struct auxilia · line 281

Quoted 5 lines
drivers/platform/x86/intel/plr_tpmi.c +1 -1
@@ -278,15 +278,10 @@ static int intel_plr_probe(struct auxiliary_device *auxdev, const struct auxilia
 	if (!num_resources)
 		return -EINVAL;
 
-	plr = devm_kzalloc(&auxdev->dev, sizeof(*plr), GFP_KERNEL);
+	plr = devm_kzalloc(&auxdev->dev, struct_size(plr, die_info, num_resources), GFP_KERNEL);

Is there some particular reason why we don't have devm_kzalloc_flex() other than that nobody has yet bothered to added one.

One of the most annoying thing with the various alloc APIs is that devm_* variants seem to never keep up with them. It would be nice if there would be some generic solution that when somebody decides a new alloc api func, the corresponding devm counterpart would be auto-generated for it.

Signature · 1 line
 i.
#2 lore raw
Quoted 31 lines · Ilpo Järvinen
Quoted 28 lines · Rosen Penev

Simplifies allocations slightly.

Add __counted_by for extra runtime analysis.

---
 drivers/platform/x86/intel/plr_tpmi.c | 9 ++-------
 1 file changed, 2 insertions(+), 7 deletions(-)
drivers/platform/x86/intel/plr_tpmi.c +1 -1
index 05727169f49c..2fd27e80bc1f 100644
@@ -57,9 +57,9 @@ struct tpmi_plr_die {
 
 struct tpmi_plr {
      struct dentry *dbgfs_dir;
-     struct tpmi_plr_die *die_info;
      int num_dies;
      struct auxiliary_device *auxdev;
+     struct tpmi_plr_die die_info[] __counted_by(num_dies);
 };
 
 static const char * const plr_coarse_reasons[] = {
@@ -278,15 +278,10 @@ static int intel_plr_probe(struct auxiliary_device *auxdev, const struct auxilia
      if (!num_resources)
              return -EINVAL;
 
Quoted 5 lines

drivers/platform/x86/intel/plr_tpmi.c static int intel_plr_probe(struct auxiliary_device *auxdev, const struct auxilia · line 281

Quoted 2 lines
drivers/platform/x86/intel/plr_tpmi.c +1 -1
-     plr = devm_kzalloc(&auxdev->dev, sizeof(*plr), GFP_KERNEL);
+     plr = devm_kzalloc(&auxdev->dev, struct_size(plr, die_info, num_resources), GFP_KERNEL);

Is there some particular reason why we don't have devm_kzalloc_flex() other than that nobody has yet bothered to added one.

I'm not up to date with the hardening people. Anyway when it does, this will get transformed by a treewide patch.

Quoted 9 lines

One of the most annoying thing with the various alloc APIs is that devm_* variants seem to never keep up with them. It would be nice if there would be some generic solution that when somebody decides a new alloc api func, the corresponding devm counterpart would be auto-generated for it.

--
i.