* [PATCH] thermal: qcom: tsens: Fix potential repeated removal of shared debugfs root
@ 2026-11-20 17:35 Guangshuo Li
2026-11-30 11:15 ` Konrad Dybcio
0 siblings, 1 reply; 2+ messages in thread
From: Guangshuo Li @ 2026-11-20 17:35 UTC (permalink / raw)
To: Amit Kucheria, Thara Gopinath, Rafael J. Wysocki, Daniel Lezcano,
Zhang Rui, Lukasz Luba
Cc: linux-arm-msm, linux-pm, linux-kernel, stable
Each TSENS instance stores the same debugfs root and removes it during
teardown. Removing one instance therefore removes the files of its
peers, and subsequent removal operates on the same root again.
Own the root at driver initialization and exit. Each instance only
removes its own directory, leaving the shared root to the driver.
This issue was found by our static analysis tool under development.
Fixes: 7c938f4837ab ("drivers: thermal: tsens: Add debugfs support")
Cc: stable@vger.kernel.org
Signed-off-by: Guangshuo Li <liguangshuo@mail.sdu.edu.cn>
---
drivers/thermal/qcom/tsens.c | 31 ++++++++++++++++++++++++-------
1 file changed, 24 insertions(+), 7 deletions(-)
diff --git a/drivers/thermal/qcom/tsens.c b/drivers/thermal/qcom/tsens.c
index 4d7013fc79d6..e0fdeafdca30 100644
--- a/drivers/thermal/qcom/tsens.c
+++ b/drivers/thermal/qcom/tsens.c
@@ -22,6 +22,8 @@
#include "../thermal_hwmon.h"
#include "tsens.h"
+static struct dentry *tsens_debugfs_root;
+
/**
* struct tsens_irq_data - IRQ status and temperature violations
* @up_viol: upper threshold violated
@@ -902,12 +904,8 @@ static void tsens_debug_init(struct platform_device *pdev)
{
struct tsens_priv *priv = platform_get_drvdata(pdev);
- priv->debug_root = debugfs_lookup("tsens", NULL);
- if (!priv->debug_root)
- priv->debug_root = debugfs_create_dir("tsens", NULL);
-
/* A directory for each instance of the TSENS IP */
- priv->debug = debugfs_create_dir(dev_name(&pdev->dev), priv->debug_root);
+ priv->debug = debugfs_create_dir(dev_name(&pdev->dev), tsens_debugfs_root);
debugfs_create_file("version", 0444, priv->debug, pdev, &dbg_version_fops);
debugfs_create_file("sensors", 0444, priv->debug, pdev, &dbg_sensors_fops);
}
@@ -1459,7 +1457,7 @@ static void tsens_remove(struct platform_device *pdev)
{
struct tsens_priv *priv = platform_get_drvdata(pdev);
- debugfs_remove_recursive(priv->debug_root);
+ debugfs_remove_recursive(priv->debug);
tsens_disable_irq(priv);
if (priv->ops->disable)
priv->ops->disable(priv);
@@ -1474,7 +1472,26 @@ static struct platform_driver tsens_driver = {
.of_match_table = tsens_table,
},
};
-module_platform_driver(tsens_driver);
+
+static int __init tsens_init(void)
+{
+ int ret;
+
+ tsens_debugfs_root = debugfs_create_dir("tsens", NULL);
+ ret = platform_driver_register(&tsens_driver);
+ if (ret)
+ debugfs_remove_recursive(tsens_debugfs_root);
+
+ return ret;
+}
+module_init(tsens_init);
+
+static void __exit tsens_exit(void)
+{
+ platform_driver_unregister(&tsens_driver);
+ debugfs_remove_recursive(tsens_debugfs_root);
+}
+module_exit(tsens_exit);
MODULE_LICENSE("GPL v2");
MODULE_DESCRIPTION("QCOM Temperature Sensor driver");
base-commit: 6628e7d4c6b25c8d18f1345e3a20d21829aae7e4
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] thermal: qcom: tsens: Fix potential repeated removal of shared debugfs root
2026-11-20 17:35 [PATCH] thermal: qcom: tsens: Fix potential repeated removal of shared debugfs root Guangshuo Li
@ 2026-11-30 11:15 ` Konrad Dybcio
0 siblings, 0 replies; 2+ messages in thread
From: Konrad Dybcio @ 2026-11-30 11:15 UTC (permalink / raw)
To: Guangshuo Li, Amit Kucheria, Thara Gopinath, Rafael J. Wysocki,
Daniel Lezcano, Zhang Rui, Lukasz Luba
Cc: linux-arm-msm, linux-pm, linux-kernel, stable
On 11/20/26 6:35 PM, Guangshuo Li wrote:
> Each TSENS instance stores the same debugfs root and removes it during
> teardown. Removing one instance therefore removes the files of its
> peers, and subsequent removal operates on the same root again.
>
> Own the root at driver initialization and exit. Each instance only
> removes its own directory, leaving the shared root to the driver.
>
> This issue was found by our static analysis tool under development.
>
> Fixes: 7c938f4837ab ("drivers: thermal: tsens: Add debugfs support")
> Cc: stable@vger.kernel.org
> Signed-off-by: Guangshuo Li <liguangshuo@mail.sdu.edu.cn>
> ---
Reviewed-by: Konrad Dybcio <konrad.dybcio@oss.qualcomm.com>
Konrad
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-11-30 11:15 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-20 17:35 [PATCH] thermal: qcom: tsens: Fix potential repeated removal of shared debugfs root Guangshuo Li
2026-11-30 11:15 ` Konrad Dybcio
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®