Message ID | 20230202141545.2295679-1-gregkh@linuxfoundation.org |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp265009wrn; Thu, 2 Feb 2023 06:19:15 -0800 (PST) X-Google-Smtp-Source: AK7set9w6XVM/R2zTwszWW4jWsdi+ls0qlg4upSLbTkOP0CVeKve54MF6FwsGnAlIthWejv3avsY X-Received: by 2002:a05:6a20:938d:b0:bc:e2d1:dc29 with SMTP id x13-20020a056a20938d00b000bce2d1dc29mr7894612pzh.59.1675347555049; Thu, 02 Feb 2023 06:19:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675347555; cv=none; d=google.com; s=arc-20160816; b=vBOLiZ/tH9fTJbUwwwdae58jUpiorSdsntRJc1WFEPKCXTnVsTXHvIKxastopdZPej GIOJhf56RIllpDkjWiDhrNBqjwZAGYLTZGxVaFr/HNLp2K+yliDwsWnQzGuhzEEK+7wp liKh0gOG7vHmsG/eUgC/+v/dz7j/3yynEld/a+k55h5gGqtlv7POugZ4czwVi5v6BP/w L2Bbe/REPhcyxrLJdGcksBDhqzmKvNZBHSdyUq3xHmbBSc082+KyYbWVr7ms+xyD4Y5t 3Q0+QiGrN08/IlH+8yxa+Z+Q9ap+ccpP4WBvhi/P5gruQSOzGiPk2DJ1muOY+tbxONxE nTJQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=h4R185pa9AD8Z97h58/QNlLd9ejE8WI57Afe/e1u67E=; b=HOZ0lXJH0imcIv/0lccOEtyB9B/MGH9z2r0FRRKefRJZHLne0yLX3vqNE2mrkosnPg E09sWPe5gMlOgtnAK2YBi5GjCcyBhrTf5z8TdiKkkoofI1fJaMPTO6iIFeSDsuPmMXIQ 9/P54LXZaP65tl1aS62Mo4iOXu/Skt8L/+UdKwJok0FQKWgka8lWpMZsqNyrO8btCkOS OREkzwXfRMCs4LzY8IO1xprM/VTYyYI/6yHXbY0faTmzJpZKulvdCl1kJDIzLitq3K28 F8HUXo7IOQD6kgAOTCg2wZqCFFkvOVNVMUTmVmw48pzn7OeTDV404rkxyq0K9MzpRPlZ xPmQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=L3XCC+RB; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id u7-20020a63b547000000b004de92107efesi20527081pgo.821.2023.02.02.06.19.03; Thu, 02 Feb 2023 06:19:15 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=L3XCC+RB; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232089AbjBBOP4 (ORCPT <rfc822;il.mystafa@gmail.com> + 99 others); Thu, 2 Feb 2023 09:15:56 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32972 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230230AbjBBOPy (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Thu, 2 Feb 2023 09:15:54 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EAC65E3A7; Thu, 2 Feb 2023 06:15:52 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 91EB9B8266F; Thu, 2 Feb 2023 14:15:51 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D3434C433EF; Thu, 2 Feb 2023 14:15:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1675347350; bh=cliceGEpDPWRRZ/wPbCTq+b7JfWhyfm7xM7yP+3Udss=; h=From:To:Cc:Subject:Date:From; b=L3XCC+RB6OLs+dem4JWYjTEKK6dYVsNb3Ub6C9fxSg2Yagggn33cxyAheZ+HLh6HY JBcpf32VTpJsplj0/6KYRTSXuFcL3/lfgyrfRwS92rHH+Q1Se4QxHxEEiN+PSUwSZs BDKKI6H81XKsdbx4ZUlUhc3EyQNRN4aAKWHbebxw= From: Greg Kroah-Hartman <gregkh@linuxfoundation.org> To: rafael@kernel.org Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>, Kevin Hilman <khilman@kernel.org>, Ulf Hansson <ulf.hansson@linaro.org>, Pavel Machek <pavel@ucw.cz>, Len Brown <len.brown@intel.com>, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] drivers: base: power: fix memory leak with using debugfs_lookup() Date: Thu, 2 Feb 2023 15:15:45 +0100 Message-Id: <20230202141545.2295679-1-gregkh@linuxfoundation.org> X-Mailer: git-send-email 2.39.1 MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=1289; i=gregkh@linuxfoundation.org; h=from:subject; bh=cliceGEpDPWRRZ/wPbCTq+b7JfWhyfm7xM7yP+3Udss=; b=owGbwMvMwCRo6H6F97bub03G02pJDMm3j04UzD2tfm2DYJSIxnIPDe03LgWHl6aFsT5Zkz2FXa7V VDmyI5aFQZCJQVZMkeXLNp6j+ysOKXoZ2p6GmcPKBDKEgYtTACaybT7DgmuzIg5mqHlnyWTcyF/xMr 9Ms/7XRoa5MktCfzTfTXKw+/g46SyTa9c5R4tlAA== X-Developer-Key: i=gregkh@linuxfoundation.org; a=openpgp; fpr=F4B60CC5BF78C2214A313DCB3147D40DDB2DFB29 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1756729237847690449?= X-GMAIL-MSGID: =?utf-8?q?1756729237847690449?= |
Series |
drivers: base: power: fix memory leak with using debugfs_lookup()
|
|
Commit Message
Greg KH
Feb. 2, 2023, 2:15 p.m. UTC
When calling debugfs_lookup() the result must have dput() called on it,
otherwise the memory will leak over time. To make things simpler, just
call debugfs_lookup_and_remove() instead which handles all of the logic
at
once.
Cc: "Rafael J. Wysocki" <rafael@kernel.org>
Cc: Kevin Hilman <khilman@kernel.org>
Cc: Ulf Hansson <ulf.hansson@linaro.org>
Cc: Pavel Machek <pavel@ucw.cz>
Cc: Len Brown <len.brown@intel.com>
Cc: linux-pm@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
drivers/base/power/domain.c | 5 +----
1 file changed, 1 insertion(+), 4 deletions(-)
Comments
On Thu, Feb 2, 2023 at 3:15 PM Greg Kroah-Hartman <gregkh@linuxfoundation.org> wrote: > > When calling debugfs_lookup() the result must have dput() called on it, > otherwise the memory will leak over time. To make things simpler, just > call debugfs_lookup_and_remove() instead which handles all of the logic > at > once. > > Cc: "Rafael J. Wysocki" <rafael@kernel.org> > Cc: Kevin Hilman <khilman@kernel.org> > Cc: Ulf Hansson <ulf.hansson@linaro.org> > Cc: Pavel Machek <pavel@ucw.cz> > Cc: Len Brown <len.brown@intel.com> > Cc: linux-pm@vger.kernel.org > Cc: linux-kernel@vger.kernel.org > Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> > --- > drivers/base/power/domain.c | 5 +---- > 1 file changed, 1 insertion(+), 4 deletions(-) > > diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c > index 967bcf9d415e..6097644ebdc5 100644 > --- a/drivers/base/power/domain.c > +++ b/drivers/base/power/domain.c > @@ -220,13 +220,10 @@ static void genpd_debug_add(struct generic_pm_domain *genpd); > > static void genpd_debug_remove(struct generic_pm_domain *genpd) > { > - struct dentry *d; > - > if (!genpd_debugfs_dir) > return; > > - d = debugfs_lookup(genpd->name, genpd_debugfs_dir); > - debugfs_remove(d); > + debugfs_lookup_and_remove(genpd->name, genpd_debugfs_dir); > } > > static void genpd_update_accounting(struct generic_pm_domain *genpd) > -- Does this depend on anything in your tree, or can I apply it?
On Thu, 2 Feb 2023 at 15:15, Greg Kroah-Hartman <gregkh@linuxfoundation.org> wrote: > > When calling debugfs_lookup() the result must have dput() called on it, > otherwise the memory will leak over time. To make things simpler, just > call debugfs_lookup_and_remove() instead which handles all of the logic > at > once. > > Cc: "Rafael J. Wysocki" <rafael@kernel.org> > Cc: Kevin Hilman <khilman@kernel.org> > Cc: Ulf Hansson <ulf.hansson@linaro.org> > Cc: Pavel Machek <pavel@ucw.cz> > Cc: Len Brown <len.brown@intel.com> > Cc: linux-pm@vger.kernel.org > Cc: linux-kernel@vger.kernel.org > Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Reviewed-by: Ulf Hansson <ulf.hansson@linaro.org> Kind regards Uffe > --- > drivers/base/power/domain.c | 5 +---- > 1 file changed, 1 insertion(+), 4 deletions(-) > > diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c > index 967bcf9d415e..6097644ebdc5 100644 > --- a/drivers/base/power/domain.c > +++ b/drivers/base/power/domain.c > @@ -220,13 +220,10 @@ static void genpd_debug_add(struct generic_pm_domain *genpd); > > static void genpd_debug_remove(struct generic_pm_domain *genpd) > { > - struct dentry *d; > - > if (!genpd_debugfs_dir) > return; > > - d = debugfs_lookup(genpd->name, genpd_debugfs_dir); > - debugfs_remove(d); > + debugfs_lookup_and_remove(genpd->name, genpd_debugfs_dir); > } > > static void genpd_update_accounting(struct generic_pm_domain *genpd) > -- > 2.39.1 >
On Thu, Feb 02, 2023 at 03:23:46PM +0100, Rafael J. Wysocki wrote: > On Thu, Feb 2, 2023 at 3:15 PM Greg Kroah-Hartman > <gregkh@linuxfoundation.org> wrote: > > > > When calling debugfs_lookup() the result must have dput() called on it, > > otherwise the memory will leak over time. To make things simpler, just > > call debugfs_lookup_and_remove() instead which handles all of the logic > > at > > once. > > > > Cc: "Rafael J. Wysocki" <rafael@kernel.org> > > Cc: Kevin Hilman <khilman@kernel.org> > > Cc: Ulf Hansson <ulf.hansson@linaro.org> > > Cc: Pavel Machek <pavel@ucw.cz> > > Cc: Len Brown <len.brown@intel.com> > > Cc: linux-pm@vger.kernel.org > > Cc: linux-kernel@vger.kernel.org > > Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> > > --- > > drivers/base/power/domain.c | 5 +---- > > 1 file changed, 1 insertion(+), 4 deletions(-) > > > > diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c > > index 967bcf9d415e..6097644ebdc5 100644 > > --- a/drivers/base/power/domain.c > > +++ b/drivers/base/power/domain.c > > @@ -220,13 +220,10 @@ static void genpd_debug_add(struct generic_pm_domain *genpd); > > > > static void genpd_debug_remove(struct generic_pm_domain *genpd) > > { > > - struct dentry *d; > > - > > if (!genpd_debugfs_dir) > > return; > > > > - d = debugfs_lookup(genpd->name, genpd_debugfs_dir); > > - debugfs_remove(d); > > + debugfs_lookup_and_remove(genpd->name, genpd_debugfs_dir); > > } > > > > static void genpd_update_accounting(struct generic_pm_domain *genpd) > > -- > > Does this depend on anything in your tree, or can I apply it? It does not depend on anything in any of my trees, it's made against Linus's tree right now so please take it through yours. thanks! greg k-h
On Thu, Feb 2, 2023 at 4:09 PM Greg Kroah-Hartman <gregkh@linuxfoundation.org> wrote: > > On Thu, Feb 02, 2023 at 03:23:46PM +0100, Rafael J. Wysocki wrote: > > On Thu, Feb 2, 2023 at 3:15 PM Greg Kroah-Hartman > > <gregkh@linuxfoundation.org> wrote: > > > > > > When calling debugfs_lookup() the result must have dput() called on it, > > > otherwise the memory will leak over time. To make things simpler, just > > > call debugfs_lookup_and_remove() instead which handles all of the logic > > > at > > > once. > > > > > > Cc: "Rafael J. Wysocki" <rafael@kernel.org> > > > Cc: Kevin Hilman <khilman@kernel.org> > > > Cc: Ulf Hansson <ulf.hansson@linaro.org> > > > Cc: Pavel Machek <pavel@ucw.cz> > > > Cc: Len Brown <len.brown@intel.com> > > > Cc: linux-pm@vger.kernel.org > > > Cc: linux-kernel@vger.kernel.org > > > Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> > > > --- > > > drivers/base/power/domain.c | 5 +---- > > > 1 file changed, 1 insertion(+), 4 deletions(-) > > > > > > diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c > > > index 967bcf9d415e..6097644ebdc5 100644 > > > --- a/drivers/base/power/domain.c > > > +++ b/drivers/base/power/domain.c > > > @@ -220,13 +220,10 @@ static void genpd_debug_add(struct generic_pm_domain *genpd); > > > > > > static void genpd_debug_remove(struct generic_pm_domain *genpd) > > > { > > > - struct dentry *d; > > > - > > > if (!genpd_debugfs_dir) > > > return; > > > > > > - d = debugfs_lookup(genpd->name, genpd_debugfs_dir); > > > - debugfs_remove(d); > > > + debugfs_lookup_and_remove(genpd->name, genpd_debugfs_dir); > > > } > > > > > > static void genpd_update_accounting(struct generic_pm_domain *genpd) > > > -- > > > > Does this depend on anything in your tree, or can I apply it? > > It does not depend on anything in any of my trees, it's made against > Linus's tree right now so please take it through yours. Applied for 6.3 now, thanks!
diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c index 967bcf9d415e..6097644ebdc5 100644 --- a/drivers/base/power/domain.c +++ b/drivers/base/power/domain.c @@ -220,13 +220,10 @@ static void genpd_debug_add(struct generic_pm_domain *genpd); static void genpd_debug_remove(struct generic_pm_domain *genpd) { - struct dentry *d; - if (!genpd_debugfs_dir) return; - d = debugfs_lookup(genpd->name, genpd_debugfs_dir); - debugfs_remove(d); + debugfs_lookup_and_remove(genpd->name, genpd_debugfs_dir); } static void genpd_update_accounting(struct generic_pm_domain *genpd)