All of lore.kernel.org
 help / color / mirror / Atom feed
From: Peter Seiderer <ps.report@gmx.net>
To: Rasmus Villemoes <linux@rasmusvillemoes.dk>
Cc: "Konrad Gräfe" <k.graefe@gateware.de>,
	"Quentin Schulz" <quentin.schulz@theobroma-systems.com>,
	"Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
	"Petr Mladek" <pmladek@suse.com>,
	"Steven Rostedt" <rostedt@goodmis.org>,
	"Sergey Senozhatsky" <senozhatsky@chromium.org>,
	"Andy Shevchenko" <andriy.shevchenko@linux.intel.com>,
	linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org,
	"Kyungmin Park" <kyungmin.park@samsung.com>,
	"Andrzej Pietrasiewicz" <andrzej.p@collabora.com>,
	"Felipe Balbi" <balbi@ti.com>,
	stable@vger.kernel.org
Subject: Re: [PATCH v3 1/2] vsprintf: Add %p[mM]U for uppercase MAC address
Date: Thu, 27 Apr 2023 23:30:10 +0200	[thread overview]
Message-ID: <20230427233010.15f7677d@gmx.net> (raw)
In-Reply-To: <d1a14976-5f53-3373-0695-e10e6a9371de@rasmusvillemoes.dk>

Hello Rasmus, Konrad, *,

On Thu, 27 Apr 2023 14:35:19 +0200, Rasmus Villemoes <linux@rasmusvillemoes.dk> wrote:

> On 27/04/2023 13.51, Konrad Gräfe wrote:
> > The CDC-ECM specification requires an USB gadget to send the host MAC
> > address as uppercase hex string. This change adds the appropriate
> > modifier.
> > 
> > Cc: stable@vger.kernel.org  
> 
> Why cc stable?
> 
> > Signed-off-by: Konrad Gräfe <k.graefe@gateware.de>
> > ---
> > Added in v3
> > 
> >  lib/vsprintf.c | 18 +++++++++++++++---
> >  1 file changed, 15 insertions(+), 3 deletions(-)  
> 
> The diffstat here, or for some other patch in the same series,
> definitely ought to mention lib/test_printf.c.
> 
> > diff --git a/lib/vsprintf.c b/lib/vsprintf.c
> > index be71a03c936a..8aee1caabd9e 100644
> > --- a/lib/vsprintf.c
> > +++ b/lib/vsprintf.c
> > @@ -1269,9 +1269,10 @@ char *mac_address_string(char *buf, char *end, u8 *addr,
> >  {
> >  	char mac_addr[sizeof("xx:xx:xx:xx:xx:xx")];
> >  	char *p = mac_addr;
> > -	int i;
> > +	int i, pos;
> >  	char separator;
> >  	bool reversed = false;
> > +	bool uppercase = false;
> >  
> >  	if (check_pointer(&buf, end, addr, spec))
> >  		return buf;
> > @@ -1281,6 +1282,10 @@ char *mac_address_string(char *buf, char *end, u8 *addr,
> >  		separator = '-';
> >  		break;
> >  
> > +	case 'U':
> > +		uppercase = true;
> > +		break;
> > +
> >  	case 'R':
> >  		reversed = true;
> >  		fallthrough;  
> 
> This seems broken, and I'm surprised the compiler doesn't warn about
> separator possibly being uninitialized further down. I'm also surprised
> your testing hasn't caught this. For reference, the full switch
> statement is currently

Compiler (gcc) does not warn because of Makefile:

  1038 # Enabled with W=2, disabled by default as noisy
  1039 ifdef CONFIG_CC_IS_GCC
  1040 KBUILD_CFLAGS += -Wno-maybe-uninitialized
  1041 endif

With this commented:

  lib/vsprintf.c: In function ‘mac_address_string’:
  lib/vsprintf.c:1310:30: warning: ‘separator’ may be used uninitialized [-Wmaybe-uninitialized]
   1310 |                         *p++ = separator;
        |                         ~~~~~^~~~~~~~~~~
  lib/vsprintf.c:1273:14: note: ‘separator’ was declared here
   1273 |         char separator;
        |              ^~~~~~~~~

Regards,
Peter

> 
>         switch (fmt[1]) {
>         case 'F':
>                 separator = '-';
>                 break;
> 
>         case 'R':
>                 reversed = true;
>                 fallthrough;
> 
>         default:
>                 separator = ':';
>                 break;
>         }
> 
> > @@ -1292,9 +1297,14 @@ char *mac_address_string(char *buf, char *end, u8 *addr,
> >  
> >  	for (i = 0; i < 6; i++) {
> >  		if (reversed)
> > -			p = hex_byte_pack(p, addr[5 - i]);
> > +			pos = 5 - i;
> > +		else
> > +			pos = i;
> > +
> > +		if (uppercase)
> > +			p = hex_byte_pack_upper(p, addr[pos]);
> >  		else
> > -			p = hex_byte_pack(p, addr[i]);
> > +			p = hex_byte_pack(p, addr[pos]);  
> 
> I think this becomes quite hard to follow. We have string_upper() in
> linux/string_helpers.h, so I'd rather just leave this loop alone and do
> 
>   if (uppercase)
>     string_upper(mac_addr, mac_addr);
> 
> after the nul-termination.
> 
> Rasmus
> 


  parent reply	other threads:[~2023-04-27 21:31 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-25 13:15 [PATCH] usb: gadget: u_ether: Fix host MAC address case Konrad Gräfe
2023-04-25 13:37 ` Greg KH
2023-04-26 10:17   ` Konrad Gräfe
2023-04-26 11:49     ` Quentin Schulz
2023-04-26 11:49     ` Greg KH
2023-04-27 11:51       ` [PATCH v3 1/2] vsprintf: Add %p[mM]U for uppercase MAC address Konrad Gräfe
2023-04-27 11:51         ` [PATCH v3 2/2] usb: gadget: u_ether: Fix host MAC address case Konrad Gräfe
2023-04-28  6:49           ` [PATCH v4 1/2] vsprintf: Add %p[mM]U for uppercase MAC address Konrad Gräfe
2023-04-28  6:49             ` [PATCH v4 2/2] usb: gadget: u_ether: Fix host MAC address case Konrad Gräfe
2023-05-02 20:03             ` [PATCH v4 1/2] vsprintf: Add %p[mM]U for uppercase MAC address Andy Shevchenko
2023-05-05 14:36           ` [PATCH v5] usb: gadget: u_ether: Fix host MAC address case Konrad Gräfe
2023-04-27 12:26         ` [PATCH v3 1/2] vsprintf: Add %p[mM]U for uppercase MAC address Greg Kroah-Hartman
2023-04-27 12:35         ` Rasmus Villemoes
2023-04-27 14:26           ` Konrad Gräfe
2023-04-27 21:30           ` Peter Seiderer [this message]
2023-04-28  6:56         ` Rasmus Villemoes
2023-04-28  7:19           ` Greg Kroah-Hartman
2023-04-28  7:46           ` David Laight
2023-05-02 20:01             ` Andy Shevchenko
2023-05-02 12:23           ` Petr Mladek
2023-05-04 13:25             ` Konrad Gräfe

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=20230427233010.15f7677d@gmx.net \
    --to=ps.report@gmx.net \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=andrzej.p@collabora.com \
    --cc=balbi@ti.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=k.graefe@gateware.de \
    --cc=kyungmin.park@samsung.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=linux@rasmusvillemoes.dk \
    --cc=pmladek@suse.com \
    --cc=quentin.schulz@theobroma-systems.com \
    --cc=rostedt@goodmis.org \
    --cc=senozhatsky@chromium.org \
    --cc=stable@vger.kernel.org \
    /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.