From: Nathan Chancellor <nathan@kernel.org>
To: Arnd Bergmann <arnd@kernel.org>,
Maximilian Luz <luzmaximilian@gmail.com>,
Hans de Goede <hdegoede@redhat.com>
Cc: Arnd Bergmann <arnd@arndb.de>,
platform-driver-x86@vger.kernel.org,
Nick Desaulniers <ndesaulniers@google.com>,
linux-kernel@vger.kernel.org, clang-built-linux@googlegroups.com
Subject: Re: [PATCH] [v2] platform/surface: aggregator: avoid clang -Wconstant-conversion warning
Date: Fri, 14 May 2021 14:22:53 -0700 [thread overview]
Message-ID: <057b5568-c4b8-820c-3dd7-2200f61a4d58@kernel.org> (raw)
In-Reply-To: <20210514200453.1542978-1-arnd@kernel.org>
On 5/14/2021 1:04 PM, Arnd Bergmann wrote:
> From: Arnd Bergmann <arnd@arndb.de>
>
> Clang complains about the assignment of SSAM_ANY_IID to
> ssam_device_uid->instance:
>
> drivers/platform/surface/surface_aggregator_registry.c:478:25: error: implicit conversion from 'int' to '__u8' (aka 'unsigned char') changes value from 65535 to 255 [-Werror,-Wconstant-conversion]
> { SSAM_VDEV(HUB, 0x02, SSAM_ANY_IID, 0x00) },
> ~ ^~~~~~~~~~~~
> include/linux/surface_aggregator/device.h:71:23: note: expanded from macro 'SSAM_ANY_IID'
> #define SSAM_ANY_IID 0xffff
> ^~~~~~
> include/linux/surface_aggregator/device.h:126:63: note: expanded from macro 'SSAM_VDEV'
> SSAM_DEVICE(SSAM_DOMAIN_VIRTUAL, SSAM_VIRTUAL_TC_##cat, tid, iid, fun)
> ^~~
> include/linux/surface_aggregator/device.h:102:41: note: expanded from macro 'SSAM_DEVICE'
> .instance = ((iid) != SSAM_ANY_IID) ? (iid) : 0, \
> ^~~
>
> The assignment doesn't actually happen, but clang checks the type limits
> before checking whether this assignment is reached. Replace the ?:
> operator with a __builtin_choose_expr() invocation that avoids the
> warning for the untaken part.
>
> Fixes: eb0e90a82098 ("platform/surface: aggregator: Add dedicated bus and device type")
> Cc: platform-driver-x86@vger.kernel.org
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Reviewed-by: Nathan Chancellor <nathan@kernel.org>
> ---
> v2: use __builtin_choose_expr() instead of a cast to shut up the warning
> ---
> include/linux/surface_aggregator/device.h | 6 +++---
> 1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/include/linux/surface_aggregator/device.h b/include/linux/surface_aggregator/device.h
> index 4441ad667c3f..6ff9c58b3e17 100644
> --- a/include/linux/surface_aggregator/device.h
> +++ b/include/linux/surface_aggregator/device.h
> @@ -98,9 +98,9 @@ struct ssam_device_uid {
> | (((fun) != SSAM_ANY_FUN) ? SSAM_MATCH_FUNCTION : 0), \
> .domain = d, \
> .category = cat, \
> - .target = ((tid) != SSAM_ANY_TID) ? (tid) : 0, \
> - .instance = ((iid) != SSAM_ANY_IID) ? (iid) : 0, \
> - .function = ((fun) != SSAM_ANY_FUN) ? (fun) : 0 \
> + .target = __builtin_choose_expr((tid) != SSAM_ANY_TID, (tid), 0), \
> + .instance = __builtin_choose_expr((iid) != SSAM_ANY_IID, (iid), 0), \
> + .function = __builtin_choose_expr((fun) != SSAM_ANY_FUN, (fun), 0)
>
> /**
> * SSAM_VDEV() - Initialize a &struct ssam_device_id as virtual device with
>
next prev parent reply other threads:[~2021-05-14 21:23 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-05-14 20:04 [PATCH] [v2] platform/surface: aggregator: avoid clang -Wconstant-conversion warning Arnd Bergmann
2021-05-14 21:22 ` Nathan Chancellor [this message]
2021-05-17 8:31 ` David Laight
2021-05-17 12:40 ` Maximilian Luz
2021-05-14 21:56 ` Maximilian Luz
2021-05-19 13:12 ` Hans de Goede
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=057b5568-c4b8-820c-3dd7-2200f61a4d58@kernel.org \
--to=nathan@kernel.org \
--cc=arnd@arndb.de \
--cc=arnd@kernel.org \
--cc=clang-built-linux@googlegroups.com \
--cc=hdegoede@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=luzmaximilian@gmail.com \
--cc=ndesaulniers@google.com \
--cc=platform-driver-x86@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 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).