From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: Tong Zhang <ztong0001@gmail.com>
Cc: Jakub Kicinski <kuba@kernel.org>,
Colin Ian King <colin.king@intel.com>,
Saurav Girepunje <saurav.girepunje@gmail.com>,
Nathan Chancellor <nathan@kernel.org>,
Johan Hovold <johan@kernel.org>,
linux-kernel@vger.kernel.org, linux-staging@lists.linux.dev,
dan.carpenter@oracle.com, Zheyu Ma <zheyuma97@gmail.com>
Subject: Re: [PATCH v2 3/3] staging: rtl8192u: fix rmmod warn when wlan0 is renamed
Date: Tue, 19 Jul 2022 14:39:56 +0200 [thread overview]
Message-ID: <YtamHKt7e/xqk+Jk@kroah.com> (raw)
In-Reply-To: <20220719055047.322355-4-ztong0001@gmail.com>
On Mon, Jul 18, 2022 at 10:50:38PM -0700, Tong Zhang wrote:
> This driver creates 4 debug files under [devname] folder. The devname
> could be wlan0 initially, however it could be renamed later to e.g.
> enx00e04c00000. This will cause problem during debug file teardown since
> it uses netdev->name which is no longer wlan0. To solve this problem,
> add a notifier to handle device renaming.
>
> Reported-by: Zheyu Ma <zheyuma97@gmail.com>
> Tested-by: Zheyu Ma <zheyuma97@gmail.com>
> Signed-off-by: Tong Zhang <ztong0001@gmail.com>
> ---
> drivers/staging/rtl8192u/r8192U.h | 1 +
> drivers/staging/rtl8192u/r8192U_core.c | 35 ++++++++++++++++++++++-
> drivers/staging/rtl8192u/r8192U_debugfs.c | 13 +++++++++
> 3 files changed, 48 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/staging/rtl8192u/r8192U.h b/drivers/staging/rtl8192u/r8192U.h
> index e8860bb2b607..ccce37b7e2ae 100644
> --- a/drivers/staging/rtl8192u/r8192U.h
> +++ b/drivers/staging/rtl8192u/r8192U.h
> @@ -1122,4 +1122,5 @@ void setKey(struct net_device *dev, u8 EntryNo, u8 KeyIndex, u16 KeyType,
>
> void rtl8192_debugfs_init(struct net_device *dev);
> void rtl8192_debugfs_exit(struct net_device *dev);
> +void rtl8192_debugfs_rename(struct net_device *dev);
> #endif
> diff --git a/drivers/staging/rtl8192u/r8192U_core.c b/drivers/staging/rtl8192u/r8192U_core.c
> index ac3716550505..5cc78c5bd706 100644
> --- a/drivers/staging/rtl8192u/r8192U_core.c
> +++ b/drivers/staging/rtl8192u/r8192U_core.c
> @@ -4606,6 +4606,30 @@ static void rtl8192_usb_disconnect(struct usb_interface *intf)
> RT_TRACE(COMP_DOWN, "wlan driver removed\n");
> }
>
> +static int rtl8192_usb_netdev_event(struct notifier_block *nb, unsigned long event,
> + void *data)
> +{
> + struct net_device *netdev = netdev_notifier_info_to_dev(data);
> +
> + if (netdev->netdev_ops != &rtl8192_netdev_ops)
> + goto out;
> +
> + switch (event) {
> + case NETDEV_CHANGENAME:
> + rtl8192_debugfs_rename(netdev);
> + break;
> + default:
> + break;
> + }
> +
> +out:
> + return NOTIFY_DONE;
> +}
> +
> +static struct notifier_block rtl8192_usb_netdev_notifier = {
> + .notifier_call = rtl8192_usb_netdev_event,
> +};
> +
> static int __init rtl8192_usb_module_init(void)
> {
> int ret;
> @@ -4615,10 +4639,16 @@ static int __init rtl8192_usb_module_init(void)
> RT_TRACE(COMP_INIT, "Initializing module");
> RT_TRACE(COMP_INIT, "Wireless extensions version %d", WIRELESS_EXT);
>
> + ret = register_netdevice_notifier(&rtl8192_usb_netdev_notifier);
> + if (ret) {
> + pr_err("register_netdevice_notifier failed %d\n", ret);
> + return ret;
> + }
> +
> ret = ieee80211_debug_init();
> if (ret) {
> pr_err("ieee80211_debug_init() failed %d\n", ret);
> - return ret;
> + goto unregister_notifier;
> }
>
> ret = ieee80211_crypto_init();
> @@ -4660,6 +4690,8 @@ static int __init rtl8192_usb_module_init(void)
> ieee80211_crypto_deinit();
> debug_exit:
> ieee80211_debug_exit();
> +unregister_notifier:
> + unregister_netdevice_notifier(&rtl8192_usb_netdev_notifier);
> return ret;
> }
>
> @@ -4671,6 +4703,7 @@ static void __exit rtl8192_usb_module_exit(void)
> ieee80211_crypto_tkip_exit();
> ieee80211_crypto_deinit();
> ieee80211_debug_exit();
> + unregister_netdevice_notifier(&rtl8192_usb_netdev_notifier);
> RT_TRACE(COMP_DOWN, "Exiting");
> }
>
> diff --git a/drivers/staging/rtl8192u/r8192U_debugfs.c b/drivers/staging/rtl8192u/r8192U_debugfs.c
> index 5c9376e50889..c94f5dfac96b 100644
> --- a/drivers/staging/rtl8192u/r8192U_debugfs.c
> +++ b/drivers/staging/rtl8192u/r8192U_debugfs.c
> @@ -173,3 +173,16 @@ void rtl8192_debugfs_exit(struct net_device *dev)
> priv->debugfs_dir = NULL;
> }
>
> +void rtl8192_debugfs_rename(struct net_device *dev)
> +{
> + struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
No need to cast.
> +
> + if (!priv->debugfs_dir)
> + return;
Why does it matter?
> +
> + if (!strcmp(priv->debugfs_dir->d_name.name, dev->name))
Ick, never poke around in a dentry from debugfs if you can help it. You
know you are being renamed, why does it matter to check or not?
> + return;
> +
> + debugfs_rename(priv->debugfs_dir->d_parent, priv->debugfs_dir,
> + priv->debugfs_dir->d_parent, dev->name);
Don't poke around in the dentry for the parent here either. That feels
racy and wrong. Isn't there some other way to get the parent?
Also you can look up the dentry for this, no need to have it saved, like
I said in patch 2.
thanks,
greg k-h
next prev parent reply other threads:[~2022-07-19 13:39 UTC|newest]
Thread overview: 35+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-07-16 12:16 [BUG] staging: rtl8192u: Found a bug when removing the module Zheyu Ma
2022-07-17 7:01 ` Tong Zhang
2022-07-17 7:01 ` [PATCH] staging: rtl8192u: fix rmmod warn when wlan0 is renamed Tong Zhang
2022-07-17 8:04 ` Zheyu Ma
2022-07-18 11:39 ` Dan Carpenter
2022-07-18 11:47 ` Dan Carpenter
2022-07-18 12:01 ` Dan Carpenter
2022-07-19 5:50 ` [PATCH v2 0/3] " Tong Zhang
2022-07-19 8:04 ` Dan Carpenter
2022-07-19 5:50 ` [PATCH v2 1/3] staging: rtl8192u: move debug stuff to its own file Tong Zhang
2022-07-19 5:50 ` [PATCH v2 2/3] staging: rtl8192u: move debug files to debugfs Tong Zhang
2022-07-19 12:37 ` Greg Kroah-Hartman
2022-07-20 4:58 ` Tong Zhang
2022-07-27 6:35 ` Greg Kroah-Hartman
2022-07-20 6:30 ` Tong Zhang
2022-07-27 6:37 ` Greg Kroah-Hartman
2022-07-29 3:51 ` Tong Zhang
2022-07-29 3:52 ` [PATCH v3 0/3] staging: rtl8192u: fix rmmod warn when device is renamed Tong Zhang
2022-07-29 3:52 ` [PATCH v3 1/3] staging: rtl8192u: move debug stuff to its own file Tong Zhang
2022-07-29 6:23 ` Philipp Hortmann
2022-07-30 3:35 ` Tong Zhang
2022-07-29 3:52 ` [PATCH v3 2/3] staging: rtl8192u: move debug files to debugfs Tong Zhang
2022-07-29 7:31 ` Greg Kroah-Hartman
2022-07-29 3:52 ` [PATCH v3 3/3] staging: rtl8192u: fix rmmod warn when device is renamed Tong Zhang
2022-07-29 7:27 ` Greg Kroah-Hartman
2022-07-30 3:33 ` Tong Zhang
2022-07-30 3:33 ` [PATCH v4 0/4] " Tong Zhang
2022-07-30 3:33 ` [PATCH v4 1/4] staging: rtl8192u: move debug stuff to its own file Tong Zhang
2022-07-30 3:33 ` [PATCH v4 2/4] staging: rtl8192u: remove unnecessary cast Tong Zhang
2022-07-30 3:33 ` [PATCH v4 3/4] staging: rtl8192u: move debug files to debugfs Tong Zhang
2022-07-30 3:33 ` [PATCH v4 4/4] staging: rtl8192u: fix rmmod warn when device is renamed Tong Zhang
2022-07-19 5:50 ` [PATCH v2 3/3] staging: rtl8192u: fix rmmod warn when wlan0 " Tong Zhang
2022-07-19 12:39 ` Greg Kroah-Hartman [this message]
2022-07-20 6:16 ` Tong Zhang
2022-07-19 5:52 ` [PATCH] " Tong Zhang
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=YtamHKt7e/xqk+Jk@kroah.com \
--to=gregkh@linuxfoundation.org \
--cc=colin.king@intel.com \
--cc=dan.carpenter@oracle.com \
--cc=johan@kernel.org \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-staging@lists.linux.dev \
--cc=nathan@kernel.org \
--cc=saurav.girepunje@gmail.com \
--cc=zheyuma97@gmail.com \
--cc=ztong0001@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®