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 --- 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