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@xxxxxxxxxxxxx> > >> > >> 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@xxxxxxxxx> > >> Reviewed-by: Alexandra Winkler <wintera@xxxxxxxxxxxxx> > > > > s/Winkler/Winter/ ? > > Of course. Wow, you have good eyes! Only on my good days. > >> Signed-off-by: Thorsten Winkler <twinkler@xxxxxxxxxxxxx> > >> Signed-off-by: Alexandra Winter <wintera@xxxxxxxxxxxxx> > > > > ... > > > >> 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@xxxxxxxxxxxxxxxx/