linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Dan Carpenter <dan.carpenter@oracle.com>
To: Tong Zhang <ztong0001@gmail.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Jakub Kicinski <kuba@kernel.org>,
	Colin Ian King <colin.king@intel.com>,
	Saurav Girepunje <saurav.girepunje@gmail.com>,
	Johan Hovold <johan@kernel.org>,
	linux-kernel@vger.kernel.org, linux-staging@lists.linux.dev,
	Zheyu Ma <zheyuma97@gmail.com>
Subject: Re: [PATCH] staging: rtl8192u: fix rmmod warn when wlan0 is renamed
Date: Mon, 18 Jul 2022 15:01:49 +0300	[thread overview]
Message-ID: <20220718120149.GD2338@kadam> (raw)
In-Reply-To: <20220717070204.705878-1-ztong0001@gmail.com>

On Sun, Jul 17, 2022 at 12:01:57AM -0700, Tong Zhang wrote:
> +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;
> +	}

This isn't indented properly.  Don't forget to run ./scripts/checkpatch.pl
on your patch.

> +
> +out:
> +	return NOTIFY_DONE;
> +}
> +
> +static struct notifier_block rtl8192_usb_netdev_notifier = {
> +	.notifier_call = rtl8192_usb_netdev_event,
> +};
> +
> +

Here too.

>  static int __init rtl8192_usb_module_init(void)
>  {
>  	int ret;
> @@ -4788,10 +4638,14 @@ static int __init rtl8192_usb_module_init(void)

[ snip ]

> +void rtl8192_debugfs_init(struct net_device *dev)
> +{
> +	struct dentry *dir;
> +	struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
> +
> +	dir = debugfs_create_dir(dev->name, NULL);
> +	if (IS_ERR_OR_NULL(dir))
> +		return;

In olden times the debugfs_create_dir() function used to return a mix
of error pointers and NULL.  But the idea with that function is that
most people are not supposed to check for errors.  But instead of that
they added all kind of *buggy* checks.  So then we made it just return
error pointers.

This code *does* care about it because it uses the
priv->debugfs_dir->d_name.name in rtl8192_debugfs_rename().

But caring about the debugfs dir and creating a rtl8192_debugfs_rename()
function is really unusual.  And normally when we have to do something
unusual that means we are doing something wrong...  :/

Anyway, just check for if (IS_ERR(dir)) {

> +
> +	debugfs_create_file("stats-rx", 0444, dir, dev, &rtl8192_usb_stats_rx_fops);
> +	debugfs_create_file("stats-tx", 0444, dir, dev, &rtl8192_usb_stats_tx_fops);
> +	debugfs_create_file("stats-ap", 0444, dir, dev, &rtl8192_usb_stats_ap_fops);
> +	debugfs_create_file("registers", 0444, dir, dev, &rtl8192_usb_registers_fops);
> +
> +	priv->debugfs_dir = dir;
> +}
> +
> +void rtl8192_debugfs_exit(struct net_device *dev)
> +{
> +	struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
> +	if (!priv->debugfs_dir)
> +		return;
> +	debugfs_remove_recursive(priv->debugfs_dir);
> +	priv->debugfs_dir = NULL;
> +}
> +
> +void rtl8192_debugfs_rename(struct net_device *dev)
> +{
> +	struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
> +
> +	if (!priv->debugfs_dir)
> +		return;
> +
> +	if (!strcmp(priv->debugfs_dir->d_name.name, dev->name))
> +		return;
> +
> +	debugfs_rename(priv->debugfs_dir->d_parent, priv->debugfs_dir,
> +			priv->debugfs_dir->d_parent, dev->name);
> +}
> +

regards,
dan carpenter

  parent reply	other threads:[~2022-07-18 12:02 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 [this message]
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
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=20220718120149.GD2338@kadam \
    --to=dan.carpenter@oracle.com \
    --cc=colin.king@intel.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=johan@kernel.org \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-staging@lists.linux.dev \
    --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;
as well as URLs for NNTP newsgroup(s).