LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
* [PATCH v1 0/4] Make probe() of Tegra devfreq driver completely resource-managed
@ 2021-09-12 18:44 Dmitry Osipenko
  2021-09-12 18:44 ` [PATCH v1 1/4] opp: Add more resource-managed variants of dev_pm_opp_of_add_table() Dmitry Osipenko
                   ` (3 more replies)
  0 siblings, 4 replies; 13+ messages in thread
From: Dmitry Osipenko @ 2021-09-12 18:44 UTC (permalink / raw)
  To: Thierry Reding, Jonathan Hunter, Viresh Kumar, Nishanth Menon,
	MyungJoo Ham, Stephen Boyd, Kyungmin Park, Chanwoo Choi
  Cc: linux-tegra, linux-kernel, linux-pm

This series adds new resource-managed helpers and makes Tegra devfreq
driver to use them, improving the driver's error-handling code.

Dmitry Osipenko (4):
  opp: Add more resource-managed variants of dev_pm_opp_of_add_table()
  PM / devfreq: Add devm_devfreq_add_governor()
  PM / devfreq: tegra30: Use resource-managed helpers
  PM / devfreq: tegra30: Check whether clk_round_rate() returns zero
    rate

 drivers/devfreq/devfreq.c         |  26 +++++++
 drivers/devfreq/governor.h        |   3 +
 drivers/devfreq/tegra30-devfreq.c | 109 +++++++++++++-----------------
 drivers/opp/of.c                  |  46 +++++++++++--
 include/linux/pm_opp.h            |  12 ++++
 5 files changed, 127 insertions(+), 69 deletions(-)

-- 
2.32.0


^ permalink raw reply	[flat|nested] 13+ messages in thread

* [PATCH v1 1/4] opp: Add more resource-managed variants of dev_pm_opp_of_add_table()
  2021-09-12 18:44 [PATCH v1 0/4] Make probe() of Tegra devfreq driver completely resource-managed Dmitry Osipenko
@ 2021-09-12 18:44 ` Dmitry Osipenko
  2021-09-12 18:44 ` [PATCH v1 2/4] PM / devfreq: Add devm_devfreq_add_governor() Dmitry Osipenko
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 13+ messages in thread
From: Dmitry Osipenko @ 2021-09-12 18:44 UTC (permalink / raw)
  To: Thierry Reding, Jonathan Hunter, Viresh Kumar, Nishanth Menon,
	MyungJoo Ham, Stephen Boyd, Kyungmin Park, Chanwoo Choi
  Cc: linux-tegra, linux-kernel, linux-pm

Add resource-managed variants of dev_pm_opp_of_add_table_indexed() and
dev_pm_opp_of_add_table_noclk(), allowing drivers to remove boilerplate
code.

Signed-off-by: Dmitry Osipenko <digetx@gmail.com>
---
 drivers/opp/of.c       | 46 +++++++++++++++++++++++++++++++++++-------
 include/linux/pm_opp.h | 12 +++++++++++
 2 files changed, 51 insertions(+), 7 deletions(-)

diff --git a/drivers/opp/of.c b/drivers/opp/of.c
index 2a97c6535c4c..bd01ecb1d85c 100644
--- a/drivers/opp/of.c
+++ b/drivers/opp/of.c
@@ -1081,6 +1081,17 @@ static void devm_pm_opp_of_table_release(void *data)
 	dev_pm_opp_of_remove_table(data);
 }
 
+static int devm_of_add_table_indexed(struct device *dev, int index, bool getclk)
+{
+	int ret;
+
+	ret = _of_add_table_indexed(dev, index, getclk);
+	if (ret)
+		return ret;
+
+	return devm_add_action_or_reset(dev, devm_pm_opp_of_table_release, dev);
+}
+
 /**
  * devm_pm_opp_of_add_table() - Initialize opp table from device tree
  * @dev:	device pointer used to lookup OPP table.
@@ -1102,13 +1113,7 @@ static void devm_pm_opp_of_table_release(void *data)
  */
 int devm_pm_opp_of_add_table(struct device *dev)
 {
-	int ret;
-
-	ret = dev_pm_opp_of_add_table(dev);
-	if (ret)
-		return ret;
-
-	return devm_add_action_or_reset(dev, devm_pm_opp_of_table_release, dev);
+	return devm_of_add_table_indexed(dev, 0, true);
 }
 EXPORT_SYMBOL_GPL(devm_pm_opp_of_add_table);
 
@@ -1151,6 +1156,19 @@ int dev_pm_opp_of_add_table_indexed(struct device *dev, int index)
 }
 EXPORT_SYMBOL_GPL(dev_pm_opp_of_add_table_indexed);
 
+/**
+ * devm_pm_opp_of_add_table_indexed() - Initialize indexed opp table from device tree
+ * @dev:	device pointer used to lookup OPP table.
+ * @index:	Index number.
+ *
+ * This is a resource-managed variant of dev_pm_opp_of_add_table_indexed().
+ */
+int devm_pm_opp_of_add_table_indexed(struct device *dev, int index)
+{
+	return devm_of_add_table_indexed(dev, index, true);
+}
+EXPORT_SYMBOL_GPL(devm_pm_opp_of_add_table_indexed);
+
 /**
  * dev_pm_opp_of_add_table_noclk() - Initialize indexed opp table from device
  *		tree without getting clk for device.
@@ -1169,6 +1187,20 @@ int dev_pm_opp_of_add_table_noclk(struct device *dev, int index)
 }
 EXPORT_SYMBOL_GPL(dev_pm_opp_of_add_table_noclk);
 
+/**
+ * devm_pm_opp_of_add_table_noclk() - Initialize indexed opp table from device
+ *		tree without getting clk for device.
+ * @dev:	device pointer used to lookup OPP table.
+ * @index:	Index number.
+ *
+ * This is a resource-managed variant of dev_pm_opp_of_add_table_noclk().
+ */
+int devm_pm_opp_of_add_table_noclk(struct device *dev, int index)
+{
+	return devm_of_add_table_indexed(dev, index, false);
+}
+EXPORT_SYMBOL_GPL(devm_pm_opp_of_add_table_noclk);
+
 /* CPU device specific helpers */
 
 /**
diff --git a/include/linux/pm_opp.h b/include/linux/pm_opp.h
index 84150a22fd7c..a95d6fdd20b6 100644
--- a/include/linux/pm_opp.h
+++ b/include/linux/pm_opp.h
@@ -439,7 +439,9 @@ static inline int dev_pm_opp_sync_regulators(struct device *dev)
 #if defined(CONFIG_PM_OPP) && defined(CONFIG_OF)
 int dev_pm_opp_of_add_table(struct device *dev);
 int dev_pm_opp_of_add_table_indexed(struct device *dev, int index);
+int devm_pm_opp_of_add_table_indexed(struct device *dev, int index);
 int dev_pm_opp_of_add_table_noclk(struct device *dev, int index);
+int devm_pm_opp_of_add_table_noclk(struct device *dev, int index);
 void dev_pm_opp_of_remove_table(struct device *dev);
 int devm_pm_opp_of_add_table(struct device *dev);
 int dev_pm_opp_of_cpumask_add_table(const struct cpumask *cpumask);
@@ -465,11 +467,21 @@ static inline int dev_pm_opp_of_add_table_indexed(struct device *dev, int index)
 	return -EOPNOTSUPP;
 }
 
+static inline int devm_pm_opp_of_add_table_indexed(struct device *dev, int index)
+{
+	return -EOPNOTSUPP;
+}
+
 static inline int dev_pm_opp_of_add_table_noclk(struct device *dev, int index)
 {
 	return -EOPNOTSUPP;
 }
 
+static inline int devm_pm_opp_of_add_table_noclk(struct device *dev, int index)
+{
+	return -EOPNOTSUPP;
+}
+
 static inline void dev_pm_opp_of_remove_table(struct device *dev)
 {
 }
-- 
2.32.0


^ permalink raw reply	[flat|nested] 13+ messages in thread

* [PATCH v1 2/4] PM / devfreq: Add devm_devfreq_add_governor()
  2021-09-12 18:44 [PATCH v1 0/4] Make probe() of Tegra devfreq driver completely resource-managed Dmitry Osipenko
  2021-09-12 18:44 ` [PATCH v1 1/4] opp: Add more resource-managed variants of dev_pm_opp_of_add_table() Dmitry Osipenko
@ 2021-09-12 18:44 ` Dmitry Osipenko
  2021-09-15 18:23   ` Chanwoo Choi
  2021-09-15 18:37   ` Chanwoo Choi
  2021-09-12 18:44 ` [PATCH v1 3/4] PM / devfreq: tegra30: Use resource-managed helpers Dmitry Osipenko
  2021-09-12 18:44 ` [PATCH v1 4/4] PM / devfreq: tegra30: Check whether clk_round_rate() returns zero rate Dmitry Osipenko
  3 siblings, 2 replies; 13+ messages in thread
From: Dmitry Osipenko @ 2021-09-12 18:44 UTC (permalink / raw)
  To: Thierry Reding, Jonathan Hunter, Viresh Kumar, Nishanth Menon,
	MyungJoo Ham, Stephen Boyd, Kyungmin Park, Chanwoo Choi
  Cc: linux-tegra, linux-kernel, linux-pm

Add resource-managed variant of devfreq_add_governor().

Signed-off-by: Dmitry Osipenko <digetx@gmail.com>
---
 drivers/devfreq/devfreq.c  | 26 ++++++++++++++++++++++++++
 drivers/devfreq/governor.h |  3 +++
 2 files changed, 29 insertions(+)

diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c
index 85faa7a5c7d1..d3af000ec290 100644
--- a/drivers/devfreq/devfreq.c
+++ b/drivers/devfreq/devfreq.c
@@ -1301,6 +1301,32 @@ int devfreq_add_governor(struct devfreq_governor *governor)
 }
 EXPORT_SYMBOL(devfreq_add_governor);
 
+static void devm_devfreq_remove_governor(void *governor)
+{
+	devfreq_remove_governor(governor);
+}
+
+/**
+ * devm_devfreq_add_governor() - Add devfreq governor
+ * @dev:	device which adds devfreq governor
+ * @governor:	the devfreq governor to be added
+ *
+ * This is a resource-managed variant of devfreq_add_governor().
+ */
+int devm_devfreq_add_governor(struct device *dev,
+			      struct devfreq_governor *governor)
+{
+	int err;
+
+	err = devfreq_add_governor(governor);
+	if (err)
+		return err;
+
+	return devm_add_action_or_reset(dev, devm_devfreq_remove_governor,
+					governor);
+}
+EXPORT_SYMBOL(devm_devfreq_add_governor);
+
 /**
  * devfreq_remove_governor() - Remove devfreq feature from a device.
  * @governor:	the devfreq governor to be removed
diff --git a/drivers/devfreq/governor.h b/drivers/devfreq/governor.h
index 2d69a0ce6291..0d70a9ad951e 100644
--- a/drivers/devfreq/governor.h
+++ b/drivers/devfreq/governor.h
@@ -94,4 +94,7 @@ static inline int devfreq_update_stats(struct devfreq *df)
 
 	return df->profile->get_dev_status(df->dev.parent, &df->last_status);
 }
+
+int devm_devfreq_add_governor(struct device *dev,
+			      struct devfreq_governor *governor);
 #endif /* _GOVERNOR_H */
-- 
2.32.0


^ permalink raw reply	[flat|nested] 13+ messages in thread

* [PATCH v1 3/4] PM / devfreq: tegra30: Use resource-managed helpers
  2021-09-12 18:44 [PATCH v1 0/4] Make probe() of Tegra devfreq driver completely resource-managed Dmitry Osipenko
  2021-09-12 18:44 ` [PATCH v1 1/4] opp: Add more resource-managed variants of dev_pm_opp_of_add_table() Dmitry Osipenko
  2021-09-12 18:44 ` [PATCH v1 2/4] PM / devfreq: Add devm_devfreq_add_governor() Dmitry Osipenko
@ 2021-09-12 18:44 ` Dmitry Osipenko
  2021-09-12 18:44 ` [PATCH v1 4/4] PM / devfreq: tegra30: Check whether clk_round_rate() returns zero rate Dmitry Osipenko
  3 siblings, 0 replies; 13+ messages in thread
From: Dmitry Osipenko @ 2021-09-12 18:44 UTC (permalink / raw)
  To: Thierry Reding, Jonathan Hunter, Viresh Kumar, Nishanth Menon,
	MyungJoo Ham, Stephen Boyd, Kyungmin Park, Chanwoo Choi
  Cc: linux-tegra, linux-kernel, linux-pm

Use resource-managed API helpers to simplify driver's probe() function,
making code cleaner.

Signed-off-by: Dmitry Osipenko <digetx@gmail.com>
---
 drivers/devfreq/tegra30-devfreq.c | 107 +++++++++++++-----------------
 1 file changed, 46 insertions(+), 61 deletions(-)

diff --git a/drivers/devfreq/tegra30-devfreq.c b/drivers/devfreq/tegra30-devfreq.c
index 10661eb2aed8..d83fdc2713ed 100644
--- a/drivers/devfreq/tegra30-devfreq.c
+++ b/drivers/devfreq/tegra30-devfreq.c
@@ -178,7 +178,6 @@ struct tegra_devfreq_soc_data {
 
 struct tegra_devfreq {
 	struct devfreq		*devfreq;
-	struct opp_table	*opp_table;
 
 	struct reset_control	*reset;
 	struct clk		*clock;
@@ -789,6 +788,39 @@ static struct devfreq_governor tegra_devfreq_governor = {
 	.event_handler = tegra_governor_event_handler,
 };
 
+static void devm_tegra_devfreq_deinit_hw(void *data)
+{
+	struct tegra_devfreq *tegra = data;
+
+	reset_control_reset(tegra->reset);
+	clk_disable_unprepare(tegra->clock);
+}
+
+static int devm_tegra_devfreq_init_hw(struct device *dev,
+				      struct tegra_devfreq *tegra)
+{
+	int err;
+
+	err = clk_prepare_enable(tegra->clock);
+	if (err) {
+		dev_err(dev, "Failed to prepare and enable ACTMON clock\n");
+		return err;
+	}
+
+	err = devm_add_action_or_reset(dev, devm_tegra_devfreq_deinit_hw,
+				       tegra);
+	if (err)
+		return err;
+
+	err = reset_control_reset(tegra->reset);
+	if (err) {
+		dev_err(dev, "Failed to reset hardware: %d\n", err);
+		return err;
+	}
+
+	return err;
+}
+
 static int tegra_devfreq_probe(struct platform_device *pdev)
 {
 	u32 hw_version = BIT(tegra_sku_info.soc_speedo_id);
@@ -842,38 +874,26 @@ static int tegra_devfreq_probe(struct platform_device *pdev)
 		return err;
 	}
 
-	tegra->opp_table = dev_pm_opp_set_supported_hw(&pdev->dev,
-						       &hw_version, 1);
-	err = PTR_ERR_OR_ZERO(tegra->opp_table);
+	err = devm_pm_opp_set_supported_hw(&pdev->dev, &hw_version, 1);
 	if (err) {
 		dev_err(&pdev->dev, "Failed to set supported HW: %d\n", err);
 		return err;
 	}
 
-	err = dev_pm_opp_of_add_table_noclk(&pdev->dev, 0);
+	err = devm_pm_opp_of_add_table_noclk(&pdev->dev, 0);
 	if (err) {
 		dev_err(&pdev->dev, "Failed to add OPP table: %d\n", err);
-		goto put_hw;
-	}
-
-	err = clk_prepare_enable(tegra->clock);
-	if (err) {
-		dev_err(&pdev->dev,
-			"Failed to prepare and enable ACTMON clock\n");
-		goto remove_table;
+		return err;
 	}
 
-	err = reset_control_reset(tegra->reset);
-	if (err) {
-		dev_err(&pdev->dev, "Failed to reset hardware: %d\n", err);
-		goto disable_clk;
-	}
+	err = devm_tegra_devfreq_init_hw(&pdev->dev, tegra);
+	if (err)
+		return err;
 
 	rate = clk_round_rate(tegra->emc_clock, ULONG_MAX);
 	if (rate < 0) {
 		dev_err(&pdev->dev, "Failed to round clock rate: %ld\n", rate);
-		err = rate;
-		goto disable_clk;
+		return rate;
 	}
 
 	tegra->max_freq = rate / KHZ;
@@ -892,52 +912,18 @@ static int tegra_devfreq_probe(struct platform_device *pdev)
 	INIT_DELAYED_WORK(&tegra->cpufreq_update_work,
 			  tegra_actmon_delayed_update);
 
-	err = devfreq_add_governor(&tegra_devfreq_governor);
+	err = devm_devfreq_add_governor(&pdev->dev, &tegra_devfreq_governor);
 	if (err) {
 		dev_err(&pdev->dev, "Failed to add governor: %d\n", err);
-		goto remove_opps;
+		return err;
 	}
 
 	tegra_devfreq_profile.initial_freq = clk_get_rate(tegra->emc_clock);
 
-	devfreq = devfreq_add_device(&pdev->dev, &tegra_devfreq_profile,
-				     "tegra_actmon", NULL);
-	if (IS_ERR(devfreq)) {
-		err = PTR_ERR(devfreq);
-		goto remove_governor;
-	}
-
-	return 0;
-
-remove_governor:
-	devfreq_remove_governor(&tegra_devfreq_governor);
-
-remove_opps:
-	dev_pm_opp_remove_all_dynamic(&pdev->dev);
-
-	reset_control_reset(tegra->reset);
-disable_clk:
-	clk_disable_unprepare(tegra->clock);
-remove_table:
-	dev_pm_opp_of_remove_table(&pdev->dev);
-put_hw:
-	dev_pm_opp_put_supported_hw(tegra->opp_table);
-
-	return err;
-}
-
-static int tegra_devfreq_remove(struct platform_device *pdev)
-{
-	struct tegra_devfreq *tegra = platform_get_drvdata(pdev);
-
-	devfreq_remove_device(tegra->devfreq);
-	devfreq_remove_governor(&tegra_devfreq_governor);
-
-	reset_control_reset(tegra->reset);
-	clk_disable_unprepare(tegra->clock);
-
-	dev_pm_opp_of_remove_table(&pdev->dev);
-	dev_pm_opp_put_supported_hw(tegra->opp_table);
+	devfreq = devm_devfreq_add_device(&pdev->dev, &tegra_devfreq_profile,
+					  "tegra_actmon", NULL);
+	if (IS_ERR(devfreq))
+		return PTR_ERR(devfreq);
 
 	return 0;
 }
@@ -967,7 +953,6 @@ MODULE_DEVICE_TABLE(of, tegra_devfreq_of_match);
 
 static struct platform_driver tegra_devfreq_driver = {
 	.probe	= tegra_devfreq_probe,
-	.remove	= tegra_devfreq_remove,
 	.driver = {
 		.name = "tegra-devfreq",
 		.of_match_table = tegra_devfreq_of_match,
-- 
2.32.0


^ permalink raw reply	[flat|nested] 13+ messages in thread

* [PATCH v1 4/4] PM / devfreq: tegra30: Check whether clk_round_rate() returns zero rate
  2021-09-12 18:44 [PATCH v1 0/4] Make probe() of Tegra devfreq driver completely resource-managed Dmitry Osipenko
                   ` (2 preceding siblings ...)
  2021-09-12 18:44 ` [PATCH v1 3/4] PM / devfreq: tegra30: Use resource-managed helpers Dmitry Osipenko
@ 2021-09-12 18:44 ` Dmitry Osipenko
  2021-09-15  3:51   ` Chanwoo Choi
  3 siblings, 1 reply; 13+ messages in thread
From: Dmitry Osipenko @ 2021-09-12 18:44 UTC (permalink / raw)
  To: Thierry Reding, Jonathan Hunter, Viresh Kumar, Nishanth Menon,
	MyungJoo Ham, Stephen Boyd, Kyungmin Park, Chanwoo Choi
  Cc: linux-tegra, linux-kernel, linux-pm

EMC clock is always-on and can't be zero. Check whether clk_round_rate()
returns zero rate and error out if it does. It can return zero if clock
tree isn't initialized properly.

Signed-off-by: Dmitry Osipenko <digetx@gmail.com>
---
 drivers/devfreq/tegra30-devfreq.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/devfreq/tegra30-devfreq.c b/drivers/devfreq/tegra30-devfreq.c
index d83fdc2713ed..65ecf17a36f4 100644
--- a/drivers/devfreq/tegra30-devfreq.c
+++ b/drivers/devfreq/tegra30-devfreq.c
@@ -891,9 +891,9 @@ static int tegra_devfreq_probe(struct platform_device *pdev)
 		return err;
 
 	rate = clk_round_rate(tegra->emc_clock, ULONG_MAX);
-	if (rate < 0) {
+	if (rate <= 0) {
 		dev_err(&pdev->dev, "Failed to round clock rate: %ld\n", rate);
-		return rate;
+		return rate ?: -EINVAL;
 	}
 
 	tegra->max_freq = rate / KHZ;
-- 
2.32.0


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH v1 4/4] PM / devfreq: tegra30: Check whether clk_round_rate() returns zero rate
  2021-09-12 18:44 ` [PATCH v1 4/4] PM / devfreq: tegra30: Check whether clk_round_rate() returns zero rate Dmitry Osipenko
@ 2021-09-15  3:51   ` Chanwoo Choi
  2021-09-15 18:31     ` Chanwoo Choi
  0 siblings, 1 reply; 13+ messages in thread
From: Chanwoo Choi @ 2021-09-15  3:51 UTC (permalink / raw)
  To: Dmitry Osipenko, Thierry Reding, Jonathan Hunter, Viresh Kumar,
	Nishanth Menon, MyungJoo Ham, Stephen Boyd, Kyungmin Park,
	Chanwoo Choi
  Cc: linux-tegra, linux-kernel, linux-pm

Hi,

On 21. 9. 13. 오전 3:44, Dmitry Osipenko wrote:
> EMC clock is always-on and can't be zero. Check whether clk_round_rate()
> returns zero rate and error out if it does. It can return zero if clock
> tree isn't initialized properly.
> 
> Signed-off-by: Dmitry Osipenko <digetx@gmail.com>
> ---
>   drivers/devfreq/tegra30-devfreq.c | 4 ++--
>   1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/devfreq/tegra30-devfreq.c b/drivers/devfreq/tegra30-devfreq.c
> index d83fdc2713ed..65ecf17a36f4 100644
> --- a/drivers/devfreq/tegra30-devfreq.c
> +++ b/drivers/devfreq/tegra30-devfreq.c
> @@ -891,9 +891,9 @@ static int tegra_devfreq_probe(struct platform_device *pdev)
>   		return err;
>   
>   	rate = clk_round_rate(tegra->emc_clock, ULONG_MAX);
> -	if (rate < 0) {
> +	if (rate <= 0) {
>   		dev_err(&pdev->dev, "Failed to round clock rate: %ld\n", rate);
> -		return rate;
> +		return rate ?: -EINVAL;
>   	}
>   
>   	tegra->max_freq = rate / KHZ;
> 

Acked-by: Chanwoo Choi <cw00.choi@samsung.com>

-- 
Best Regards,
Samsung Electronics
Chanwoo Choi

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH v1 2/4] PM / devfreq: Add devm_devfreq_add_governor()
  2021-09-12 18:44 ` [PATCH v1 2/4] PM / devfreq: Add devm_devfreq_add_governor() Dmitry Osipenko
@ 2021-09-15 18:23   ` Chanwoo Choi
  2021-09-16  1:30     ` Dmitry Osipenko
  2021-09-15 18:37   ` Chanwoo Choi
  1 sibling, 1 reply; 13+ messages in thread
From: Chanwoo Choi @ 2021-09-15 18:23 UTC (permalink / raw)
  To: Dmitry Osipenko, Thierry Reding, Jonathan Hunter, Viresh Kumar,
	Nishanth Menon, MyungJoo Ham, Stephen Boyd, Kyungmin Park,
	Chanwoo Choi
  Cc: linux-tegra, linux-kernel, linux-pm

On 21. 9. 13. 오전 3:44, Dmitry Osipenko wrote:
> Add resource-managed variant of devfreq_add_governor().
> 
> Signed-off-by: Dmitry Osipenko <digetx@gmail.com>
> ---
>   drivers/devfreq/devfreq.c  | 26 ++++++++++++++++++++++++++
>   drivers/devfreq/governor.h |  3 +++
>   2 files changed, 29 insertions(+)
> 
> diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c
> index 85faa7a5c7d1..d3af000ec290 100644
> --- a/drivers/devfreq/devfreq.c
> +++ b/drivers/devfreq/devfreq.c
> @@ -1301,6 +1301,32 @@ int devfreq_add_governor(struct devfreq_governor *governor)
>   }
>   EXPORT_SYMBOL(devfreq_add_governor);
>   
> +static void devm_devfreq_remove_governor(void *governor)
> +{
> +	devfreq_remove_governor(governor);

Because devfreq_remove_governor has the return value,
you need to check the return value and then print error at least.

	WARN_ON(devfreq_remove_governor(governor));

> +}
> +
> +/**
> + * devm_devfreq_add_governor() - Add devfreq governor
> + * @dev:	device which adds devfreq governor
> + * @governor:	the devfreq governor to be added
> + *
> + * This is a resource-managed variant of devfreq_add_governor().
> + */
> +int devm_devfreq_add_governor(struct device *dev,
> +			      struct devfreq_governor *governor)
> +{
> +	int err;
> +
> +	err = devfreq_add_governor(governor);
> +	if (err)
> +		return err;
> +
> +	return devm_add_action_or_reset(dev, devm_devfreq_remove_governor,
> +					governor);
> +}
> +EXPORT_SYMBOL(devm_devfreq_add_governor);
> +
>   /**
>    * devfreq_remove_governor() - Remove devfreq feature from a device.
>    * @governor:	the devfreq governor to be removed
> diff --git a/drivers/devfreq/governor.h b/drivers/devfreq/governor.h
> index 2d69a0ce6291..0d70a9ad951e 100644
> --- a/drivers/devfreq/governor.h
> +++ b/drivers/devfreq/governor.h
> @@ -94,4 +94,7 @@ static inline int devfreq_update_stats(struct devfreq *df)
>   
>   	return df->profile->get_dev_status(df->dev.parent, &df->last_status);
>   }
> +
> +int devm_devfreq_add_governor(struct device *dev,
> +			      struct devfreq_governor *governor);

Better to add under devfreq_remove_governor definition in order to 
gather the similar functions.

>   #endif /* _GOVERNOR_H */
> 


-- 
Best Regards,
Samsung Electronics
Chanwoo Choi

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH v1 4/4] PM / devfreq: tegra30: Check whether clk_round_rate() returns zero rate
  2021-09-15  3:51   ` Chanwoo Choi
@ 2021-09-15 18:31     ` Chanwoo Choi
  2021-09-16  1:28       ` Dmitry Osipenko
  0 siblings, 1 reply; 13+ messages in thread
From: Chanwoo Choi @ 2021-09-15 18:31 UTC (permalink / raw)
  To: Dmitry Osipenko, Thierry Reding, Jonathan Hunter, Viresh Kumar,
	Nishanth Menon, MyungJoo Ham, Stephen Boyd, Kyungmin Park,
	Chanwoo Choi
  Cc: linux-tegra, linux-kernel, linux-pm

On 21. 9. 15. 오후 12:51, Chanwoo Choi wrote:
> Hi,
> 
> On 21. 9. 13. 오전 3:44, Dmitry Osipenko wrote:
>> EMC clock is always-on and can't be zero. Check whether clk_round_rate()
>> returns zero rate and error out if it does. It can return zero if clock
>> tree isn't initialized properly.
>>
>> Signed-off-by: Dmitry Osipenko <digetx@gmail.com>
>> ---
>>   drivers/devfreq/tegra30-devfreq.c | 4 ++--
>>   1 file changed, 2 insertions(+), 2 deletions(-)
>>
>> diff --git a/drivers/devfreq/tegra30-devfreq.c 
>> b/drivers/devfreq/tegra30-devfreq.c
>> index d83fdc2713ed..65ecf17a36f4 100644
>> --- a/drivers/devfreq/tegra30-devfreq.c
>> +++ b/drivers/devfreq/tegra30-devfreq.c
>> @@ -891,9 +891,9 @@ static int tegra_devfreq_probe(struct 
>> platform_device *pdev)
>>           return err;
>>       rate = clk_round_rate(tegra->emc_clock, ULONG_MAX);
>> -    if (rate < 0) {
>> +    if (rate <= 0) {
>>           dev_err(&pdev->dev, "Failed to round clock rate: %ld\n", rate);
>> -        return rate;
>> +        return rate ?: -EINVAL;

If rate is 0, It doesn't return and fall-through? even if print the 
error message. 'return rate ?: -EINVAL;' style is strange for me
because it doesn't specify the 'return value' when rate is true.


-- 
Best Regards,
Samsung Electronics
Chanwoo Choi

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH v1 2/4] PM / devfreq: Add devm_devfreq_add_governor()
  2021-09-12 18:44 ` [PATCH v1 2/4] PM / devfreq: Add devm_devfreq_add_governor() Dmitry Osipenko
  2021-09-15 18:23   ` Chanwoo Choi
@ 2021-09-15 18:37   ` Chanwoo Choi
  2021-09-16  1:29     ` Dmitry Osipenko
  1 sibling, 1 reply; 13+ messages in thread
From: Chanwoo Choi @ 2021-09-15 18:37 UTC (permalink / raw)
  To: Dmitry Osipenko, Thierry Reding, Jonathan Hunter, Viresh Kumar,
	Nishanth Menon, MyungJoo Ham, Stephen Boyd, Kyungmin Park,
	Chanwoo Choi
  Cc: linux-tegra, linux-kernel, linux-pm

Hi,

There is ordering dependency between devfreq device and devfreq
governor. Theoretically, devfreq governor must be released after
released of devfreq device.

devm_* support the release ordering by the sequence of registration
in probe()?

On 21. 9. 13. 오전 3:44, Dmitry Osipenko wrote:
> Add resource-managed variant of devfreq_add_governor().
> 
> Signed-off-by: Dmitry Osipenko <digetx@gmail.com>
> ---
>   drivers/devfreq/devfreq.c  | 26 ++++++++++++++++++++++++++
>   drivers/devfreq/governor.h |  3 +++
>   2 files changed, 29 insertions(+)
> 
> diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c
> index 85faa7a5c7d1..d3af000ec290 100644
> --- a/drivers/devfreq/devfreq.c
> +++ b/drivers/devfreq/devfreq.c
> @@ -1301,6 +1301,32 @@ int devfreq_add_governor(struct devfreq_governor *governor)
>   }
>   EXPORT_SYMBOL(devfreq_add_governor);
>   
> +static void devm_devfreq_remove_governor(void *governor)
> +{
> +	devfreq_remove_governor(governor);
> +}
> +
> +/**
> + * devm_devfreq_add_governor() - Add devfreq governor
> + * @dev:	device which adds devfreq governor
> + * @governor:	the devfreq governor to be added
> + *
> + * This is a resource-managed variant of devfreq_add_governor().
> + */
> +int devm_devfreq_add_governor(struct device *dev,
> +			      struct devfreq_governor *governor)
> +{
> +	int err;
> +
> +	err = devfreq_add_governor(governor);
> +	if (err)
> +		return err;
> +
> +	return devm_add_action_or_reset(dev, devm_devfreq_remove_governor,
> +					governor);
> +}
> +EXPORT_SYMBOL(devm_devfreq_add_governor);
> +
>   /**
>    * devfreq_remove_governor() - Remove devfreq feature from a device.
>    * @governor:	the devfreq governor to be removed
> diff --git a/drivers/devfreq/governor.h b/drivers/devfreq/governor.h
> index 2d69a0ce6291..0d70a9ad951e 100644
> --- a/drivers/devfreq/governor.h
> +++ b/drivers/devfreq/governor.h
> @@ -94,4 +94,7 @@ static inline int devfreq_update_stats(struct devfreq *df)
>   
>   	return df->profile->get_dev_status(df->dev.parent, &df->last_status);
>   }
> +
> +int devm_devfreq_add_governor(struct device *dev,
> +			      struct devfreq_governor *governor);
>   #endif /* _GOVERNOR_H */
> 


-- 
Best Regards,
Samsung Electronics
Chanwoo Choi

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH v1 4/4] PM / devfreq: tegra30: Check whether clk_round_rate() returns zero rate
  2021-09-15 18:31     ` Chanwoo Choi
@ 2021-09-16  1:28       ` Dmitry Osipenko
  2021-09-19  9:43         ` Chanwoo Choi
  0 siblings, 1 reply; 13+ messages in thread
From: Dmitry Osipenko @ 2021-09-16  1:28 UTC (permalink / raw)
  To: Chanwoo Choi
  Cc: linux-tegra, linux-kernel, linux-pm, Thierry Reding,
	Jonathan Hunter, Viresh Kumar, Nishanth Menon, MyungJoo Ham,
	Stephen Boyd, Kyungmin Park, Chanwoo Choi

15.09.2021 21:31, Chanwoo Choi пишет:
> On 21. 9. 15. 오후 12:51, Chanwoo Choi wrote:
>> Hi,
>>
>> On 21. 9. 13. 오전 3:44, Dmitry Osipenko wrote:
>>> EMC clock is always-on and can't be zero. Check whether clk_round_rate()
>>> returns zero rate and error out if it does. It can return zero if clock
>>> tree isn't initialized properly.
>>>
>>> Signed-off-by: Dmitry Osipenko <digetx@gmail.com>
>>> ---
>>>   drivers/devfreq/tegra30-devfreq.c | 4 ++--
>>>   1 file changed, 2 insertions(+), 2 deletions(-)
>>>
>>> diff --git a/drivers/devfreq/tegra30-devfreq.c
>>> b/drivers/devfreq/tegra30-devfreq.c
>>> index d83fdc2713ed..65ecf17a36f4 100644
>>> --- a/drivers/devfreq/tegra30-devfreq.c
>>> +++ b/drivers/devfreq/tegra30-devfreq.c
>>> @@ -891,9 +891,9 @@ static int tegra_devfreq_probe(struct
>>> platform_device *pdev)
>>>           return err;
>>>       rate = clk_round_rate(tegra->emc_clock, ULONG_MAX);
>>> -    if (rate < 0) {
>>> +    if (rate <= 0) {
>>>           dev_err(&pdev->dev, "Failed to round clock rate: %ld\n",
>>> rate);
>>> -        return rate;
>>> +        return rate ?: -EINVAL;
> 
> If rate is 0, It doesn't return and fall-through? even if print the
> error message. 'return rate ?: -EINVAL;' style is strange for me
> because it doesn't specify the 'return value' when rate is true.

It's not clear to me what do you mean by "return and fall-through".

It specifies the 'return value' when rate is true. It's a short form of
"rate ? rate : -EINVAL".

The final returned value will be printed by the driver's core. The value
returned by clk_round_rate() is important here since it tells the reason
of the error.

https://elixir.bootlin.com/linux/v5.15-rc1/source/drivers/base/dd.c#L533

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH v1 2/4] PM / devfreq: Add devm_devfreq_add_governor()
  2021-09-15 18:37   ` Chanwoo Choi
@ 2021-09-16  1:29     ` Dmitry Osipenko
  0 siblings, 0 replies; 13+ messages in thread
From: Dmitry Osipenko @ 2021-09-16  1:29 UTC (permalink / raw)
  To: Chanwoo Choi, Thierry Reding, Jonathan Hunter, Viresh Kumar,
	Nishanth Menon, MyungJoo Ham, Stephen Boyd, Kyungmin Park,
	Chanwoo Choi
  Cc: linux-tegra, linux-kernel, linux-pm

15.09.2021 21:37, Chanwoo Choi пишет:
> Hi,
> 
> There is ordering dependency between devfreq device and devfreq
> governor. Theoretically, devfreq governor must be released after
> released of devfreq device.
> 
> devm_* support the release ordering by the sequence of registration
> in probe()?

Yes, the release order is always opposite to the registration order.

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH v1 2/4] PM / devfreq: Add devm_devfreq_add_governor()
  2021-09-15 18:23   ` Chanwoo Choi
@ 2021-09-16  1:30     ` Dmitry Osipenko
  0 siblings, 0 replies; 13+ messages in thread
From: Dmitry Osipenko @ 2021-09-16  1:30 UTC (permalink / raw)
  To: Chanwoo Choi
  Cc: linux-tegra, linux-kernel, linux-pm, Thierry Reding,
	Jonathan Hunter, Viresh Kumar, Nishanth Menon, MyungJoo Ham,
	Stephen Boyd, Kyungmin Park, Chanwoo Choi

15.09.2021 21:23, Chanwoo Choi пишет:
> On 21. 9. 13. 오전 3:44, Dmitry Osipenko wrote:
>> Add resource-managed variant of devfreq_add_governor().
>>
>> Signed-off-by: Dmitry Osipenko <digetx@gmail.com>
>> ---
>>   drivers/devfreq/devfreq.c  | 26 ++++++++++++++++++++++++++
>>   drivers/devfreq/governor.h |  3 +++
>>   2 files changed, 29 insertions(+)
>>
>> diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c
>> index 85faa7a5c7d1..d3af000ec290 100644
>> --- a/drivers/devfreq/devfreq.c
>> +++ b/drivers/devfreq/devfreq.c
>> @@ -1301,6 +1301,32 @@ int devfreq_add_governor(struct
>> devfreq_governor *governor)
>>   }
>>   EXPORT_SYMBOL(devfreq_add_governor);
>>   +static void devm_devfreq_remove_governor(void *governor)
>> +{
>> +    devfreq_remove_governor(governor);
> 
> Because devfreq_remove_governor has the return value,
> you need to check the return value and then print error at least.
> 
>     WARN_ON(devfreq_remove_governor(governor));

...
>> diff --git a/drivers/devfreq/governor.h b/drivers/devfreq/governor.h
>> index 2d69a0ce6291..0d70a9ad951e 100644
>> --- a/drivers/devfreq/governor.h
>> +++ b/drivers/devfreq/governor.h
>> @@ -94,4 +94,7 @@ static inline int devfreq_update_stats(struct
>> devfreq *df)
>>         return df->profile->get_dev_status(df->dev.parent,
>> &df->last_status);
>>   }
>> +
>> +int devm_devfreq_add_governor(struct device *dev,
>> +                  struct devfreq_governor *governor);
> 
> Better to add under devfreq_remove_governor definition in order to
> gather the similar functions.

I'll change it in v2, thanks.

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH v1 4/4] PM / devfreq: tegra30: Check whether clk_round_rate() returns zero rate
  2021-09-16  1:28       ` Dmitry Osipenko
@ 2021-09-19  9:43         ` Chanwoo Choi
  0 siblings, 0 replies; 13+ messages in thread
From: Chanwoo Choi @ 2021-09-19  9:43 UTC (permalink / raw)
  To: Dmitry Osipenko
  Cc: linux-tegra, linux-kernel, linux-pm, Thierry Reding,
	Jonathan Hunter, Viresh Kumar, Nishanth Menon, MyungJoo Ham,
	Stephen Boyd, Kyungmin Park, Chanwoo Choi

On 21. 9. 16. 오전 10:28, Dmitry Osipenko wrote:
> 15.09.2021 21:31, Chanwoo Choi пишет:
>> On 21. 9. 15. 오후 12:51, Chanwoo Choi wrote:
>>> Hi,
>>>
>>> On 21. 9. 13. 오전 3:44, Dmitry Osipenko wrote:
>>>> EMC clock is always-on and can't be zero. Check whether clk_round_rate()
>>>> returns zero rate and error out if it does. It can return zero if clock
>>>> tree isn't initialized properly.
>>>>
>>>> Signed-off-by: Dmitry Osipenko <digetx@gmail.com>
>>>> ---
>>>>    drivers/devfreq/tegra30-devfreq.c | 4 ++--
>>>>    1 file changed, 2 insertions(+), 2 deletions(-)
>>>>
>>>> diff --git a/drivers/devfreq/tegra30-devfreq.c
>>>> b/drivers/devfreq/tegra30-devfreq.c
>>>> index d83fdc2713ed..65ecf17a36f4 100644
>>>> --- a/drivers/devfreq/tegra30-devfreq.c
>>>> +++ b/drivers/devfreq/tegra30-devfreq.c
>>>> @@ -891,9 +891,9 @@ static int tegra_devfreq_probe(struct
>>>> platform_device *pdev)
>>>>            return err;
>>>>        rate = clk_round_rate(tegra->emc_clock, ULONG_MAX);
>>>> -    if (rate < 0) {
>>>> +    if (rate <= 0) {
>>>>            dev_err(&pdev->dev, "Failed to round clock rate: %ld\n",
>>>> rate);
>>>> -        return rate;
>>>> +        return rate ?: -EINVAL;
>>
>> If rate is 0, It doesn't return and fall-through? even if print the
>> error message. 'return rate ?: -EINVAL;' style is strange for me
>> because it doesn't specify the 'return value' when rate is true.
> 
> It's not clear to me what do you mean by "return and fall-through".
> 
> It specifies the 'return value' when rate is true. It's a short form of
> "rate ? rate : -EINVAL".

I has not known this short form. Thanks for comment. I understand.



-- 
Best Regards,
Samsung Electronics
Chanwoo Choi

^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2021-09-19  9:44 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-12 18:44 [PATCH v1 0/4] Make probe() of Tegra devfreq driver completely resource-managed Dmitry Osipenko
2021-09-12 18:44 ` [PATCH v1 1/4] opp: Add more resource-managed variants of dev_pm_opp_of_add_table() Dmitry Osipenko
2021-09-12 18:44 ` [PATCH v1 2/4] PM / devfreq: Add devm_devfreq_add_governor() Dmitry Osipenko
2021-09-15 18:23   ` Chanwoo Choi
2021-09-16  1:30     ` Dmitry Osipenko
2021-09-15 18:37   ` Chanwoo Choi
2021-09-16  1:29     ` Dmitry Osipenko
2021-09-12 18:44 ` [PATCH v1 3/4] PM / devfreq: tegra30: Use resource-managed helpers Dmitry Osipenko
2021-09-12 18:44 ` [PATCH v1 4/4] PM / devfreq: tegra30: Check whether clk_round_rate() returns zero rate Dmitry Osipenko
2021-09-15  3:51   ` Chanwoo Choi
2021-09-15 18:31     ` Chanwoo Choi
2021-09-16  1:28       ` Dmitry Osipenko
2021-09-19  9:43         ` Chanwoo Choi

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).