From: Simon Horman <simon.horman@corigine.com>
To: Alexandra Winter <wintera@linux.ibm.com>
Cc: David Miller <davem@davemloft.net>,
Jakub Kicinski <kuba@kernel.org>,
netdev@vger.kernel.org, linux-s390@vger.kernel.org,
Heiko Carstens <hca@linux.ibm.com>,
Thorsten Winkler <twinkler@linux.ibm.com>,
Jules Irenge <jbi.octave@gmail.com>
Subject: Re: [PATCH net-next 4/4] s390/qeth: Convert sprintf/snprintf to scnprintf
Date: Thu, 9 Feb 2023 10:38:15 +0100 [thread overview]
Message-ID: <Y+S/B3Q/En1UzrWW@corigine.com> (raw)
In-Reply-To: <045d16d2-fca2-4dbe-e999-05d5365da1ad@linux.ibm.com>
On Wed, Feb 08, 2023 at 07:19:29PM +0100, Alexandra Winter wrote:
>
>
> On 07.02.23 16:42, Simon Horman wrote:
> > On Mon, Feb 06, 2023 at 06:27:54PM +0100, Alexandra Winter wrote:
> >> From: Thorsten Winkler <twinkler@linux.ibm.com>
> >>
> >> This LWN article explains the rationale for this change
> >> https: //lwn.net/Articles/69419/
> >
> > https://lwn.net/Articles/69419/
> >
> >> Ie. snprintf() returns what *would* be the resulting length,
> >> while scnprintf() returns the actual length.
> >
> > Ok, but in most cases in this patch the return value is not checked.
> > Is there any value in this change in those cases?
> >
>
> Jules Irenge reported a coccinnelle warning to use scnprintf in
> show() functions [1]. (Thorsten Winkler changed these instances to
> sysfs_emit in patch 3 of this series.)
> We read the article as a call to implement the plan to upgrade the kernel
> to the newer *scnprintf functions. Is that not intended?
>
> I totally agree, that in these cases no real problem was fixed, it is
> more of a style improvement.
My feeling is that it isn't an improvement and therefore probably
best not done. But that is just my opinion.
> [1] https://lore.kernel.org/netdev/YzHyniCyf+G%2F2xI8@fedora/T/
>
> >> Reported-by: Jules Irenge <jbi.octave@gmail.com>
> >> Reviewed-by: Alexandra Winkler <wintera@linux.ibm.com>
> >
> > s/Winkler/Winter/ ?
>
> Of course. Wow, you have good eyes!
Only on my good days.
> >> Signed-off-by: Thorsten Winkler <twinkler@linux.ibm.com>
> >> Signed-off-by: Alexandra Winter <wintera@linux.ibm.com>
> >
> > ...
> >
> >> diff --git a/drivers/s390/net/qeth_l3_main.c b/drivers/s390/net/qeth_l3_main.c
> >> index 1cf4e354693f..af4e60d2917e 100644
> >> --- a/drivers/s390/net/qeth_l3_main.c
> >> +++ b/drivers/s390/net/qeth_l3_main.c
> >> @@ -47,9 +47,9 @@ int qeth_l3_ipaddr_to_string(enum qeth_prot_versions proto, const u8 *addr,
> >> char *buf)
> >> {
> >> if (proto == QETH_PROT_IPV4)
> >> - return sprintf(buf, "%pI4", addr);
> >> + return scnprintf(buf, INET_ADDRSTRLEN, "%pI4", addr);
> >> else
> >> - return sprintf(buf, "%pI6", addr);
> >> + return scnprintf(buf, INET6_ADDRSTRLEN, "%pI6", addr);
> >> }
> >
> >
> > This seems to be the once case where the return value is not ignored.
> >
> > Of the 4 callers of qeth_l3_ipaddr_to_string, two don't ignore the return
> > value. And I agree in those cases this change seems correct.
> >
> > However, amongst other usages of the return value,
> > those callers also check for a return < 0 from this function.
> > Can that occur, in the sprintf or scnprintf case?
>
> I was under the impression this was a safeguard against a bad address format,
> but I tried it out and it never resulted in a negative return.
> Thanks a lot for pointing this out, we can further simplify patch 3 with that.
The advice elsewhere in this thread is that perhaps leaving this as-is may
be best after all.
* https://lore.kernel.org/netdev/63c6825fc2c94ad19ac7de93a6f151f6@AcuMS.aculab.com/
prev parent reply other threads:[~2023-02-09 9:39 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-02-06 17:27 [PATCH net-next 0/4] s390/net: updates 2023-02-06 Alexandra Winter
2023-02-06 17:27 ` [PATCH net-next 1/4] s390/ctcm: cleanup indenting Alexandra Winter
2023-02-07 15:25 ` Simon Horman
2023-02-06 17:27 ` [PATCH net-next 2/4] s390/qeth: Use constant for IP address buffers Alexandra Winter
2023-02-07 15:26 ` Simon Horman
2023-02-06 17:27 ` [PATCH net-next 3/4] s390/qeth: Convert sysfs sprintf to sysfs_emit Alexandra Winter
2023-02-07 15:37 ` Simon Horman
2023-02-07 16:06 ` Joe Perches
2023-02-08 18:30 ` Alexandra Winter
2023-02-06 17:27 ` [PATCH net-next 4/4] s390/qeth: Convert sprintf/snprintf to scnprintf Alexandra Winter
2023-02-07 15:42 ` Simon Horman
2023-02-08 14:37 ` David Laight
2023-02-08 14:40 ` Simon Horman
2023-02-08 18:19 ` Alexandra Winter
2023-02-09 9:38 ` Simon Horman [this message]
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=Y+S/B3Q/En1UzrWW@corigine.com \
--to=simon.horman@corigine.com \
--cc=davem@davemloft.net \
--cc=hca@linux.ibm.com \
--cc=jbi.octave@gmail.com \
--cc=kuba@kernel.org \
--cc=linux-s390@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=twinkler@linux.ibm.com \
--cc=wintera@linux.ibm.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