Skip to contentSkip to conversation

platform/x86/intel/pmt: Fix kobject memory leak on init failure

PATCH In review Kaushlendra Kumar 2 participants 3 messages Dec 23, 2025 – Dec 24, 2025

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 platform/x86/intel/pmt: Fix kobject memory leak on init failure

When kobject_init_and_add() fails in pmt_features_discovery(), the function returns without calling kobject_put(). This violates the kobject API contract where kobject_put() must be called even on initialization failure to properly release allocated resources.

---
 drivers/platform/x86/intel/pmt/discovery.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/platform/x86/intel/pmt/discovery.c +3 -1
index 32713a194a55..9c5b4d0e1fae 100644
@@ -503,8 +503,10 @@ static int pmt_features_discovery(struct pmt_features_priv *priv,
 
 	ret = kobject_init_and_add(&feature->kobj, ktype, &priv->dev->kobj,
 				   "%s", pmt_feature_names[feature->id]);
-	if (ret)
+	if (ret) {
+		kobject_put(&feature->kobj);
 		return ret;
+	}
 
 	kobject_uevent(&feature->kobj, KOBJ_ADD);
 	pmt_features_add_feat(feature);
Signature · 1 line
2.34.1
maintainer
#1 lore raw
Quoted 6 lines · Kaushlendra Kumar

When kobject_init_and_add() fails in pmt_features_discovery(), the function returns without calling kobject_put(). This violates the kobject API contract where kobject_put() must be called even on initialization failure to properly release allocated resources.

Hi,

Thanks, I've applied this to the review-ilpo-fixes branch but I had to add Fixes tag myself as your submission did not contain one. In the future, when fixing an issue, please add a Fixes tag pointing to the commit that introduced the problem.

Quoted 20 lines
---
 drivers/platform/x86/intel/pmt/discovery.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/platform/x86/intel/pmt/discovery.c +3 -1
index 32713a194a55..9c5b4d0e1fae 100644
@@ -503,8 +503,10 @@ static int pmt_features_discovery(struct pmt_features_priv *priv,
 
 	ret = kobject_init_and_add(&feature->kobj, ktype, &priv->dev->kobj,
 				   "%s", pmt_feature_names[feature->id]);
-	if (ret)
+	if (ret) {
+		kobject_put(&feature->kobj);
 		return ret;
+	}
 
 	kobject_uevent(&feature->kobj, KOBJ_ADD);
 	pmt_features_add_feat(feature);
Signature · 1 line
 i.
#2 lore raw
Quoted 6 lines · Ilpo Järvinen

Hi,

Thanks, I've applied this to the review-ilpo-fixes branch but I had to add Fixes tag myself as your submission did not contain one. In the future, when fixing an issue, please add a Fixes tag pointing to the commit that introduced the problem.

Hi Ilpo,

Thank you for applying the patch and adding the Fixes tag. I'll ensure to include it in future submissions.

Thanks,
Kaushlendra