netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Alexandra Winter <wintera@linux.ibm.com>
To: Simon Horman <simon.horman@corigine.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: Wed, 8 Feb 2023 19:19:29 +0100	[thread overview]
Message-ID: <045d16d2-fca2-4dbe-e999-05d5365da1ad@linux.ibm.com> (raw)
In-Reply-To: <Y+JxcPOJiRl0qMo1@corigine.com>



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.

[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!

> 
>> 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.

  parent reply	other threads:[~2023-02-08 18:19 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 [this message]
2023-02-09  9:38       ` Simon Horman

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=045d16d2-fca2-4dbe-e999-05d5365da1ad@linux.ibm.com \
    --to=wintera@linux.ibm.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=simon.horman@corigine.com \
    --cc=twinkler@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;
as well as URLs for NNTP newsgroup(s).