soc/tegra: pmc: Simplify debugfs initialization
authorThierry Reding <treding@nvidia.com>
Fri, 9 Jun 2023 14:42:24 +0000 (16:42 +0200)
committerThierry Reding <treding@nvidia.com>
Fri, 9 Jun 2023 14:56:57 +0000 (16:56 +0200)
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 <jonathanh@nvidia.com>
Reviewed-by: Jon Hunter <jonathanh@nvidia.com>
Signed-off-by: Thierry Reding <treding@nvidia.com>
drivers/soc/tegra/pmc.c

index b562b00..438c30c 100644 (file)
@@ -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);