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 D2B00C05027 for ; Thu, 2 Feb 2023 15:14:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232667AbjBBPO0 (ORCPT ); Thu, 2 Feb 2023 10:14:26 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58012 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229972AbjBBPOV (ORCPT ); Thu, 2 Feb 2023 10:14:21 -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 1392140C7 for ; Thu, 2 Feb 2023 07:14:20 -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 BB4E9B8268F for ; Thu, 2 Feb 2023 15:14:18 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0FDCDC433D2; Thu, 2 Feb 2023 15:14:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1675350857; bh=PUTozbY7ITrcSJ91h8ZeqAGIKgz32oJvRkMU4DQE528=; h=From:To:Cc:Subject:Date:From; b=YZHnWClZfzooZfXNcIM4b5fTYzgWngMeBrOjM5tzdnwNLvtxtGMmQSUFGNNGd/FDn Ju7iC1LFOFEnbw1s6COIqXcNCnsET17sfZhJzT6SZMClOhO9XgL3LWLrPRu7GrBEAI A2FrjoGxCAW98XmojnyEywelfnuNIvPUGtEbbQBE= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , Chris Down , Petr Mladek , Sergey Senozhatsky , Steven Rostedt , John Ogness Subject: [PATCH] kernel/printk/index.c: fix memory leak with using debugfs_lookup() Date: Thu, 2 Feb 2023 16:14:11 +0100 Message-Id: <20230202151411.2308576-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=1164; i=gregkh@linuxfoundation.org; h=from:subject; bh=PUTozbY7ITrcSJ91h8ZeqAGIKgz32oJvRkMU4DQE528=; b=owGbwMvMwCRo6H6F97bub03G02pJDMm3LzsXq1lWH1ee0z7r5pPTm9KfPnvxPE16Ju/ujQYLTmbx ncnU6ohlYRBkYpAVU2T5so3n6P6KQ4pehranYeawMoEMYeDiFICJ8HswLLjwTWj1o8Qva505157j2M rUk1xo9oxhfv32udFSMY5M01czTe0K5DFryc8yBQA= X-Developer-Key: i=gregkh@linuxfoundation.org; a=openpgp; fpr=F4B60CC5BF78C2214A313DCB3147D40DDB2DFB29 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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: Chris Down Cc: Petr Mladek Cc: Sergey Senozhatsky Cc: Steven Rostedt Cc: John Ogness Cc: linux-kernel@vger.kernel.org Signed-off-by: Greg Kroah-Hartman --- kernel/printk/index.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kernel/printk/index.c b/kernel/printk/index.c index c85be186a783..a6b27526baaf 100644 --- a/kernel/printk/index.c +++ b/kernel/printk/index.c @@ -145,7 +145,7 @@ static void pi_create_file(struct module *mod) #ifdef CONFIG_MODULES static void pi_remove_file(struct module *mod) { - debugfs_remove(debugfs_lookup(pi_get_module_name(mod), dfs_index)); + debugfs_lookup_and_remove(pi_get_module_name(mod), dfs_index); } static int pi_module_notify(struct notifier_block *nb, unsigned long op, -- 2.39.1