soc/tegra: pmc: Simplify debugfs initialization
PATCH 1/2 soc/tegra: pmc: Simplify debugfs initialization
From: Thierry Reding <[email protected]>
debugfs calls should generally not be error-checked to simplify the case where debugfs is disabled. Since this driver is built-in and has the sysfs bind/unbind attributes disabled, it cannot be unloaded, so there is no need to hold onto a reference to the debugfs files that are created.
We can further simplify this by moving the debugfs file creation to a later stage to avoid any cleanup we might have to do during error unwind operations. This is also a little cleaner because the debugfs file relies on data structures that are created at a later point than when the file was previously created.
--- drivers/soc/tegra/pmc.c | 26 ++++---------------------- 1 file changed, 4 insertions(+), 22 deletions(-)
drivers/soc/tegra/pmc.c +4 -22
@@ -396,7 +396,6 @@ struct tegra_pmc_soc {* @clk: pointer to pclk clock * @soc: pointer to SoC data structure * @tz_only: flag specifying if the PMC can only be accessed via TrustZone -* @debugfs: pointer to debugfs entry * @rate: currently configured rate of pclk * @suspend_mode: lowest suspend mode available * @cpu_good_time: CPU power good time (in microseconds)
@@ -431,7 +430,6 @@ struct tegra_pmc {void __iomem *aotag;void __iomem *scratch;struct clk *clk; -struct dentry *debugfs;const struct tegra_pmc_soc *soc;bool tz_only;
@@ -1190,16 +1188,6 @@ static int powergate_show(struct seq_file *s, void *data)DEFINE_SHOW_ATTRIBUTE (powergate); -static int tegra_powergate_debugfs_init (void ) -{ - pmc->debugfs =debugfs_create_file ("powergate" ,S_IRUGO ,NULL ,NULL , - &powergate_fops); -if (!pmc->debugfs) -return -ENOMEM ; - -return 0 ; -} -static int tegra_powergate_of_get_clks (struct tegra_powergate *pg,struct device_node *np) {
@@ -3026,19 +3014,13 @@ static int tegra_pmc_probe(struct platform_device *pdev)tegra_pmc_reset_sysfs_init (pmc); -if (IS_ENABLED (CONFIG_DEBUG_FS )) { - err =tegra_powergate_debugfs_init (); -if (err <0 ) - goto cleanup_sysfs; - } - err =tegra_pmc_pinctrl_init (pmc);if (err) - goto cleanup_debugfs; + goto cleanup_sysfs; err =tegra_pmc_regmap_init (pmc);if (err <0 ) - goto cleanup_debugfs; + goto cleanup_sysfs; err =tegra_powergate_init (pmc, pdev->dev.of_node);if (err <0 )
@@ -3061,12 +3043,12 @@ static int tegra_pmc_probe(struct platform_device *pdev)if (pmc->soc->set_wake_filters) pmc->soc->set_wake_filters (pmc); +debugfs_create_file ("powergate" ,0444 ,NULL ,NULL , &powergate_fops); +return 0 ; cleanup_powergates:tegra_powergate_remove_all (pdev->dev.of_node); -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);
Signature · 1 line
2.40.1
PATCH 2/2 soc/tegra: pmc: Use devm_clk_notifier_register()
From: Thierry Reding <[email protected]>
Move to the device-managed version of clk_notifier_register() to remove the need for manual cleanup. This fixes a potential issue where the clock notifier would stick around after the driver fails to probe at a later point.
--- drivers/soc/tegra/pmc.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/soc/tegra/pmc.c +2 -2
@@ -2992,7 +2992,8 @@ static int tegra_pmc_probe(struct platform_device *pdev)*/ if (pmc->clk) { pmc->clk_nb.notifier_call = tegra_pmc_clk_notify_cb; - err =clk_notifier_register (pmc->clk, &pmc->clk_nb); + err =devm_clk_notifier_register (&pdev->dev, pmc->clk, + &pmc->clk_nb);if (err) {dev_err (&pdev->dev,"failed to register clk notifier\n" );
@@ -3052,7 +3053,6 @@ static int tegra_pmc_probe(struct platform_device *pdev) cleanup_sysfs:device_remove_file (&pdev->dev, &dev_attr_reset_reason);device_remove_file (&pdev->dev, &dev_attr_reset_level); -clk_notifier_unregister (pmc->clk, &pmc->clk_nb);return err; }
Signature · 1 line
2.40.1
Re: [PATCH 2/2] soc/tegra: pmc: Use devm_clk_notifier_register()
Quoted 27 lines · Thierry Reding
From: Thierry Reding <[email protected]>
Move to the device-managed version of
clk_notifier_register()to remove the need for manual cleanup. This fixes a potential issue where the clock notifier would stick around after the driver fails to probe at a later point.Signed-off-by Thierry Reding <[email protected]>--- drivers/soc/tegra/pmc.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)drivers/soc/tegra/pmc.c +2
-1@@ -2992,7 +2992,8 @@ static int tegra_pmc_probe(struct platform_device *pdev)*/ if (pmc->clk) { pmc->clk_nb.notifier_call = tegra_pmc_clk_notify_cb; - err =clk_notifier_register (pmc->clk, &pmc->clk_nb); + err =devm_clk_notifier_register (&pdev->dev, pmc->clk, + &pmc->clk_nb);if (err) {dev_err (&pdev->dev,"failed to register clk notifier\n" );
drivers/soc/tegra/pmc.c static int tegra_pmc_probe(struct platform_device *pdev) · line 3058
Quoted 7 lines
drivers/soc/tegra/pmc.c +0
-1@@ -3052,7 +3053,6 @@ static int tegra_pmc_probe(struct platform_device *pdev) cleanup_sysfs:device_remove_file (&pdev->dev, &dev_attr_reset_reason);device_remove_file (&pdev->dev, &dev_attr_reset_level); -clk_notifier_unregister (pmc->clk, &pmc->clk_nb);return err; }
Thanks!
Jon
Signature · 1 line
nvpublic
Quoted 84 lines · Thierry Reding
From: Thierry Reding <[email protected]>
debugfs calls should generally not be error-checked to simplify the case where debugfs is disabled. Since this driver is built-in and has the sysfs bind/unbind attributes disabled, it cannot be unloaded, so there is no need to hold onto a reference to the debugfs files that are created.
We can further simplify this by moving the debugfs file creation to a later stage to avoid any cleanup we might have to do during error unwind operations. This is also a little cleaner because the debugfs file relies on data structures that are created at a later point than when the file was previously created.
Suggested-by Jon Hunter <[email protected]>Signed-off-by Thierry Reding <[email protected]>--- drivers/soc/tegra/pmc.c | 26 ++++---------------------- 1 file changed, 4 insertions(+), 22 deletions(-)drivers/soc/tegra/pmc.c +3
-20@@ -396,7 +396,6 @@ struct tegra_pmc_soc {* @clk: pointer to pclk clock * @soc: pointer to SoC data structure * @tz_only: flag specifying if the PMC can only be accessed via TrustZone -* @debugfs: pointer to debugfs entry * @rate: currently configured rate of pclk * @suspend_mode: lowest suspend mode available * @cpu_good_time: CPU power good time (in microseconds) @@ -431,7 +430,6 @@ struct tegra_pmc {void __iomem *aotag;void __iomem *scratch;struct clk *clk; -struct dentry *debugfs;const struct tegra_pmc_soc *soc;bool tz_only;@@ -1190,16 +1188,6 @@ static int powergate_show(struct seq_file *s, void *data)DEFINE_SHOW_ATTRIBUTE (powergate); -static int tegra_powergate_debugfs_init (void ) -{ - pmc->debugfs =debugfs_create_file ("powergate" ,S_IRUGO ,NULL ,NULL , - &powergate_fops); -if (!pmc->debugfs) -return -ENOMEM ; - -return 0 ; -} -static int tegra_powergate_of_get_clks (struct tegra_powergate *pg,struct device_node *np) {@@ -3026,19 +3014,13 @@ static int tegra_pmc_probe(struct platform_device *pdev)tegra_pmc_reset_sysfs_init (pmc); -if (IS_ENABLED (CONFIG_DEBUG_FS )) { - err =tegra_powergate_debugfs_init (); -if (err <0 ) - goto cleanup_sysfs; - } - err =tegra_pmc_pinctrl_init (pmc);if (err) - goto cleanup_debugfs; + goto cleanup_sysfs; err =tegra_pmc_regmap_init (pmc);if (err <0 ) - goto cleanup_debugfs; + goto cleanup_sysfs; err =tegra_powergate_init (pmc, pdev->dev.of_node);if (err <0 )@@ -3061,12 +3043,12 @@ static int tegra_pmc_probe(struct platform_device *pdev)if (pmc->soc->set_wake_filters) pmc->soc->set_wake_filters (pmc); +debugfs_create_file ("powergate" ,0444 ,NULL ,NULL , &powergate_fops);
drivers/soc/tegra/pmc.c static int tegra_pmc_probe(struct platform_device *pdev) · line 3054
Quoted 10 lines
drivers/soc/tegra/pmc.c +1
-2+return 0 ; cleanup_powergates:tegra_powergate_remove_all (pdev->dev.of_node); -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);
Great!
Thanks
Jon
Signature · 1 line
nvpublic