Received: by 2002:a05:6358:45e:b0:b5:b6eb:e1f9 with SMTP id 30csp2028707rwe; Fri, 2 Sep 2022 07:33:35 -0700 (PDT) X-Google-Smtp-Source: AA6agR6a2kUjWhiNaIY5uPQjTeAs4VDq7BjvVwkXaHpU6fAVsNlCFuVpvacSkuKibY8Aa/4nzJLY X-Received: by 2002:a17:902:720c:b0:172:a1ff:8c21 with SMTP id ba12-20020a170902720c00b00172a1ff8c21mr35951797plb.159.1662129215267; Fri, 02 Sep 2022 07:33:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662129215; cv=none; d=google.com; s=arc-20160816; b=kX5JC0oUWnENSDeYPtE7uX62KGVUFTpSiQqsXDLoqLMzXk+ChqJQNe64tMA3C9el8X keJ+SK+dvizg4Dm+6NSdN+bYGvEnwQPJIHSZDiPkTpEDBdShAYnLagNhJNlQY0fde1pB wTkj+9oFMoFChMe7C5yPAdRWKprey7i1C6EF41JtK0jrfUVhNtE2/ccTs6sZ3cYAhwwh nmqBDq+qg+TBhNGfOb4RPwSiedGLxf3lVdzIaPF9T6UJxzWa0/OmY36vBXAsC8F9c5l/ ogRXPZ+KlfHjiDa4jdrVAlyfniVzAJavJCEsYYF7fmf2jBk/8RcCBtt6ZNK7JLYiRyot F+HA== 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=vRd26sQq1BNnI5x0SUkVJYPjBq24ek/zDfaAMrVyukg=; b=0GHKRDc0dxT6jlFl9yTJvoI7ZjM3R55v/rKiD30E9yIDyEdP1X3LB3RFK3auTRdr79 hhsls1PdDyS39h2IpvZ6UNP7mJFB+9YpL6A47IkqdQHKJBYhk8d3I2OCTkrBmS1a17N7 a8EOBuRloKxTWwv/juuBcaEfHRud3+wP77+kJKOmEIYbzDxc6c7R7Jjx17qO6RuU76IY dNZCsHTOkPQIdw45LVOdV71l61Grnm4bImQEwdqfmHbBetixG56hSd8th9gsCCkw1lgg GeIyr8tkZnSeLlujkVRRR464lAxzItqbH9qoMO9BRICQEjJV3gGy5naJX4waS/EkYssA VbJw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=2ViCa0hS; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id t8-20020a6549c8000000b0041d9a9bb77fsi2148162pgs.45.2022.09.02.07.33.19; Fri, 02 Sep 2022 07:33:35 -0700 (PDT) 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=2ViCa0hS; 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 S237288AbiIBOQB (ORCPT + 99 others); Fri, 2 Sep 2022 10:16:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54788 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236905AbiIBOPe (ORCPT ); Fri, 2 Sep 2022 10:15:34 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BE75914D458 for ; Fri, 2 Sep 2022 06:42:43 -0700 (PDT) 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 1A418B82AA1 for ; Fri, 2 Sep 2022 13:37:36 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2D85FC433D7; Fri, 2 Sep 2022 13:37:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1662125854; bh=jzG0D03+vxrGLGIs+YSm8b2wkD8dPvpWfTaQQGIfuUQ=; h=From:To:Cc:Subject:Date:From; b=2ViCa0hSTALym2d7H6yIqIwgR8f1Cxi4K31j+6jsXg+w1JHIOCKWKLXjg1VZvqhcg ftRrqkTVmSIvwGK11JY5lSt1cKLALoA2oxNjjkp7XBYrB0hmbvV9VvaDwxTJgn5oXE O/5IXY5ow7hYMnDanucblQbpuWYVpwLfxi7TIOe0= From: Greg Kroah-Hartman To: tudor.ambarus@microchip.com, pratyush@kernel.org Cc: linux-kernel@vger.kernel.org, Greg Kroah-Hartman , Michael Walle , Miquel Raynal , Richard Weinberger , Vignesh Raghavendra , linux-mtd@lists.infradead.org, stable Subject: [PATCH] mtd: spi-nor: fix memory leak when using debugfs_lookup() Date: Fri, 2 Sep 2022 15:37:24 +0200 Message-Id: <20220902133724.278133-1-gregkh@linuxfoundation.org> X-Mailer: git-send-email 2.37.3 MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=1455; i=gregkh@linuxfoundation.org; h=from:subject; bh=jzG0D03+vxrGLGIs+YSm8b2wkD8dPvpWfTaQQGIfuUQ=; b=owGbwMvMwCRo6H6F97bub03G02pJDMlC7EJ2v/4aB/pOcFJJuSPvsO+F/9TH8iail28bPHKyMTx9 VaCyI5aFQZCJQVZMkeXLNp6j+ysOKXoZ2p6GmcPKBDKEgYtTACZSdZ5hQevH1PPLlYxy/TfemvtXde 7U2z+8zjHMZMyf/qdsnvzMS3uCPF/bH1p8iOtQHQA= 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,T_SCC_BODY_TEXT_LINE 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: 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. Fix this up to be much simpler logic and only create the root debugfs directory once when the driver is first accessed. That resolves the memory leak and makes things more obvious as to what the intent is. Cc: Tudor Ambarus Cc: Pratyush Yadav Cc: Michael Walle Cc: Miquel Raynal Cc: Richard Weinberger Cc: Vignesh Raghavendra Cc: linux-mtd@lists.infradead.org Cc: stable Signed-off-by: Greg Kroah-Hartman --- drivers/mtd/spi-nor/debugfs.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/mtd/spi-nor/debugfs.c b/drivers/mtd/spi-nor/debugfs.c index df76cb5de3f9..3aab595e82d1 100644 --- a/drivers/mtd/spi-nor/debugfs.c +++ b/drivers/mtd/spi-nor/debugfs.c @@ -228,11 +228,11 @@ static void spi_nor_debugfs_unregister(void *data) void spi_nor_debugfs_register(struct spi_nor *nor) { - struct dentry *rootdir, *d; + static struct dentry *rootdir; + struct dentry *d; int ret; /* Create rootdir once. Will never be deleted again. */ - rootdir = debugfs_lookup(SPI_NOR_DEBUGFS_ROOT, NULL); if (!rootdir) rootdir = debugfs_create_dir(SPI_NOR_DEBUGFS_ROOT, NULL); -- 2.37.3