From: Thomas Zimmermann <tzimmermann@suse.de>
To: "José Expósito" <jose.exposito89@gmail.com>,
rodrigosiqueiramelo@gmail.com
Cc: melissa.srw@gmail.com, mairacanal@riseup.net,
hamohammed.sa@gmail.com, daniel@ffwll.ch,
maarten.lankhorst@linux.intel.com, mripard@kernel.org,
airlied@gmail.com, dri-devel@lists.freedesktop.org,
linux-kernel@vger.kernel.org, louis.chauvet@bootlin.com
Subject: Re: [PATCH v2] drm/vkms: Fix cpu_to_le16()/le16_to_cpu() warnings
Date: Mon, 15 Jul 2024 17:38:03 +0200 [thread overview]
Message-ID: <aa140df8-efc0-49f0-9c65-64bee7cc437e@suse.de> (raw)
In-Reply-To: <20240715151625.6968-2-jose.exposito89@gmail.com>
Hi
Am 15.07.24 um 17:16 schrieb José Expósito:
> Building with Sparse enabled prints this warning for cpu_to_le16()
> calls:
>
> warning: incorrect type in assignment (different base types)
> expected unsigned short [usertype]
> got restricted __le16 [usertype]
>
> And this warning for le16_to_cpu() calls:
>
> warning: cast to restricted __le16
>
> Declare the target buffer as __le16 to fix both warnings.
>
> Signed-off-by: José Expósito <jose.exposito89@gmail.com>
>
> ---
>
> v1 -> v2: https://lore.kernel.org/dri-devel/20240712161656.7480-1-jose.exposito89@gmail.com/T/
>
> - Thomas Zimmermann: Declare "pixels" cariable as __le16 instead of
> multiple casting.
> ---
> drivers/gpu/drm/vkms/vkms_formats.c | 14 +++++++-------
> 1 file changed, 7 insertions(+), 7 deletions(-)
>
> diff --git a/drivers/gpu/drm/vkms/vkms_formats.c b/drivers/gpu/drm/vkms/vkms_formats.c
> index 36046b12f296..1ff535222bd4 100644
> --- a/drivers/gpu/drm/vkms/vkms_formats.c
> +++ b/drivers/gpu/drm/vkms/vkms_formats.c
> @@ -75,7 +75,7 @@ static void XRGB8888_to_argb_u16(u8 *src_pixels, struct pixel_argb_u16 *out_pixe
>
> static void ARGB16161616_to_argb_u16(u8 *src_pixels, struct pixel_argb_u16 *out_pixel)
> {
> - u16 *pixels = (u16 *)src_pixels;
> + __le16 *pixels = (__force __le16 *)src_pixels;
>
> out_pixel->a = le16_to_cpu(pixels[3]);
> out_pixel->r = le16_to_cpu(pixels[2]);
> @@ -85,7 +85,7 @@ static void ARGB16161616_to_argb_u16(u8 *src_pixels, struct pixel_argb_u16 *out_
>
> static void XRGB16161616_to_argb_u16(u8 *src_pixels, struct pixel_argb_u16 *out_pixel)
> {
> - u16 *pixels = (u16 *)src_pixels;
> + __le16 *pixels = (__force __le16 *)src_pixels;
>
> out_pixel->a = (u16)0xffff;
> out_pixel->r = le16_to_cpu(pixels[2]);
> @@ -95,7 +95,7 @@ static void XRGB16161616_to_argb_u16(u8 *src_pixels, struct pixel_argb_u16 *out_
>
> static void RGB565_to_argb_u16(u8 *src_pixels, struct pixel_argb_u16 *out_pixel)
> {
> - u16 *pixels = (u16 *)src_pixels;
> + __le16 *pixels = (__force __le16 *)src_pixels;
>
> s64 fp_rb_ratio = drm_fixp_div(drm_int2fixp(65535), drm_int2fixp(31));
> s64 fp_g_ratio = drm_fixp_div(drm_int2fixp(65535), drm_int2fixp(63));
> @@ -178,7 +178,7 @@ static void argb_u16_to_XRGB8888(u8 *dst_pixels, struct pixel_argb_u16 *in_pixel
>
> static void argb_u16_to_ARGB16161616(u8 *dst_pixels, struct pixel_argb_u16 *in_pixel)
> {
> - u16 *pixels = (u16 *)dst_pixels;
> + __le16 *pixels = (__force __le16 *)dst_pixels;
>
> pixels[3] = cpu_to_le16(in_pixel->a);
> pixels[2] = cpu_to_le16(in_pixel->r);
> @@ -188,9 +188,9 @@ static void argb_u16_to_ARGB16161616(u8 *dst_pixels, struct pixel_argb_u16 *in_p
>
> static void argb_u16_to_XRGB16161616(u8 *dst_pixels, struct pixel_argb_u16 *in_pixel)
> {
> - u16 *pixels = (u16 *)dst_pixels;
> + __le16 *pixels = (__force __le16 *)dst_pixels;
>
> - pixels[3] = 0xffff;
> + pixels[3] = (__force __le16)0xffff;
I'd use cpu_to_le16() even on the constant. It makes it clear what is
happening, makes __le16 opaque, and avoids the ugly cast.
In any case
Reviewed-by: Thomas Zimmermann <tzimmermann@suse.de>
Best regards
Thomas
> pixels[2] = cpu_to_le16(in_pixel->r);
> pixels[1] = cpu_to_le16(in_pixel->g);
> pixels[0] = cpu_to_le16(in_pixel->b);
> @@ -198,7 +198,7 @@ static void argb_u16_to_XRGB16161616(u8 *dst_pixels, struct pixel_argb_u16 *in_p
>
> static void argb_u16_to_RGB565(u8 *dst_pixels, struct pixel_argb_u16 *in_pixel)
> {
> - u16 *pixels = (u16 *)dst_pixels;
> + __le16 *pixels = (__force __le16 *)dst_pixels;
>
> s64 fp_rb_ratio = drm_fixp_div(drm_int2fixp(65535), drm_int2fixp(31));
> s64 fp_g_ratio = drm_fixp_div(drm_int2fixp(65535), drm_int2fixp(63));
--
--
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Frankenstrasse 146, 90461 Nuernberg, Germany
GF: Ivo Totev, Andrew Myers, Andrew McDonald, Boudien Moerman
HRB 36809 (AG Nuernberg)
next prev parent reply other threads:[~2024-07-15 15:38 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-07-15 15:16 José Expósito
2024-07-15 15:38 ` Thomas Zimmermann [this message]
2024-07-16 9:25 ` Louis Chauvet
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=aa140df8-efc0-49f0-9c65-64bee7cc437e@suse.de \
--to=tzimmermann@suse.de \
--cc=airlied@gmail.com \
--cc=daniel@ffwll.ch \
--cc=dri-devel@lists.freedesktop.org \
--cc=hamohammed.sa@gmail.com \
--cc=jose.exposito89@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=louis.chauvet@bootlin.com \
--cc=maarten.lankhorst@linux.intel.com \
--cc=mairacanal@riseup.net \
--cc=melissa.srw@gmail.com \
--cc=mripard@kernel.org \
--cc=rodrigosiqueiramelo@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
all inboxes | Powered by JetHome®