From patchwork Mon Jul 18 13:36:31 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Liang He X-Patchwork-Id: 12921290 X-Patchwork-Delegate: daniel.lezcano@linaro.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A90EDC433EF for ; Mon, 18 Jul 2022 13:36:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233852AbiGRNgs (ORCPT ); Mon, 18 Jul 2022 09:36:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60272 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233264AbiGRNgr (ORCPT ); Mon, 18 Jul 2022 09:36:47 -0400 Received: from mail-m963.mail.126.com (mail-m963.mail.126.com [123.126.96.3]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 89B251A3B0 for ; Mon, 18 Jul 2022 06:36:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=126.com; s=s110527; h=From:Subject:Date:Message-Id:MIME-Version; bh=qiii+ ijtDUpLXuKUfT/gct0Y4qtxlMum/HdyRii7+OE=; b=p9de7dN/DVTk5mq1PeV/8 IZhL8Dm3QMSJ1vNcOoCWHPQ7FogT0WLDpU4vgEhJpMOBWf3QZUYqT3q9H9raOVeb HA/5BmjiLAXoKRe9pln+clSAHPYV0c6k0tcba5KCYw64aI6zeXy5vdKsnnf5Hmp3 AEB0YJpTouUKLtVRH5OgkY= Received: from localhost.localdomain (unknown [124.16.139.61]) by smtp8 (Coremail) with SMTP id NORpCgBX6IThYdVigvlWIA--.52604S2; Mon, 18 Jul 2022 21:36:33 +0800 (CST) From: Liang He To: vireshk@kernel.org, nm@ti.com, sboyd@kernel.org, linux-pm@vger.kernel.org, windhl@126.com Subject: [PATCH v2 1/2] OPP: Fix refcount leak bug for opp_table Date: Mon, 18 Jul 2022 21:36:31 +0800 Message-Id: <20220718133632.937290-1-windhl@126.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-CM-TRANSID: NORpCgBX6IThYdVigvlWIA--.52604S2 X-Coremail-Antispam: 1Uf129KBjvJXoW7ZrW7KrykJr4rWw1kJryxXwb_yoW8XFW3pr 15JrZ0yFW3X3yqyr47Jan29a4YyanFqrykK3s5C34Yvw1qya4UXFW2q343AFykJas5XFWa qF1qqr4UWa1xJ37anT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07UYjgxUUUUU= X-Originating-IP: [124.16.139.61] X-CM-SenderInfo: hzlqvxbo6rjloofrz/1tbizgJCF18RPhBXjAAAsi Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org 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 --- 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(-) 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) From patchwork Mon Jul 18 13:36:32 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Liang He X-Patchwork-Id: 12921291 X-Patchwork-Delegate: daniel.lezcano@linaro.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id CCCEBC43334 for ; Mon, 18 Jul 2022 13:36:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234102AbiGRNgt (ORCPT ); Mon, 18 Jul 2022 09:36:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60282 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233264AbiGRNgt (ORCPT ); Mon, 18 Jul 2022 09:36:49 -0400 Received: from mail-m963.mail.126.com (mail-m963.mail.126.com [123.126.96.3]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 0DB111A3B1 for ; Mon, 18 Jul 2022 06:36:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=126.com; s=s110527; h=From:Subject:Date:Message-Id:MIME-Version; bh=MxHIn upCOqspUhbDEdp4NqT3uVJmKh522j8Cwo7kgUM=; b=dMo0xQavWWCt+kKn2a9Ja TOAByAVu5THddOtXrZdEUmCPsHHocX9nEau6PXB3A96CdNhd31X1OElQlQM6CsBe 09nA4Fmz9K+h4rSEIgg7eS/A70i1OxUSWEb3CcrFkX12MRWd5QYAskbvdWti/8T2 oCD3PDbRyk9T0tTHbGdwHk= Received: from localhost.localdomain (unknown [124.16.139.61]) by smtp8 (Coremail) with SMTP id NORpCgBX6IThYdVigvlWIA--.52604S3; Mon, 18 Jul 2022 21:36:36 +0800 (CST) From: Liang He To: vireshk@kernel.org, nm@ti.com, sboyd@kernel.org, linux-pm@vger.kernel.org, windhl@126.com Subject: [PATCH v2 2/2] OPP: Fix refcount leak bug for opp Date: Mon, 18 Jul 2022 21:36:32 +0800 Message-Id: <20220718133632.937290-2-windhl@126.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220718133632.937290-1-windhl@126.com> References: <20220718133632.937290-1-windhl@126.com> MIME-Version: 1.0 X-CM-TRANSID: NORpCgBX6IThYdVigvlWIA--.52604S3 X-Coremail-Antispam: 1Uf129KBjvJXoW7Aw4UGr4xZw1xXF1xXw43ZFb_yoW8Wryxpr sxK343AFyDXFWDtw4Iy3W8uF90y3Wqqry8WFyfG34F9w45tFyUX34Ygay5tFn8XFykArWa qF18tF45Wa18Jw7anT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07Ufb18UUUUU= X-Originating-IP: [124.16.139.61] X-CM-SenderInfo: hzlqvxbo6rjloofrz/1tbiuARCF2JVkaOAHwAAsz Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org In _opp_add_static_v2(), we need call of_node_get() for the new reference created when "new_opp->np = np;" as new_opp is escaped out. Here we should also take care of the of_node_put() when 'new_opp' is freed based on the function description: "The opp can be controlled ... and may be removed by dev_pm_opp_remove". For example, _opp_add_static_v2() is called by _of_add_opp_table_v2() in a for_each_available_child_of_node() which will automatically increase and decrease the refcount. So we need an additional of_node_get() for the new reference created in _opp_add_static_v2(). Signed-off-by: Liang He --- drivers/opp/core.c | 1 + drivers/opp/of.c | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/opp/core.c b/drivers/opp/core.c index cc2671322e41..2f7988a05cb7 100644 --- a/drivers/opp/core.c +++ b/drivers/opp/core.c @@ -1549,6 +1549,7 @@ static void _opp_kref_release(struct kref *kref) list_del(&opp->node); mutex_unlock(&opp_table->lock); + of_node_put(opp->np); /* * Notify the changes in the availability of the operable * frequency/voltage list. diff --git a/drivers/opp/of.c b/drivers/opp/of.c index 374544afe9e4..ac4a3ff12677 100644 --- a/drivers/opp/of.c +++ b/drivers/opp/of.c @@ -937,7 +937,7 @@ static struct dev_pm_opp *_opp_add_static_v2(struct opp_table *opp_table, new_opp->turbo = of_property_read_bool(np, "turbo-mode"); - new_opp->np = np; + new_opp->np = of_node_get(np); new_opp->dynamic = false; new_opp->available = true;