platform/x86/intel/pmt: Fix kobject memory leak on init failure
Subsystems (2)
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
@@ -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
Ilpo Järvinen
maintainerQuoted 6 lines · Kaushlendra Kumar
When
kobject_init_and_add()fails inpmt_features_discovery(), the function returns without callingkobject_put(). This violates the kobject API contract wherekobject_put()must be called even on initialization failure to properly release allocated resources.Signed-off-by Kaushlendra Kumar <[email protected]>
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@@ -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.
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