Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp876350rwi; Wed, 19 Oct 2022 04:12:02 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5xB2jVIz2LyuWyc7K2af2kVujLjtfuZe06jhueW5da7C34fCDeWg45xF1DSFigDFW/whmd X-Received: by 2002:a17:907:1deb:b0:78d:4a0e:f654 with SMTP id og43-20020a1709071deb00b0078d4a0ef654mr6348136ejc.757.1666177922649; Wed, 19 Oct 2022 04:12:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666177922; cv=none; d=google.com; s=arc-20160816; b=gY2bKlrD5cyc7aaAHyKeGlsXihCp6rdHA7rTG0l4Om0waejTyBlE0lXT8W+YkZSGpS nozyat48EWR6dcPzfga2CVRc6Yf6O/hpqG3Kzk3g+qv0dNGytgo3BU5FGPLQfKzR7puU NI468jmPPy55ON6V1DBbZRfk+P8dAz+PCSt3v0PqNgjk3aoR+j6s9M13BTVMNGmZClPi L97Y8mCHh0XH6n158WYUobPFn1Ez9zd3QWH9nUVuiWY7M+QFHRiapAyNE0FFD1MK9YCT sP9My15cy40Ml2lDLQfsL0GgSzYXfH8KxyoNH5jc+VWukj91phAAOAoFLRwHsbEQt+4F SrKQ== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=0FZfFRDggJThrZKP5h0o9Bgs4E9AylyY3r2+ZY2GSlA=; b=EVvoODhVBjM1KuZ2ZbuKIaUzDkalX/02OY1AZlIGwPOgfOKfvokW84Az5beQt1Ucxo ksa8l94BtfkSXRHRrMN/T8IZn6VT71fFUQOuWgGaDyi13k/MZqXlyaC7PPBe/AKCdbJb hWk8XINcmWhOH5hKy4BvtIGlC2RfcXsfYMVSm7cu9kNgeKTMjq2lvQeg8uEnJVpUbleu YwkPsluqV7Z5dCKFKYObDlN9WdB6XR1F8pkOE3ql2GuNhIzv/F8UHpQ/lyjW+fhmDr7J OE2J1iFUBytGhdWg7WJkzMOQIan318DDuzthue2ppDZ82zdzqsKW0KcA7HQrmHb8dNa7 Xbgw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=gS2V5IMe; 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 wv2-20020a170907080200b0073146b3f95asi14643306ejb.632.2022.10.19.04.11.30; Wed, 19 Oct 2022 04:12:02 -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=gS2V5IMe; 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 S232390AbiJSKlf (ORCPT + 99 others); Wed, 19 Oct 2022 06:41:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46816 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231480AbiJSKkW (ORCPT ); Wed, 19 Oct 2022 06:40:22 -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 6533410EA09; Wed, 19 Oct 2022 03:19:00 -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 C2225B823CC; Wed, 19 Oct 2022 08:55:09 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 25468C433D6; Wed, 19 Oct 2022 08:55:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666169708; bh=LVfDi4HCdgetF0yIHxqNdI6P3WM866A87brlpoCcN4g=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=gS2V5IMeBj6EMoNWQOVnIHK90f89dZj3jUAv1ulQIySYbPx6P590cMZd9HzjS5ZR+ Yf/Gc0+dG+UkbkY8mZoPH46ejlcNJH56+tTuYHXeMW3xHY3KH3K0FYdpQYvLfajfRR IZ8E1PM7Jaeo2RRqfQ0CFhSsTzv2R7k7VXyv3G0E= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, "Russell King (Oracle)" , Marcin Wojtas , Jakub Kicinski , Sasha Levin Subject: [PATCH 6.0 345/862] net: mvpp2: fix mvpp2 debugfs leak Date: Wed, 19 Oct 2022 10:27:12 +0200 Message-Id: <20221019083305.293903036@linuxfoundation.org> X-Mailer: git-send-email 2.38.0 In-Reply-To: <20221019083249.951566199@linuxfoundation.org> References: <20221019083249.951566199@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.4 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: X-Mailing-List: linux-kernel@vger.kernel.org From: Russell King (Oracle) [ Upstream commit 0152dfee235e87660f52a117fc9f70dc55956bb4 ] When mvpp2 is unloaded, the driver specific debugfs directory is not removed, which technically leads to a memory leak. However, this directory is only created when the first device is probed, so the hardware is present. Removing the module is only something a developer would to when e.g. testing out changes, so the module would be reloaded. So this memory leak is minor. The original attempt in commit fe2c9c61f668 ("net: mvpp2: debugfs: fix memory leak when using debugfs_lookup()") that was labelled as a memory leak fix was not, it fixed a refcount leak, but in doing so created a problem when the module is reloaded - the directory already exists, but mvpp2_root is NULL, so we lose all debugfs entries. This fix has been reverted. This is the alternative fix, where we remove the offending directory whenever the driver is unloaded. Fixes: 21da57a23125 ("net: mvpp2: add a debugfs interface for the Header Parser") Signed-off-by: Russell King (Oracle) Reviewed-by: Greg Kroah-Hartman Reviewed-by: Marcin Wojtas Link: https://lore.kernel.org/r/E1ofOAB-00CzkG-UO@rmk-PC.armlinux.org.uk Signed-off-by: Jakub Kicinski Signed-off-by: Sasha Levin --- drivers/net/ethernet/marvell/mvpp2/mvpp2.h | 1 + drivers/net/ethernet/marvell/mvpp2/mvpp2_debugfs.c | 10 ++++++++-- drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c | 13 ++++++++++++- 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/drivers/net/ethernet/marvell/mvpp2/mvpp2.h b/drivers/net/ethernet/marvell/mvpp2/mvpp2.h index ad73a488fc5f..11e603686a27 100644 --- a/drivers/net/ethernet/marvell/mvpp2/mvpp2.h +++ b/drivers/net/ethernet/marvell/mvpp2/mvpp2.h @@ -1530,6 +1530,7 @@ u32 mvpp2_read(struct mvpp2 *priv, u32 offset); void mvpp2_dbgfs_init(struct mvpp2 *priv, const char *name); void mvpp2_dbgfs_cleanup(struct mvpp2 *priv); +void mvpp2_dbgfs_exit(void); void mvpp23_rx_fifo_fc_en(struct mvpp2 *priv, int port, bool en); diff --git a/drivers/net/ethernet/marvell/mvpp2/mvpp2_debugfs.c b/drivers/net/ethernet/marvell/mvpp2/mvpp2_debugfs.c index 4a3baa7e0142..75e83ea2a926 100644 --- a/drivers/net/ethernet/marvell/mvpp2/mvpp2_debugfs.c +++ b/drivers/net/ethernet/marvell/mvpp2/mvpp2_debugfs.c @@ -691,6 +691,13 @@ static int mvpp2_dbgfs_port_init(struct dentry *parent, return 0; } +static struct dentry *mvpp2_root; + +void mvpp2_dbgfs_exit(void) +{ + debugfs_remove(mvpp2_root); +} + void mvpp2_dbgfs_cleanup(struct mvpp2 *priv) { debugfs_remove_recursive(priv->dbgfs_dir); @@ -700,10 +707,9 @@ void mvpp2_dbgfs_cleanup(struct mvpp2 *priv) void mvpp2_dbgfs_init(struct mvpp2 *priv, const char *name) { - struct dentry *mvpp2_dir, *mvpp2_root; + struct dentry *mvpp2_dir; int ret, i; - mvpp2_root = debugfs_lookup(MVPP2_DRIVER_NAME, NULL); if (!mvpp2_root) mvpp2_root = debugfs_create_dir(MVPP2_DRIVER_NAME, NULL); diff --git a/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c b/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c index b84128b549b4..eaa51cd7456b 100644 --- a/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c +++ b/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c @@ -7706,7 +7706,18 @@ static struct platform_driver mvpp2_driver = { }, }; -module_platform_driver(mvpp2_driver); +static int __init mvpp2_driver_init(void) +{ + return platform_driver_register(&mvpp2_driver); +} +module_init(mvpp2_driver_init); + +static void __exit mvpp2_driver_exit(void) +{ + platform_driver_unregister(&mvpp2_driver); + mvpp2_dbgfs_exit(); +} +module_exit(mvpp2_driver_exit); MODULE_DESCRIPTION("Marvell PPv2 Ethernet Driver - www.marvell.com"); MODULE_AUTHOR("Marcin Wojtas "); -- 2.35.1