diff mbox series

[V2,2/3] soc/tegra: pmc: Remove reset sysfs entries on error

Message ID 1555433288-16967-2-git-send-email-jonathanh@nvidia.com
State Accepted
Headers show
Series [V2,1/3] soc/tegra: pmc: Fix reset sources and levels | expand

Commit Message

Jon Hunter April 16, 2019, 4:48 p.m. UTC
Commit 5f84bb1a4099 ("soc/tegra: pmc: Add sysfs entries for reset info")
added sysfs entries for Tegra reset source and level. However, these
sysfs are not removed on error and so if the registering of PMC device
is probe deferred, then the next time we attempt to probe the PMC device
warnings such as the following will be displayed on boot ...

 sysfs: cannot create duplicate filename '/devices/platform/7000e400.pmc/reset_reason'

Fix this by calling device_remove_file() for each sysfs entry added on
failure. Note that we call device_remove_file() unconditionally without
checking if the sysfs entry was created in the first place, but this
should be OK because kernfs_remove_by_name_ns() will fail silently.

Fixes: 5f84bb1a4099 ("soc/tegra: pmc: Add sysfs entries for reset info")
Signed-off-by: Jon Hunter <jonathanh@nvidia.com>

soc/tegra: pmc:
---
Changes since V1:
- Reverted changes to tegra_pmc_reset_sysfs_init()
- Added unconditional calls to device_remove_file() in error path

 drivers/soc/tegra/pmc.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

Comments

Jon Hunter April 16, 2019, 9:18 p.m. UTC | #1
On 16/04/2019 17:48, Jon Hunter wrote:
> Commit 5f84bb1a4099 ("soc/tegra: pmc: Add sysfs entries for reset info")
> added sysfs entries for Tegra reset source and level. However, these
> sysfs are not removed on error and so if the registering of PMC device
> is probe deferred, then the next time we attempt to probe the PMC device
> warnings such as the following will be displayed on boot ...
> 
>  sysfs: cannot create duplicate filename '/devices/platform/7000e400.pmc/reset_reason'
> 
> Fix this by calling device_remove_file() for each sysfs entry added on
> failure. Note that we call device_remove_file() unconditionally without
> checking if the sysfs entry was created in the first place, but this
> should be OK because kernfs_remove_by_name_ns() will fail silently.
> 
> Fixes: 5f84bb1a4099 ("soc/tegra: pmc: Add sysfs entries for reset info")
> Signed-off-by: Jon Hunter <jonathanh@nvidia.com>
> 
> soc/tegra: pmc:

Ugh, the above line should not be there!

Jon
Thierry Reding April 17, 2019, 8:34 a.m. UTC | #2
On Tue, Apr 16, 2019 at 05:48:07PM +0100, Jon Hunter wrote:
> Commit 5f84bb1a4099 ("soc/tegra: pmc: Add sysfs entries for reset info")
> added sysfs entries for Tegra reset source and level. However, these
> sysfs are not removed on error and so if the registering of PMC device
> is probe deferred, then the next time we attempt to probe the PMC device
> warnings such as the following will be displayed on boot ...
> 
>  sysfs: cannot create duplicate filename '/devices/platform/7000e400.pmc/reset_reason'
> 
> Fix this by calling device_remove_file() for each sysfs entry added on
> failure. Note that we call device_remove_file() unconditionally without
> checking if the sysfs entry was created in the first place, but this
> should be OK because kernfs_remove_by_name_ns() will fail silently.
> 
> Fixes: 5f84bb1a4099 ("soc/tegra: pmc: Add sysfs entries for reset info")
> Signed-off-by: Jon Hunter <jonathanh@nvidia.com>
> 
> soc/tegra: pmc:
> ---
> Changes since V1:
> - Reverted changes to tegra_pmc_reset_sysfs_init()
> - Added unconditional calls to device_remove_file() in error path
> 
>  drivers/soc/tegra/pmc.c | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)

Applied to for-5.2/soc, with that extra line removed, thanks.

Thierry
diff mbox series

Patch

diff --git a/drivers/soc/tegra/pmc.c b/drivers/soc/tegra/pmc.c
index 7953aa7b11df..741afb141887 100644
--- a/drivers/soc/tegra/pmc.c
+++ b/drivers/soc/tegra/pmc.c
@@ -2040,7 +2040,7 @@  static int tegra_pmc_probe(struct platform_device *pdev)
 	if (IS_ENABLED(CONFIG_DEBUG_FS)) {
 		err = tegra_powergate_debugfs_init();
 		if (err < 0)
-			return err;
+			goto cleanup_sysfs;
 	}
 
 	err = register_restart_handler(&tegra_pmc_restart_handler);
@@ -2071,6 +2071,9 @@  static int tegra_pmc_probe(struct platform_device *pdev)
 	unregister_restart_handler(&tegra_pmc_restart_handler);
 cleanup_debugfs:
 	debugfs_remove(pmc->debugfs);
+cleanup_sysfs:
+	device_remove_file(&pdev->dev, &dev_attr_reset_reason);
+	device_remove_file(&pdev->dev, &dev_attr_reset_level);
 	return err;
 }