diff mbox series

[v2,1/2] OPP: Fix refcount leak bug for opp_table

Message ID 20220718133632.937290-1-windhl@126.com (mailing list archive)
State New, archived
Delegated to: Daniel Lezcano
Headers show
Series [v2,1/2] OPP: Fix refcount leak bug for opp_table | expand

Commit Message

Liang He July 18, 2022, 1:36 p.m. UTC
In _of_init_opp_table(), of_put_node() in the last line is not
needed as the 'opp_np' is escaped out into 'opp_table->np' and
’opp_table' is an out parameter. We should call the of_node_put()
when the 'opp_table' is released in _opp_table_kref_release().

Signed-off-by: Liang He <windhl@126.com>
---
 changelog:

 v2: (1) add the of_node_put() in _opp_table_kref_release()
     (2) rebase on linux-next/master
     (3) split v1 into two commits, opp_table->np and opp->np
 v1: https://lore.kernel.org/all/20220715144712.444104-1-windhl@126.com/


 drivers/opp/core.c | 1 +
 drivers/opp/of.c   | 1 -
 2 files changed, 1 insertion(+), 1 deletion(-)

Comments

Viresh Kumar July 19, 2022, 5:38 a.m. UTC | #1
On 18-07-22, 21:36, Liang He wrote:
> In _of_init_opp_table(), of_put_node() in the last line is not
> needed as the 'opp_np' is escaped out into 'opp_table->np' and
> ’opp_table' is an out parameter. We should call the of_node_put()
> when the 'opp_table' is released in _opp_table_kref_release().
> 
> Signed-off-by: Liang He <windhl@126.com>

Applied with few changes. Thanks.

commit ce736cf71b5ab8ad9b741dc7a4a07e41c27d1421
Author: Liang He <windhl@126.com>
Date:   Mon Jul 18 21:36:31 2022 +0800

    OPP: Don't drop opp_table->np reference while it is still in use

    The OPP table contains a reference of the DT node, opp_table->np,
    throughout its lifetime. We shouldn't drop the refcount for the same
    from _of_init_opp_table(), but do that while removing the OPP table
    finally.

    Signed-off-by: Liang He <windhl@126.com>
    [ Viresh: Updated subject / commit log and drop reference from
              _of_clear_opp_table() ]
    Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
---
 drivers/opp/of.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/opp/of.c b/drivers/opp/of.c
index 8367823a2001..e4002b075422 100644
--- a/drivers/opp/of.c
+++ b/drivers/opp/of.c
@@ -242,12 +242,12 @@ void _of_init_opp_table(struct opp_table *opp_table, struct device *dev,
        opp_table->np = opp_np;

        _opp_table_alloc_required_tables(opp_table, dev, opp_np);
-       of_node_put(opp_np);
 }

 void _of_clear_opp_table(struct opp_table *opp_table)
 {
        _opp_table_free_required_tables(opp_table);
+       of_node_put(opp_table->np);
 }

 /*
diff mbox series

Patch

diff --git a/drivers/opp/core.c b/drivers/opp/core.c
index 4f4a285886fa..cc2671322e41 100644
--- a/drivers/opp/core.c
+++ b/drivers/opp/core.c
@@ -1499,6 +1499,7 @@  static void _opp_table_kref_release(struct kref *kref)
 		dev_pm_opp_put(opp_table->current_opp);
 
 	_of_clear_opp_table(opp_table);
+	of_node_put(opp_table->np);
 
 	/* Release automatically acquired single clk */
 	if (!IS_ERR(opp_table->clk))
diff --git a/drivers/opp/of.c b/drivers/opp/of.c
index 8367823a2001..374544afe9e4 100644
--- a/drivers/opp/of.c
+++ b/drivers/opp/of.c
@@ -242,7 +242,6 @@  void _of_init_opp_table(struct opp_table *opp_table, struct device *dev,
 	opp_table->np = opp_np;
 
 	_opp_table_alloc_required_tables(opp_table, dev, opp_np);
-	of_node_put(opp_np);
 }
 
 void _of_clear_opp_table(struct opp_table *opp_table)