From: 'Dmitry Torokhov' <dmitry.torokhov@gmail.com>
To: David Laight <David.Laight@aculab.com>
Cc: Arnd Bergmann <arnd@arndb.de>,
"linux-arch@vger.kernel.org" <linux-arch@vger.kernel.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
Linus Torvalds <torvalds@linux-foundation.org>
Subject: Re: [PATCH] asm-generic: make sparse happy with odd-sized put_unaligned_*()
Date: Mon, 8 Jan 2024 09:45:28 -0800 [thread overview]
Message-ID: <ZZw0uFeUAUnosaK-@google.com> (raw)
In-Reply-To: <12d88da48f6947ab86a845e8d02319ff@AcuMS.aculab.com>
On Mon, Jan 08, 2024 at 11:03:22AM +0000, David Laight wrote:
> From: Dmitry Torokhov
> > Sent: 08 January 2024 06:17
> >
> > __put_unaligned_be24() and friends use implicit casts to convert
> > larger-sized data to bytes, which trips sparse truncation warnings when
> > the argument is a constant:
> >
> > CC [M] drivers/input/touchscreen/hynitron_cstxxx.o
> > CHECK drivers/input/touchscreen/hynitron_cstxxx.c
> > drivers/input/touchscreen/hynitron_cstxxx.c: note: in included file (through
> > arch/x86/include/generated/asm/unaligned.h):
> > ./include/asm-generic/unaligned.h:119:16: warning: cast truncates bits from constant value (aa01a0
> > becomes a0)
> > ./include/asm-generic/unaligned.h:120:20: warning: cast truncates bits from constant value (aa01
> > becomes 1)
> > ./include/asm-generic/unaligned.h:119:16: warning: cast truncates bits from constant value (ab00d0
> > becomes d0)
> > ./include/asm-generic/unaligned.h:120:20: warning: cast truncates bits from constant value (ab00
> > becomes 0)
> >
> > To avoid this let's mask off upper bits explicitly, the resulting code
> > should be exactly the same, but it will keep sparse happy.
>
> Maybe someone should fix sparse?
I proposed doing this in
https://lore.kernel.org/oe-kbuild-all/ZZnzd3s2L-ZwGOlz@google.com/ but
the idea was not welcome.
> I have seen a compiler generate two explicit masks with 0xff
> followed by a byte write for:
> *p = (char)(x & 0xff);
> but I expect modern gcc is ok.
>
> > Reported-by: kernel test robot <lkp@intel.com>
> > Suggested-by: Linus Torvalds <torvalds@linux-foundation.org>
> > Closes: https://lore.kernel.org/oe-kbuild-all/202401070147.gqwVulOn-lkp@intel.com/
> > Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
> > ---
> > include/asm-generic/unaligned.h | 24 ++++++++++++------------
> > 1 file changed, 12 insertions(+), 12 deletions(-)
> >
> > diff --git a/include/asm-generic/unaligned.h b/include/asm-generic/unaligned.h
> > index 699650f81970..a84c64e5f11e 100644
> > --- a/include/asm-generic/unaligned.h
> > +++ b/include/asm-generic/unaligned.h
> > @@ -104,9 +104,9 @@ static inline u32 get_unaligned_le24(const void *p)
> >
> > static inline void __put_unaligned_be24(const u32 val, u8 *p)
> > {
> > - *p++ = val >> 16;
> > - *p++ = val >> 8;
> > - *p++ = val;
> > + *p++ = (val >> 16) & 0xff;
> > + *p++ = (val >> 8) & 0xff;
> > + *p++ = val & 0xff;
> > }
>
> What happens if you implement the as (eg):
> *p = val >> 16;
> put_unaligned_be16(p + 1, val);
> I think that should generate better code.
> And it may stop sparse bleating.
This is rarely in a hot path (typically you do this with a "slow"
device), and while being faster it looks more complex. But if that's
what people prefer...
Thanks.
--
Dmitry
prev parent reply other threads:[~2024-01-08 17:45 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-01-08 6:16 [PATCH] asm-generic: make sparse happy with odd-sized put_unaligned_*() Dmitry Torokhov
2024-01-08 11:03 ` David Laight
2024-01-08 17:45 ` 'Dmitry Torokhov' [this message]
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=ZZw0uFeUAUnosaK-@google.com \
--to=dmitry.torokhov@gmail.com \
--cc=David.Laight@aculab.com \
--cc=arnd@arndb.de \
--cc=linux-arch@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=torvalds@linux-foundation.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox