Skip to contentSkip to conversation

powercap: intel_rapl_tpmi: Handle PMU registration failure during probe

PATCH Superseded Sumeet Pawnikar 2 participants 2 messages May 15 – May 26 Power management core

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 powercap: intel_rapl_tpmi: Handle PMU registration failure during probe

intel_rapl_tpmi_probe() invokes rapl_package_add_pmu() but it ignores the return value, so a PMU registration failure may leave the driver reporting probe success despite the PMU being absent, with no log trace. Worse case scenario, the previously-added RAPL package would not be torn down.

Add check for the return value, log the failure, undo the package addition with rapl_remove_package() and fail the probe.

---
 drivers/powercap/intel_rapl_tpmi.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
drivers/powercap/intel_rapl_tpmi.c +8 -1
index 7f41491d9cd1..8bc95310b542 100644
@@ -414,7 +414,14 @@ static int intel_rapl_tpmi_probe(struct auxiliary_device *auxdev,
 		goto err;
 	}
 
-	rapl_package_add_pmu(trp->rp);
+	ret = rapl_package_add_pmu(trp->rp);
+	if (ret) {
+		dev_err(&auxdev->dev, "Failed to add RAPL PMU for Package%d, %d\n",
+			info->package_id, ret);
+		rapl_remove_package(trp->rp);
+		trp->rp = NULL;
+		goto err;
+	}
 
 	auxiliary_set_drvdata(auxdev, trp);
 
Signature · 1 line
2.43.0
#1 lore raw
Quoted 25 lines · Sumeet Pawnikar

intel_rapl_tpmi_probe() invokes rapl_package_add_pmu() but it ignores the return value, so a PMU registration failure may leave the driver reporting probe success despite the PMU being absent, with no log trace. Worse case scenario, the previously-added RAPL package would not be torn down.

Add check for the return value, log the failure, undo the package addition with rapl_remove_package() and fail the probe.

---
 drivers/powercap/intel_rapl_tpmi.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
drivers/powercap/intel_rapl_tpmi.c +1 -1
index 7f41491d9cd1..8bc95310b542 100644
@@ -414,7 +414,14 @@ static int intel_rapl_tpmi_probe(struct auxiliary_device *auxdev,
                goto err;
        }
 
-       rapl_package_add_pmu(trp->rp);
+       ret = rapl_package_add_pmu(trp->rp);

drivers/powercap/intel_rapl_tpmi.c static int intel_rapl_tpmi_probe(struct auxiliary_device *auxdev, · line 427

Quoted 10 lines
drivers/powercap/intel_rapl_tpmi.c +7 -0
+       if (ret) {
+               dev_err(&auxdev->dev, "Failed to add RAPL PMU for Package%d, %d\n",
+                       info->package_id, ret);
+               rapl_remove_package(trp->rp);
+               trp->rp = NULL;
+               goto err;
+       }
 
        auxiliary_set_drvdata(auxdev, trp);
 

Please see the sashiko.dev feedback on this:

https://sashiko.dev/#/patchset/20260515184250.228062-1-sumeet4linux%40gmail.com

and either address it or explain to me why it doesn't need to be addressed.

Thanks!