Skip to contentSkip to conversation

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

PATCH In review Rosen Penev 2 participants 2 messages May 21 x86 platform drivers

lore
Share & tools
lore
#0 lore raw

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

Simplifies allocations slightly.

Add __counted_by for extra runtime analysis.

---
v2: Rebase.

 drivers/platform/x86/intel/plr_tpmi.c | 12 ++----------
 1 file changed, 2 insertions(+), 10 deletions(-)
drivers/platform/x86/intel/plr_tpmi.c +2 -10
index 8faecc311038..66220fadf670 100644
@@ -58,11 +58,11 @@ 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 notifier_block nb;
 	struct mutex lock;	/* Protect access to dbgfs_dir */
+	struct tpmi_plr_die die_info[] __counted_by(num_dies);
 };
 
 static const char * const plr_coarse_reasons[] = {
@@ -305,7 +305,7 @@ 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;
 
@@ -315,13 +315,6 @@ static int intel_plr_probe(struct auxiliary_device *auxdev, const struct auxilia
 
 	intel_plr_register_notifier(&plr->nb);
 
-	plr->die_info = devm_kcalloc(&auxdev->dev, num_resources, sizeof(*plr->die_info),
-				     GFP_KERNEL);
-	if (!plr->die_info) {
-		err = -ENOMEM;
-		goto err_notify;
-	}
-
 	plr->num_dies = num_resources;
 	plr->dbgfs_dir = debugfs_create_dir("plr", dentry);
 	plr->auxdev = auxdev;
@@ -361,7 +354,6 @@ static int intel_plr_probe(struct auxiliary_device *auxdev, const struct auxilia
 
 err:
 	debugfs_remove_recursive(plr->dbgfs_dir);
-err_notify:
 	intel_plr_unregister_notifier(&plr->nb);
 
 	return err;
Signature · 1 line
2.54.0
maintainer
#1 lore raw
Quoted 28 lines · Rosen Penev

Simplifies allocations slightly.

Add __counted_by for extra runtime analysis.

---
v2: Rebase.

 drivers/platform/x86/intel/plr_tpmi.c | 12 ++----------
 1 file changed, 2 insertions(+), 10 deletions(-)
drivers/platform/x86/intel/plr_tpmi.c +1 -1
index 8faecc311038..66220fadf670 100644
@@ -58,11 +58,11 @@ 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 notifier_block nb;
 	struct mutex lock;	/* Protect access to dbgfs_dir */
+	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 308

Quoted 5 lines
drivers/platform/x86/intel/plr_tpmi.c +1 -1
@@ -305,7 +305,7 @@ 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);

Hi,

I'd prefer to have devm_kzalloc_flex() be added before continuing with changes like this. Last time I mentioned it, you washed your hands about adding it and moved the responsability to linux-hardening folks. (In case you didn't know, devm_kzalloc_flex() could be added even by you!)

Alternatively, I might accept a good explanation why that cannot be done or is not a good idea to have consistent interface for non-devm vs devm?

Quoted 26 lines
drivers/platform/x86/intel/plr_tpmi.c +0 -8
 	if (!plr)
 		return -ENOMEM;
 
@@ -315,13 +315,6 @@ static int intel_plr_probe(struct auxiliary_device *auxdev, const struct auxilia
 
 	intel_plr_register_notifier(&plr->nb);
 
-	plr->die_info = devm_kcalloc(&auxdev->dev, num_resources, sizeof(*plr->die_info),
-				     GFP_KERNEL);
-	if (!plr->die_info) {
-		err = -ENOMEM;
-		goto err_notify;
-	}
-
 	plr->num_dies = num_resources;
 	plr->dbgfs_dir = debugfs_create_dir("plr", dentry);
 	plr->auxdev = auxdev;
@@ -361,7 +354,6 @@ static int intel_plr_probe(struct auxiliary_device *auxdev, const struct auxilia
 
 err:
 	debugfs_remove_recursive(plr->dbgfs_dir);
-err_notify:
 	intel_plr_unregister_notifier(&plr->nb);
 
 	return err;
Signature · 1 line
 i.