linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Joe Perches <joe@perches.com>
To: Andy Shevchenko <andy.shevchenko@gmail.com>
Cc: "Jonathan Cameron" <jic23@kernel.org>,
	"Nathan Chancellor" <nathan@kernel.org>,
	"Arnd Bergmann" <arnd@kernel.org>,
	"Nick Desaulniers" <ndesaulniers@google.com>,
	"Maxime Roussin-Bélanger" <maxime.roussinbelanger@gmail.com>,
	"Jean-Francois Dagenais" <jeff.dagenais@gmail.com>,
	"Arnd Bergmann" <arnd@arndb.de>,
	"Lars-Peter Clausen" <lars@metafoo.de>,
	"Alexandru Ardelean" <alexandru.ardelean@analog.com>,
	"linux-iio@vger.kernel.org" <linux-iio@vger.kernel.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"clang-built-linux@googlegroups.com"
	<clang-built-linux@googlegroups.com>
Subject: Re: [PATCH] iio: si1133: fix format string warnings
Date: Fri, 28 May 2021 14:10:04 -0700	[thread overview]
Message-ID: <fc3afc8e74ee9eda0b4eaff9a4d9ad32f1c461c4.camel@perches.com> (raw)
In-Reply-To: <CAHp75Vc72vMbj311P3xnxh6ExxzD1=enoETj6wY8dHn+xBJ4+w@mail.gmail.com>

On Fri, 2021-05-28 at 23:59 +0300, Andy Shevchenko wrote:
> On Thursday, May 27, 2021, Joe Perches <joe@perches.com> wrote:
> > On Sun, 2021-05-16 at 10:36 +0100, Jonathan Cameron wrote:
> > > On Fri, 14 May 2021 10:45:02 -0700
> > > Nathan Chancellor <nathan@kernel.org> wrote:
> > > > On 5/14/2021 6:59 AM, Arnd Bergmann wrote:
> > > > > From: Arnd Bergmann <arnd@arndb.de>
> > > > > 
> > > > > clang complains about multiple instances of printing an integer
> > > > > using the %hhx format string:
> > > > > 
> > > > > drivers/iio/light/si1133.c:982:4: error: format specifies type
> > 'unsigned char' but the argument has type 'unsigned int' [-Werror,-Wformat]
> > > > >                   part_id, rev_id, mfr_id);
> > > > >                   ^~~~~~~
> > > > > 
> > > > > Print them as a normal integer instead, leaving the "#02"
> > > > > length modifier.
> > []
> > > > > diff --git a/drivers/iio/light/si1133.c b/drivers/iio/light/si1133.c
> > []
> > > > > @@ -978,11 +978,11 @@ static int si1133_validate_ids(struct iio_dev
> > *iio_dev)
> > > > >                   return err;
> > > > > 
> > > > > 
> > > > >           dev_info(&iio_dev->dev,
> > > > > -          "Device ID part %#02hhx rev %#02hhx mfr %#02hhx\n",
> > > > > +          "Device ID part %#02x rev %#02x mfr %#02x\n",
> > > > >                    part_id, rev_id, mfr_id);
> > > > >           if (part_id != SI1133_PART_ID) {
> > > > >                   dev_err(&iio_dev->dev,
> > > > > -                 "Part ID mismatch got %#02hhx, expected %#02x\n",
> > > > > +                 "Part ID mismatch got %#02x, expected %#02x\n",
> > 
> > which is almost certainly wrong.
> > the length specification includes the # which is already 2 bytes.
> > 
> > Likely these should be 0x%02x
> 
> What’s the difference (except printing 0)?

(assuming the argument is unsigned char/u8)

%#02x will always emit more than the specified length (3 or 4 chars)
values < 16 are 0x<hexdigit>, values >= 16 are 0x<hexdigit><hexdigit>

0x%02x will always emit 4 chars

It's very likely the writer didn't know the difference and assumed
that the # did not count in the specified width.



  parent reply	other threads:[~2021-05-28 21:10 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-14 13:59 [PATCH] iio: si1133: fix format string warnings Arnd Bergmann
2021-05-14 17:45 ` Nathan Chancellor
2021-05-16  9:36   ` Jonathan Cameron
2021-05-27 16:17     ` Joe Perches
     [not found]       ` <CAHp75Vc72vMbj311P3xnxh6ExxzD1=enoETj6wY8dHn+xBJ4+w@mail.gmail.com>
2021-05-28 21:10         ` Joe Perches [this message]
     [not found]           ` <CAHp75VeQdFoJrPhXU2fYdrhLUwvM4NEoPn=Z4WBPkhOa4xK+ig@mail.gmail.com>
2021-05-28 21:35             ` Joe Perches
2021-05-29  7:52               ` Andy Shevchenko

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=fc3afc8e74ee9eda0b4eaff9a4d9ad32f1c461c4.camel@perches.com \
    --to=joe@perches.com \
    --cc=alexandru.ardelean@analog.com \
    --cc=andy.shevchenko@gmail.com \
    --cc=arnd@arndb.de \
    --cc=arnd@kernel.org \
    --cc=clang-built-linux@googlegroups.com \
    --cc=jeff.dagenais@gmail.com \
    --cc=jic23@kernel.org \
    --cc=lars@metafoo.de \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=maxime.roussinbelanger@gmail.com \
    --cc=nathan@kernel.org \
    --cc=ndesaulniers@google.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).