From patchwork Thu Feb 2 15:15:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg Kroah-Hartman X-Patchwork-Id: 649894 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 1B87BC61DA4 for ; Thu, 2 Feb 2023 15:15:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232196AbjBBPP3 (ORCPT ); Thu, 2 Feb 2023 10:15:29 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59654 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231989AbjBBPP0 (ORCPT ); Thu, 2 Feb 2023 10:15:26 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 533B72F7A7; Thu, 2 Feb 2023 07:15:21 -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 03585B82693; Thu, 2 Feb 2023 15:15:20 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 44C7EC433D2; Thu, 2 Feb 2023 15:15:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1675350918; bh=wT6dXEufqF8NujpguhuTP6VqmeUu7nwF4Jtnz2lXcoU=; h=From:To:Cc:Subject:Date:From; b=ZZlWnTEYzrQHmf6Lxv32X7gJNz5IU//zUmmMjtX+PvEDn16OE9v8MNrpVQPUeJups vbvj125w0TWFkPobnlaJ5v8N05ypOOKGjcUnE+3JqYs1Uh5zEEOXwDzbUVdhKwNaLY RdA5Ku0inPuWj0dNNQKkQdZZBi4jo09oLGHeT3wc= From: Greg Kroah-Hartman To: linux-pm@vger.kernel.org Cc: Greg Kroah-Hartman , "Rafael J. Wysocki" , Pavel Machek , Len Brown , linux-kernel@vger.kernel.org Subject: [PATCH] kernel/power/energy_model.c: fix memory leak with using debugfs_lookup() Date: Thu, 2 Feb 2023 16:15:15 +0100 Message-Id: <20230202151515.2309543-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=1125; i=gregkh@linuxfoundation.org; h=from:subject; bh=wT6dXEufqF8NujpguhuTP6VqmeUu7nwF4Jtnz2lXcoU=; b=owGbwMvMwCRo6H6F97bub03G02pJDMm3Lzd/ufKF5SHzgr1VU6zDrrQk3uz2D2jVWqxU95in/vO8 EI6AjlgWBkEmBlkxRZYv23iO7q84pOhlaHsaZg4rE8gQBi5OAZjI/SMMCw6kCYm9O10QaLn9oOJ617 k3Jiz6+plhFlNYn+QL+18O/lELF8c56l3rWM/0AgA= X-Developer-Key: i=gregkh@linuxfoundation.org; a=openpgp; fpr=F4B60CC5BF78C2214A313DCB3147D40DDB2DFB29 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org 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" Cc: Pavel Machek Cc: Len Brown Cc: linux-pm@vger.kernel.org Cc: linux-kernel@vger.kernel.org Signed-off-by: Greg Kroah-Hartman --- kernel/power/energy_model.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/kernel/power/energy_model.c b/kernel/power/energy_model.c index f82111837b8d..7b44f5b89fa1 100644 --- a/kernel/power/energy_model.c +++ b/kernel/power/energy_model.c @@ -87,10 +87,7 @@ static void em_debug_create_pd(struct device *dev) static void em_debug_remove_pd(struct device *dev) { - struct dentry *debug_dir; - - debug_dir = debugfs_lookup(dev_name(dev), rootdir); - debugfs_remove_recursive(debug_dir); + debugfs_lookup_and_remove(dev_name(dev), rootdir); } static int __init em_debug_init(void)