From: Greg KH <gregkh@linuxfoundation.org>
To: Vivien Didelot <vivien.didelot@savoirfairelinux.com>
Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
kernel@savoirfairelinux.com,
"David S. Miller" <davem@davemloft.net>,
Florian Fainelli <f.fainelli@gmail.com>,
Andrew Lunn <andrew@lunn.ch>,
Egil Hjelmeland <privat@egil-hjelmeland.no>,
John Crispin <john@phrozen.org>,
Woojung Huh <Woojung.Huh@microchip.com>,
Sean Wang <sean.wang@mediatek.com>,
Nikita Yushchenko <nikita.yoush@cogentembedded.com>,
Chris Healy <cphealy@gmail.com>
Subject: Re: [PATCH net-next v2 01/10] net: dsa: add debugfs interface
Date: Thu, 7 Sep 2017 21:34:34 +0200 [thread overview]
Message-ID: <20170907193434.GA11006@kroah.com> (raw)
In-Reply-To: <20170828191748.19492-2-vivien.didelot@savoirfairelinux.com>
I agree you shouldn't be using debugfs for this, but in the future, if
you do write debugfs code, please take the following review into
account:
On Mon, Aug 28, 2017 at 03:17:39PM -0400, Vivien Didelot wrote:
> +static int dsa_debugfs_create_port(struct dsa_switch *ds, int port)
> +{
> + struct dentry *dir;
> + char name[32];
> +
> + snprintf(name, sizeof(name), DSA_PORT_FMT, port);
> +
> + dir = debugfs_create_dir(name, ds->debugfs_dir);
> + if (IS_ERR_OR_NULL(dir))
> + return -EFAULT;
You should _never_ care about the return value of a debugfs call, and
you should not need to ever propagate the error upward. The api was
written to not need this.
Just call the function, and return, that's it. If you need to save the
return value (i.e. it's a dentry), you also don't care, just save it and
pass it to some other debugfs call, and all will still be fine. Your
code should never do anything different if a debugfs call succeeds or
fails.
> +static int dsa_debugfs_create_switch(struct dsa_switch *ds)
> +{
> + char name[32];
> + int i, err;
> +
> + /* skip if there is no debugfs support */
> + if (!dsa_debugfs_dir)
> + return 0;
Again, you don't care, all of these functions should return void.
> + snprintf(name, sizeof(name), DSA_SWITCH_FMT, ds->index);
> +
> + ds->debugfs_dir = debugfs_create_dir(name, dsa_debugfs_dir);
> + if (IS_ERR_OR_NULL(ds->debugfs_dir))
> + return -EFAULT;
See, that's horrid, you should never need to make such a bad check.
Also, even if it were the correct way to do this you never return EFAULT
unless there is a memory copy error to/from userspace. That is not the
case here, or in any of this code, right?
> +static void dsa_debugfs_destroy_switch(struct dsa_switch *ds)
> +{
> + /* handles NULL */
> + debugfs_remove_recursive(ds->debugfs_dir);
Of course it handles NULL, why comment that? That's the whole goal of
debugfs, to be dirt simple, allow you to do anything you want, in almost
no lines of code.
Also, it will never be mounted on a "real" system, so you better not
rely on it for anything "real".
> + err = dsa_debugfs_create_switch(ds);
> + if (err) {
> + pr_warn("DSA: failed to create debugfs interface for switch %d (%d)\n",
> + ds->index, err);
Never complain to the syslog about a debugfs issue.
> +void dsa_debugfs_destroy_module(void)
> +{
> + /* handles NULL */
> + debugfs_remove_recursive(dsa_debugfs_dir);
again, of course it does, do you think we don't know how to write an
api? :)
thanks,
greg k-h
next prev parent reply other threads:[~2017-09-08 5:15 UTC|newest]
Thread overview: 40+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-08-28 19:17 [PATCH net-next v2 00/10] net: dsa: add generic debugfs interface Vivien Didelot
2017-08-28 19:17 ` [PATCH net-next v2 01/10] net: dsa: add " Vivien Didelot
2017-08-28 19:50 ` Jiri Pirko
2017-08-28 19:58 ` Florian Fainelli
2017-08-28 20:05 ` Jiri Pirko
2017-08-28 20:19 ` Andrew Lunn
2017-09-07 19:34 ` Greg KH [this message]
2017-09-08 13:58 ` Vivien Didelot
2017-09-14 19:59 ` Maxim Uvarov
2017-09-14 20:12 ` Alexander Duyck
2017-09-14 21:01 ` Andrew Lunn
2017-09-15 5:51 ` Jiri Pirko
2017-09-15 7:35 ` Egil Hjelmeland
2017-08-28 19:17 ` [PATCH net-next v2 02/10] net: dsa: debugfs: add tree Vivien Didelot
2017-09-08 14:18 ` Vivien Didelot
2017-09-08 14:40 ` Greg Kroah-Hartman
2017-09-08 14:57 ` Vivien Didelot
2017-09-08 15:03 ` David Laight
2017-09-08 15:29 ` Greg Kroah-Hartman
2017-08-28 19:17 ` [PATCH net-next v2 03/10] net: dsa: debugfs: add tag_protocol Vivien Didelot
2017-08-28 20:16 ` Andrew Lunn
2017-08-28 19:17 ` [PATCH net-next v2 04/10] net: dsa: debugfs: add port stats Vivien Didelot
2017-08-28 19:17 ` [PATCH net-next v2 05/10] net: dsa: debugfs: add port regs Vivien Didelot
2017-08-28 19:17 ` [PATCH net-next v2 06/10] net: dsa: debugfs: add port fdb Vivien Didelot
2017-08-28 19:17 ` [PATCH net-next v2 07/10] net: dsa: restore mdb dump Vivien Didelot
2017-08-28 19:17 ` [PATCH net-next v2 08/10] net: dsa: debugfs: add port mdb Vivien Didelot
2017-08-28 19:17 ` [PATCH net-next v2 09/10] net: dsa: restore VLAN dump Vivien Didelot
2017-08-28 19:17 ` [PATCH net-next v2 10/10] net: dsa: debugfs: add port vlan Vivien Didelot
2017-08-28 19:53 ` [PATCH net-next v2 00/10] net: dsa: add generic debugfs interface Jiri Pirko
2017-08-28 20:08 ` Andrew Lunn
2017-08-29 6:25 ` Jiri Pirko
2017-08-29 12:50 ` Andrew Lunn
2017-08-29 19:05 ` Arkadi Sharshevsky
2017-08-29 19:19 ` Florian Fainelli
2017-08-29 20:27 ` Andrew Lunn
2017-08-30 7:43 ` Jiri Pirko
2017-08-29 4:38 ` David Miller
2017-08-29 6:29 ` Jiri Pirko
2017-08-29 15:57 ` Vivien Didelot
2017-08-30 7:40 ` Jiri Pirko
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=20170907193434.GA11006@kroah.com \
--to=gregkh@linuxfoundation.org \
--cc=Woojung.Huh@microchip.com \
--cc=andrew@lunn.ch \
--cc=cphealy@gmail.com \
--cc=davem@davemloft.net \
--cc=f.fainelli@gmail.com \
--cc=john@phrozen.org \
--cc=kernel@savoirfairelinux.com \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=nikita.yoush@cogentembedded.com \
--cc=privat@egil-hjelmeland.no \
--cc=sean.wang@mediatek.com \
--cc=vivien.didelot@savoirfairelinux.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