From: Dan Carpenter <dan.carpenter@oracle.com>
To: Joe Perches <joe@perches.com>
Cc: Michael Zaidman <michael.zaidman@gmail.com>,
lkp@intel.com, kbuild-all@lists.01.org,
clang-built-linux@googlegroups.com, linux-kernel@vger.kernel.org,
jikos@kernel.org, linux-input@vger.kernel.org
Subject: Re: [PATCH] HID: ft260: fix format type warning in ft260_word_show()
Date: Mon, 10 May 2021 13:22:46 +0300 [thread overview]
Message-ID: <20210510102246.GR1922@kadam> (raw)
In-Reply-To: <20210510101551.GQ1922@kadam>
On Mon, May 10, 2021 at 01:15:51PM +0300, Dan Carpenter wrote:
> On Mon, May 10, 2021 at 02:52:14AM -0700, Joe Perches wrote:
> > On Mon, 2021-05-10 at 12:17 +0300, Michael Zaidman wrote:
> > > On Sun, May 09, 2021 at 01:39:29PM -0700, Joe Perches wrote:
> > > > On Sun, 2021-05-09 at 22:32 +0300, Michael Zaidman wrote:
> > > > > Fixes: 6a82582d9fa4 ("HID: ft260: add usb hid to i2c host bridge driver")
> > > > >
> > > > > Fix warning reported by static analysis when built with W=1 for arm64 by
> > > > > clang version 13.0.0
> > > > >
> > > > > > > drivers/hid/hid-ft260.c:794:44: warning: format specifies type 'short' but
> > > > > the argument has type 'int' [-Wformat]
> > > > > return scnprintf(buf, PAGE_SIZE, "%hi\n", le16_to_cpu(*field));
> > > > > ~~~ ^~~~~~~~~~~~~~~~~~~
> > > > > %i
> > > > > include/linux/byteorder/generic.h:91:21: note: expanded from
> > > > > macro 'le16_to_cpu'
> > > > > #define le16_to_cpu __le16_to_cpu
> > > > > ^
> > > > > include/uapi/linux/byteorder/big_endian.h:36:26: note: expanded from
> > > > > macro '__le16_to_cpu'
> > > > > #define __le16_to_cpu(x) __swab16((__force __u16)(__le16)(x))
> > > > > ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> > > > > include/uapi/linux/swab.h:105:2: note: expanded from macro '__swab16'
> > > > > (__builtin_constant_p((__u16)(x)) ? \
> > > > > ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> > > > >
> > > > > Signed-off-by: Michael Zaidman <michael.zaidman@gmail.com>
> > > > > Reported-by: kernel test robot <lkp@intel.com>
> > > > > ---
> > > > > drivers/hid/hid-ft260.c | 2 +-
> > > > > 1 file changed, 1 insertion(+), 1 deletion(-)
> > > > >
> > > > > diff --git a/drivers/hid/hid-ft260.c b/drivers/hid/hid-ft260.c
> > > > > index 047aa85a7c83..38794a29599c 100644
> > > > > --- a/drivers/hid/hid-ft260.c
> > > > > +++ b/drivers/hid/hid-ft260.c
> > > > > @@ -791,7 +791,7 @@ static int ft260_word_show(struct hid_device *hdev, int id, u8 *cfg, int len,
> > > > > if (ret != len && ret >= 0)
> > > > > return -EIO;
> > > > >
> > > > >
> > > > > - return scnprintf(buf, PAGE_SIZE, "%hi\n", le16_to_cpu(*field));
> > > > > + return scnprintf(buf, PAGE_SIZE, "%d\n", le16_to_cpu(*field));
> > > > > }
> > > >
> > > > There are 2 of these so I wonder about the static analysis.
> > >
> > > There is nothing wrong with the static analysis. The first scnprintf format
> > > type is perfectly valid as far as its size is greater than the size of the
> > > data pointed by the *field pointer, which is a one byte size in our case.
> > > The static analysis warned about the second scnprintf case, where the format
> > > type was shorter than the integer returned by the __builtin_constant_p.
> > > This warning can be considered as a false positive since the le16_to_cpu is
> > > all about the 16 bits numbers, but to silence it, I submitted the above fix.
> >
> > $ git grep __arch_swab16 arch/arm*/
> > arch/arm/include/asm/swab.h:#define __arch_swab16(x) ((__u16)__arch_swahb32(x))
> >
> > otherwise:
> >
> > static inline __attribute_const__ __u16 __fswab16(__u16 val)
> > {
> > #if defined (__arch_swab16)
> > return __arch_swab16(val);
> > #else
> > return ___constant_swab16(val);
> > #endif
> > }
> >
> > #define ___constant_swab16(x) ((__u16)( \
> > (((__u16)(x) & (__u16)0x00ffU) << 8) | \
> > (((__u16)(x) & (__u16)0xff00U) >> 8)))
> >
> > /**
> > * __swab16 - return a byteswapped 16-bit value
> > * @x: value to byteswap
> > */
> > #ifdef __HAVE_BUILTIN_BSWAP16__
> > #define __swab16(x) (__u16)__builtin_bswap16((__u16)(x))
> > #else
> > #define __swab16(x) \
> > (__builtin_constant_p((__u16)(x)) ? \
> > ___constant_swab16(x) : \
> > __fswab16(x))
> > #endif
> >
> > Under what condition does the ?: return an int sized value
> > rather than a u16 sized value? I fail to see a path where
> > the compiler should promote the returned value to int _before_
> > the promotion done for the varargs use.
> >
> > If it's for the varargs use, then both instances are promoted.
> >
>
> Ternary type promotion is a horrible thing.
>
> foo = a ? b : c;
>
> Everything is type promoted which ever of a, b or c has the most
> positive bits. Or if none of them have 31 positive bits it's
> type promoted to int.
Oops. Sorry, I'm not thinking straight. "a" doesn't affect the type
promotion, but it would if you had:
foo = a ?: c;
regards,
dan carpenter
next prev parent reply other threads:[~2021-05-10 10:23 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <202105060637.LeEC6ztp-lkp@intel.com>
2021-05-09 19:32 ` [PATCH] HID: ft260: fix format type warning in ft260_word_show() Michael Zaidman
2021-05-09 20:39 ` Joe Perches
2021-05-10 9:17 ` Michael Zaidman
2021-05-10 9:52 ` Joe Perches
2021-05-10 10:15 ` Dan Carpenter
2021-05-10 10:22 ` Dan Carpenter [this message]
2021-05-10 12:51 ` Michael Zaidman
2021-05-10 16:30 ` [PATCH v2] " Michael Zaidman
2021-05-10 16:41 ` Joe Perches
2021-05-10 16:34 ` [PATCH v3] " Michael Zaidman
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=20210510102246.GR1922@kadam \
--to=dan.carpenter@oracle.com \
--cc=clang-built-linux@googlegroups.com \
--cc=jikos@kernel.org \
--cc=joe@perches.com \
--cc=kbuild-all@lists.01.org \
--cc=linux-input@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=lkp@intel.com \
--cc=michael.zaidman@gmail.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).