All of lore.kernel.org
 help / color / mirror / Atom feed
From: David Laight <David.Laight@ACULAB.COM>
To: 'Nick Desaulniers' <ndesaulniers@google.com>,
	Al Viro <viro@zeniv.linux.org.uk>
Cc: Andrew Morton <akpm@linux-foundation.org>,
	Justin Stitt <jstitt007@gmail.com>,
	Nathan Chancellor <nathan@kernel.org>, Tom Rix <trix@redhat.com>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"llvm@lists.linux.dev" <llvm@lists.linux.dev>,
	Richard Smith <richardsmith@google.com>
Subject: RE: [PATCH] include/uapi/linux/swab.h: add __u16 cast to __swab16 conditional
Date: Fri, 10 Jun 2022 07:19:38 +0000	[thread overview]
Message-ID: <ef8069e60f7a4e23a26dcbedd0bc77d7@AcuMS.aculab.com> (raw)
In-Reply-To: <CAKwvOdnSSY0jexXioDTZOWSTi0fkaudZbgSjigPr5uzTRmA_Rg@mail.gmail.com>

From: Nick Desaulniers
> Sent: 08 June 2022 20:35
....
> The issue we're facing is more so that `ntohs` is being used in
> printf-like expressions; clang's -Wformat warns about default argument
> promotion so we need to clean up cases where smaller-than-int format
> flags are being used for promoted-to-int params.  While looking at
> that, Nathan noticed that __swab16 will return either a __u16 or an
> int based on whether __HAVE_BUILTIN_BSWAP16__ is defined, which
> depends on BOTH the compiler being used and target architecture.  This
> patch from Justin just cleans that up.

The 'problem' is that the (__u16) cast is likely to add an
extra '& 0xffff' instruction that is almost certainly not
required.

OTOH the lack of this masking has always been a difference between
htons() on BE and LE systems.

But clang is also being over-enthusiastic with its warnings.
IIRC varargs parameters always get integer promotion.
So if %hd ever makes sense for printf then it implies a
mask inside printf.

	David

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)

  reply	other threads:[~2022-06-10  7:19 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-07 22:20 [PATCH] include/uapi/linux/swab.h: add __u16 cast to __swab16 conditional Justin Stitt
2022-06-07 22:27 ` Andrew Morton
2022-06-07 22:42   ` Nick Desaulniers
2022-06-07 23:21     ` Andrew Morton
2022-06-07 23:43       ` Nick Desaulniers
2022-06-08  4:54       ` Al Viro
2022-06-08 19:35         ` Nick Desaulniers
2022-06-10  7:19           ` David Laight [this message]
2022-06-07 23:20 ` Nick Desaulniers
2022-06-08  0:14   ` [PATCH v2] include/uapi/linux/swab.h: move explicit cast outside ternary Justin Stitt
2022-06-08 20:09     ` Andrew Morton
2022-06-08 21:16       ` Nick Desaulniers
2022-06-08 21:19     ` Nick Desaulniers

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=ef8069e60f7a4e23a26dcbedd0bc77d7@AcuMS.aculab.com \
    --to=david.laight@aculab.com \
    --cc=akpm@linux-foundation.org \
    --cc=jstitt007@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=llvm@lists.linux.dev \
    --cc=nathan@kernel.org \
    --cc=ndesaulniers@google.com \
    --cc=richardsmith@google.com \
    --cc=trix@redhat.com \
    --cc=viro@zeniv.linux.org.uk \
    /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.