From: Stephen Hemminger <stephen@networkplumber.org>
To: Maciej Fijalkowski <maciej.fijalkowski@intel.com>
Cc: Vladimir Oltean <vladimir.oltean@nxp.com>,
<netdev@vger.kernel.org>, "David S. Miller" <davem@davemloft.net>,
"Eric Dumazet" <edumazet@google.com>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
Claudiu Manoil <claudiu.manoil@nxp.com>,
"Giuseppe Cavallaro" <peppe.cavallaro@st.com>,
Alexandre Torgue <alexandre.torgue@foss.st.com>,
Jose Abreu <joabreu@synopsys.com>,
"Maxime Coquelin" <mcoquelin.stm32@gmail.com>,
Yang Yang <yang.yang29@zte.com>, "Xu Panda" <xu.panda@zte.com.cn>,
<linux-stm32@st-md-mailman.stormreply.com>,
<linux-arm-kernel@lists.infradead.org>,
<linux-kernel@vger.kernel.org>
Subject: Re: [PATCH net-next] Revert "net: stmmac: use sysfs_streq() instead of strncmp()"
Date: Fri, 25 Nov 2022 10:44:01 -0800 [thread overview]
Message-ID: <20221125104401.0e18979f@hermes.local> (raw)
In-Reply-To: <Y4Ct37sV+/y9rcly@boxer>
On Fri, 25 Nov 2022 12:58:23 +0100
Maciej Fijalkowski <maciej.fijalkowski@intel.com> wrote:
> On Fri, Nov 25, 2022 at 12:53:04PM +0200, Vladimir Oltean wrote:
> > This reverts commit f72cd76b05ea1ce9258484e8127932d0ea928f22.
> > This patch is so broken, it hurts. Apparently no one reviewed it and it
> > passed the build testing (because the code was compiled out), but it was
> > obviously never compile-tested, since it produces the following build
> > error, due to an incomplete conversion where an extra argument was left,
> > although the function being called was left:
> >
> > stmmac_main.c: In function ‘stmmac_cmdline_opt’:
> > stmmac_main.c:7586:28: error: too many arguments to function ‘sysfs_streq’
> > 7586 | } else if (sysfs_streq(opt, "pause:", 6)) {
> > | ^~~~~~~~~~~
> > In file included from ../include/linux/bitmap.h:11,
> > from ../include/linux/cpumask.h:12,
> > from ../include/linux/smp.h:13,
> > from ../include/linux/lockdep.h:14,
> > from ../include/linux/mutex.h:17,
> > from ../include/linux/notifier.h:14,
> > from ../include/linux/clk.h:14,
> > from ../drivers/net/ethernet/stmicro/stmmac/stmmac_main.c:17:
> > ../include/linux/string.h:185:13: note: declared here
> > 185 | extern bool sysfs_streq(const char *s1, const char *s2);
> > | ^~~~~~~~~~~
> >
> > What's even worse is that the patch is flat out wrong. The stmmac_cmdline_opt()
> > function does not parse sysfs input, but cmdline input such as
> > "stmmaceth=tc:1,pause:1". The pattern of using strsep() followed by
> > strncmp() for such strings is not unique to stmmac, it can also be found
> > mainly in drivers under drivers/video/fbdev/.
> >
> > With strncmp("tc:", 3), the code matches on the "tc:1" token properly.
> > With sysfs_streq("tc:"), it doesn't.
> >
> > Fixes: f72cd76b05ea ("net: stmmac: use sysfs_streq() instead of strncmp()")
> > Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
>
> Ah the infamous string handling in C...
>
> Acked-by: Maciej Fijalkowski <maciej.fijalkowski@intel.com>
>
> Even when there would be no build error I agree that we should have kept
> the code as it was.
>
> > ---
> > .../net/ethernet/stmicro/stmmac/stmmac_main.c | 18 +++++++++---------
> > 1 file changed, 9 insertions(+), 9 deletions(-)
> >
> > diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
> > index 1a86e66e4560..3affb7d3a005 100644
> > --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
> > +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
> > @@ -7565,31 +7565,31 @@ static int __init stmmac_cmdline_opt(char *str)
> > if (!str || !*str)
> > return 1;
> > while ((opt = strsep(&str, ",")) != NULL) {
> > - if (sysfs_streq(opt, "debug:")) {
> > + if (!strncmp(opt, "debug:", 6)) {
> > if (kstrtoint(opt + 6, 0, &debug))
> > goto err;
> > - } else if (sysfs_streq(opt, "phyaddr:")) {
> > + } else if (!strncmp(opt, "phyaddr:", 8)) {
> > if (kstrtoint(opt + 8, 0, &phyaddr))
> > goto err;
> > - } else if (sysfs_streq(opt, "buf_sz:")) {
> > + } else if (!strncmp(opt, "buf_sz:", 7)) {
> > if (kstrtoint(opt + 7, 0, &buf_sz))
> > goto err;
> > - } else if (sysfs_streq(opt, "tc:")) {
> > + } else if (!strncmp(opt, "tc:", 3)) {
> > if (kstrtoint(opt + 3, 0, &tc))
> > goto err;
> > - } else if (sysfs_streq(opt, "watchdog:")) {
> > + } else if (!strncmp(opt, "watchdog:", 9)) {
> > if (kstrtoint(opt + 9, 0, &watchdog))
> > goto err;
> > - } else if (sysfs_streq(opt, "flow_ctrl:")) {
> > + } else if (!strncmp(opt, "flow_ctrl:", 10)) {
> > if (kstrtoint(opt + 10, 0, &flow_ctrl))
> > goto err;
> > - } else if (sysfs_streq(opt, "pause:", 6)) {
> > + } else if (!strncmp(opt, "pause:", 6)) {
> > if (kstrtoint(opt + 6, 0, &pause))
> > goto err;
> > - } else if (sysfs_streq(opt, "eee_timer:")) {
> > + } else if (!strncmp(opt, "eee_timer:", 10)) {
> > if (kstrtoint(opt + 10, 0, &eee_timer))
> > goto err;
> > - } else if (sysfs_streq(opt, "chain_mode:")) {
> > + } else if (!strncmp(opt, "chain_mode:", 11)) {
> > if (kstrtoint(opt + 11, 0, &chain_mode))
> > goto err;
> > }
> > --
> > 2.34.1
> >
Configuring via module options is bad idea.
If you have to do it don't roll your own key/value parsing.
If the driver just used regular module_param() for this it wouldn't have this crap.
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
WARNING: multiple messages have this Message-ID (diff)
From: Stephen Hemminger <stephen@networkplumber.org>
To: Maciej Fijalkowski <maciej.fijalkowski@intel.com>
Cc: Vladimir Oltean <vladimir.oltean@nxp.com>,
<netdev@vger.kernel.org>, "David S. Miller" <davem@davemloft.net>,
"Eric Dumazet" <edumazet@google.com>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
Claudiu Manoil <claudiu.manoil@nxp.com>,
"Giuseppe Cavallaro" <peppe.cavallaro@st.com>,
Alexandre Torgue <alexandre.torgue@foss.st.com>,
Jose Abreu <joabreu@synopsys.com>,
"Maxime Coquelin" <mcoquelin.stm32@gmail.com>,
Yang Yang <yang.yang29@zte.com>, "Xu Panda" <xu.panda@zte.com.cn>,
<linux-stm32@st-md-mailman.stormreply.com>,
<linux-arm-kernel@lists.infradead.org>,
<linux-kernel@vger.kernel.org>
Subject: Re: [PATCH net-next] Revert "net: stmmac: use sysfs_streq() instead of strncmp()"
Date: Fri, 25 Nov 2022 10:44:01 -0800 [thread overview]
Message-ID: <20221125104401.0e18979f@hermes.local> (raw)
In-Reply-To: <Y4Ct37sV+/y9rcly@boxer>
On Fri, 25 Nov 2022 12:58:23 +0100
Maciej Fijalkowski <maciej.fijalkowski@intel.com> wrote:
> On Fri, Nov 25, 2022 at 12:53:04PM +0200, Vladimir Oltean wrote:
> > This reverts commit f72cd76b05ea1ce9258484e8127932d0ea928f22.
> > This patch is so broken, it hurts. Apparently no one reviewed it and it
> > passed the build testing (because the code was compiled out), but it was
> > obviously never compile-tested, since it produces the following build
> > error, due to an incomplete conversion where an extra argument was left,
> > although the function being called was left:
> >
> > stmmac_main.c: In function ‘stmmac_cmdline_opt’:
> > stmmac_main.c:7586:28: error: too many arguments to function ‘sysfs_streq’
> > 7586 | } else if (sysfs_streq(opt, "pause:", 6)) {
> > | ^~~~~~~~~~~
> > In file included from ../include/linux/bitmap.h:11,
> > from ../include/linux/cpumask.h:12,
> > from ../include/linux/smp.h:13,
> > from ../include/linux/lockdep.h:14,
> > from ../include/linux/mutex.h:17,
> > from ../include/linux/notifier.h:14,
> > from ../include/linux/clk.h:14,
> > from ../drivers/net/ethernet/stmicro/stmmac/stmmac_main.c:17:
> > ../include/linux/string.h:185:13: note: declared here
> > 185 | extern bool sysfs_streq(const char *s1, const char *s2);
> > | ^~~~~~~~~~~
> >
> > What's even worse is that the patch is flat out wrong. The stmmac_cmdline_opt()
> > function does not parse sysfs input, but cmdline input such as
> > "stmmaceth=tc:1,pause:1". The pattern of using strsep() followed by
> > strncmp() for such strings is not unique to stmmac, it can also be found
> > mainly in drivers under drivers/video/fbdev/.
> >
> > With strncmp("tc:", 3), the code matches on the "tc:1" token properly.
> > With sysfs_streq("tc:"), it doesn't.
> >
> > Fixes: f72cd76b05ea ("net: stmmac: use sysfs_streq() instead of strncmp()")
> > Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
>
> Ah the infamous string handling in C...
>
> Acked-by: Maciej Fijalkowski <maciej.fijalkowski@intel.com>
>
> Even when there would be no build error I agree that we should have kept
> the code as it was.
>
> > ---
> > .../net/ethernet/stmicro/stmmac/stmmac_main.c | 18 +++++++++---------
> > 1 file changed, 9 insertions(+), 9 deletions(-)
> >
> > diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
> > index 1a86e66e4560..3affb7d3a005 100644
> > --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
> > +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
> > @@ -7565,31 +7565,31 @@ static int __init stmmac_cmdline_opt(char *str)
> > if (!str || !*str)
> > return 1;
> > while ((opt = strsep(&str, ",")) != NULL) {
> > - if (sysfs_streq(opt, "debug:")) {
> > + if (!strncmp(opt, "debug:", 6)) {
> > if (kstrtoint(opt + 6, 0, &debug))
> > goto err;
> > - } else if (sysfs_streq(opt, "phyaddr:")) {
> > + } else if (!strncmp(opt, "phyaddr:", 8)) {
> > if (kstrtoint(opt + 8, 0, &phyaddr))
> > goto err;
> > - } else if (sysfs_streq(opt, "buf_sz:")) {
> > + } else if (!strncmp(opt, "buf_sz:", 7)) {
> > if (kstrtoint(opt + 7, 0, &buf_sz))
> > goto err;
> > - } else if (sysfs_streq(opt, "tc:")) {
> > + } else if (!strncmp(opt, "tc:", 3)) {
> > if (kstrtoint(opt + 3, 0, &tc))
> > goto err;
> > - } else if (sysfs_streq(opt, "watchdog:")) {
> > + } else if (!strncmp(opt, "watchdog:", 9)) {
> > if (kstrtoint(opt + 9, 0, &watchdog))
> > goto err;
> > - } else if (sysfs_streq(opt, "flow_ctrl:")) {
> > + } else if (!strncmp(opt, "flow_ctrl:", 10)) {
> > if (kstrtoint(opt + 10, 0, &flow_ctrl))
> > goto err;
> > - } else if (sysfs_streq(opt, "pause:", 6)) {
> > + } else if (!strncmp(opt, "pause:", 6)) {
> > if (kstrtoint(opt + 6, 0, &pause))
> > goto err;
> > - } else if (sysfs_streq(opt, "eee_timer:")) {
> > + } else if (!strncmp(opt, "eee_timer:", 10)) {
> > if (kstrtoint(opt + 10, 0, &eee_timer))
> > goto err;
> > - } else if (sysfs_streq(opt, "chain_mode:")) {
> > + } else if (!strncmp(opt, "chain_mode:", 11)) {
> > if (kstrtoint(opt + 11, 0, &chain_mode))
> > goto err;
> > }
> > --
> > 2.34.1
> >
Configuring via module options is bad idea.
If you have to do it don't roll your own key/value parsing.
If the driver just used regular module_param() for this it wouldn't have this crap.
next prev parent reply other threads:[~2022-11-25 18:45 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-11-25 10:53 [PATCH net-next] Revert "net: stmmac: use sysfs_streq() instead of strncmp()" Vladimir Oltean
2022-11-25 10:53 ` Vladimir Oltean
2022-11-25 11:58 ` Maciej Fijalkowski
2022-11-25 11:58 ` Maciej Fijalkowski
2022-11-25 18:44 ` Stephen Hemminger [this message]
2022-11-25 18:44 ` Stephen Hemminger
2022-11-29 1:10 ` patchwork-bot+netdevbpf
2022-11-29 1:10 ` patchwork-bot+netdevbpf
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=20221125104401.0e18979f@hermes.local \
--to=stephen@networkplumber.org \
--cc=alexandre.torgue@foss.st.com \
--cc=claudiu.manoil@nxp.com \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=joabreu@synopsys.com \
--cc=kuba@kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-stm32@st-md-mailman.stormreply.com \
--cc=maciej.fijalkowski@intel.com \
--cc=mcoquelin.stm32@gmail.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=peppe.cavallaro@st.com \
--cc=vladimir.oltean@nxp.com \
--cc=xu.panda@zte.com.cn \
--cc=yang.yang29@zte.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.