diff mbox series

drm/vkms: Fix cpu_to_le16()/le16_to_cpu() warnings

Message ID 20240712161656.7480-1-jose.exposito89@gmail.com (mailing list archive)
State New, archived
Headers show
Series drm/vkms: Fix cpu_to_le16()/le16_to_cpu() warnings | expand

Commit Message

José Expósito July 12, 2024, 4:16 p.m. UTC
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

Add casts to fix both warnings.

Signed-off-by: José Expósito <jose.exposito89@gmail.com>
---
 drivers/gpu/drm/vkms/vkms_formats.c | 32 ++++++++++++++---------------
 1 file changed, 16 insertions(+), 16 deletions(-)

Comments

Thomas Zimmermann July 14, 2024, 7:41 p.m. UTC | #1
Hi

Am 12.07.24 um 18: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
>
> Add casts to fix both warnings.
>
> Signed-off-by: José Expósito <jose.exposito89@gmail.com>
> ---
>   drivers/gpu/drm/vkms/vkms_formats.c | 32 ++++++++++++++---------------
>   1 file changed, 16 insertions(+), 16 deletions(-)
>
> diff --git a/drivers/gpu/drm/vkms/vkms_formats.c b/drivers/gpu/drm/vkms/vkms_formats.c
> index 36046b12f296..053fa6ce41a9 100644
> --- a/drivers/gpu/drm/vkms/vkms_formats.c
> +++ b/drivers/gpu/drm/vkms/vkms_formats.c
> @@ -77,10 +77,10 @@ static void ARGB16161616_to_argb_u16(u8 *src_pixels, struct pixel_argb_u16 *out_
>   {
>   	u16 *pixels = (u16 *)src_pixels;

You should rather declare pixels as __le16 pointer. Same for the other 
changes. See [1] for an example.

Best regards
Thomas

[1] 
https://elixir.bootlin.com/linux/v6.9/source/drivers/gpu/drm/drm_format_helper.c#L420

>   
> -	out_pixel->a = le16_to_cpu(pixels[3]);
> -	out_pixel->r = le16_to_cpu(pixels[2]);
> -	out_pixel->g = le16_to_cpu(pixels[1]);
> -	out_pixel->b = le16_to_cpu(pixels[0]);
> +	out_pixel->a = le16_to_cpu((__force __le16)pixels[3]);
> +	out_pixel->r = le16_to_cpu((__force __le16)pixels[2]);
> +	out_pixel->g = le16_to_cpu((__force __le16)pixels[1]);
> +	out_pixel->b = le16_to_cpu((__force __le16)pixels[0]);
>   }
>   
>   static void XRGB16161616_to_argb_u16(u8 *src_pixels, struct pixel_argb_u16 *out_pixel)
> @@ -88,9 +88,9 @@ static void XRGB16161616_to_argb_u16(u8 *src_pixels, struct pixel_argb_u16 *out_
>   	u16 *pixels = (u16 *)src_pixels;
>   
>   	out_pixel->a = (u16)0xffff;
> -	out_pixel->r = le16_to_cpu(pixels[2]);
> -	out_pixel->g = le16_to_cpu(pixels[1]);
> -	out_pixel->b = le16_to_cpu(pixels[0]);
> +	out_pixel->r = le16_to_cpu((__force __le16)pixels[2]);
> +	out_pixel->g = le16_to_cpu((__force __le16)pixels[1]);
> +	out_pixel->b = le16_to_cpu((__force __le16)pixels[0]);
>   }
>   
>   static void RGB565_to_argb_u16(u8 *src_pixels, struct pixel_argb_u16 *out_pixel)
> @@ -100,7 +100,7 @@ static void RGB565_to_argb_u16(u8 *src_pixels, struct pixel_argb_u16 *out_pixel)
>   	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));
>   
> -	u16 rgb_565 = le16_to_cpu(*pixels);
> +	u16 rgb_565 = le16_to_cpu((__force __le16)*pixels);
>   	s64 fp_r = drm_int2fixp((rgb_565 >> 11) & 0x1f);
>   	s64 fp_g = drm_int2fixp((rgb_565 >> 5) & 0x3f);
>   	s64 fp_b = drm_int2fixp(rgb_565 & 0x1f);
> @@ -180,10 +180,10 @@ static void argb_u16_to_ARGB16161616(u8 *dst_pixels, struct pixel_argb_u16 *in_p
>   {
>   	u16 *pixels = (u16 *)dst_pixels;
>   
> -	pixels[3] = cpu_to_le16(in_pixel->a);
> -	pixels[2] = cpu_to_le16(in_pixel->r);
> -	pixels[1] = cpu_to_le16(in_pixel->g);
> -	pixels[0] = cpu_to_le16(in_pixel->b);
> +	pixels[3] = (__force u16)cpu_to_le16(in_pixel->a);
> +	pixels[2] = (__force u16)cpu_to_le16(in_pixel->r);
> +	pixels[1] = (__force u16)cpu_to_le16(in_pixel->g);
> +	pixels[0] = (__force u16)cpu_to_le16(in_pixel->b);
>   }
>   
>   static void argb_u16_to_XRGB16161616(u8 *dst_pixels, struct pixel_argb_u16 *in_pixel)
> @@ -191,9 +191,9 @@ static void argb_u16_to_XRGB16161616(u8 *dst_pixels, struct pixel_argb_u16 *in_p
>   	u16 *pixels = (u16 *)dst_pixels;
>   
>   	pixels[3] = 0xffff;
> -	pixels[2] = cpu_to_le16(in_pixel->r);
> -	pixels[1] = cpu_to_le16(in_pixel->g);
> -	pixels[0] = cpu_to_le16(in_pixel->b);
> +	pixels[2] = (__force u16)cpu_to_le16(in_pixel->r);
> +	pixels[1] = (__force u16)cpu_to_le16(in_pixel->g);
> +	pixels[0] = (__force u16)cpu_to_le16(in_pixel->b);
>   }
>   
>   static void argb_u16_to_RGB565(u8 *dst_pixels, struct pixel_argb_u16 *in_pixel)
> @@ -211,7 +211,7 @@ static void argb_u16_to_RGB565(u8 *dst_pixels, struct pixel_argb_u16 *in_pixel)
>   	u16 g = drm_fixp2int(drm_fixp_div(fp_g, fp_g_ratio));
>   	u16 b = drm_fixp2int(drm_fixp_div(fp_b, fp_rb_ratio));
>   
> -	*pixels = cpu_to_le16(r << 11 | g << 5 | b);
> +	*pixels = (__force u16)cpu_to_le16(r << 11 | g << 5 | b);
>   }
>   
>   void vkms_writeback_row(struct vkms_writeback_job *wb,
José Expósito July 15, 2024, 3:19 p.m. UTC | #2
On Sun, Jul 14, 2024 at 09:41:10PM +0200, Thomas Zimmermann wrote:
> Hi
> 
> Am 12.07.24 um 18: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
> > 
> > Add casts to fix both warnings.
> > 
> > Signed-off-by: José Expósito <jose.exposito89@gmail.com>
> > ---
> >   drivers/gpu/drm/vkms/vkms_formats.c | 32 ++++++++++++++---------------
> >   1 file changed, 16 insertions(+), 16 deletions(-)
> > 
> > diff --git a/drivers/gpu/drm/vkms/vkms_formats.c b/drivers/gpu/drm/vkms/vkms_formats.c
> > index 36046b12f296..053fa6ce41a9 100644
> > --- a/drivers/gpu/drm/vkms/vkms_formats.c
> > +++ b/drivers/gpu/drm/vkms/vkms_formats.c
> > @@ -77,10 +77,10 @@ static void ARGB16161616_to_argb_u16(u8 *src_pixels, struct pixel_argb_u16 *out_
> >   {
> >   	u16 *pixels = (u16 *)src_pixels;
> 
> You should rather declare pixels as __le16 pointer. Same for the other
> changes. See [1] for an example.

Thanks a lot for the quick review Thomas.

v2 is available here:
https://lore.kernel.org/dri-devel/20240715151625.6968-2-jose.exposito89@gmail.com/T/#u

> Best regards
> Thomas
> 
> [1] https://elixir.bootlin.com/linux/v6.9/source/drivers/gpu/drm/drm_format_helper.c#L420
> 
> > -	out_pixel->a = le16_to_cpu(pixels[3]);
> > -	out_pixel->r = le16_to_cpu(pixels[2]);
> > -	out_pixel->g = le16_to_cpu(pixels[1]);
> > -	out_pixel->b = le16_to_cpu(pixels[0]);
> > +	out_pixel->a = le16_to_cpu((__force __le16)pixels[3]);
> > +	out_pixel->r = le16_to_cpu((__force __le16)pixels[2]);
> > +	out_pixel->g = le16_to_cpu((__force __le16)pixels[1]);
> > +	out_pixel->b = le16_to_cpu((__force __le16)pixels[0]);
> >   }
> >   static void XRGB16161616_to_argb_u16(u8 *src_pixels, struct pixel_argb_u16 *out_pixel)
> > @@ -88,9 +88,9 @@ static void XRGB16161616_to_argb_u16(u8 *src_pixels, struct pixel_argb_u16 *out_
> >   	u16 *pixels = (u16 *)src_pixels;
> >   	out_pixel->a = (u16)0xffff;
> > -	out_pixel->r = le16_to_cpu(pixels[2]);
> > -	out_pixel->g = le16_to_cpu(pixels[1]);
> > -	out_pixel->b = le16_to_cpu(pixels[0]);
> > +	out_pixel->r = le16_to_cpu((__force __le16)pixels[2]);
> > +	out_pixel->g = le16_to_cpu((__force __le16)pixels[1]);
> > +	out_pixel->b = le16_to_cpu((__force __le16)pixels[0]);
> >   }
> >   static void RGB565_to_argb_u16(u8 *src_pixels, struct pixel_argb_u16 *out_pixel)
> > @@ -100,7 +100,7 @@ static void RGB565_to_argb_u16(u8 *src_pixels, struct pixel_argb_u16 *out_pixel)
> >   	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));
> > -	u16 rgb_565 = le16_to_cpu(*pixels);
> > +	u16 rgb_565 = le16_to_cpu((__force __le16)*pixels);
> >   	s64 fp_r = drm_int2fixp((rgb_565 >> 11) & 0x1f);
> >   	s64 fp_g = drm_int2fixp((rgb_565 >> 5) & 0x3f);
> >   	s64 fp_b = drm_int2fixp(rgb_565 & 0x1f);
> > @@ -180,10 +180,10 @@ static void argb_u16_to_ARGB16161616(u8 *dst_pixels, struct pixel_argb_u16 *in_p
> >   {
> >   	u16 *pixels = (u16 *)dst_pixels;
> > -	pixels[3] = cpu_to_le16(in_pixel->a);
> > -	pixels[2] = cpu_to_le16(in_pixel->r);
> > -	pixels[1] = cpu_to_le16(in_pixel->g);
> > -	pixels[0] = cpu_to_le16(in_pixel->b);
> > +	pixels[3] = (__force u16)cpu_to_le16(in_pixel->a);
> > +	pixels[2] = (__force u16)cpu_to_le16(in_pixel->r);
> > +	pixels[1] = (__force u16)cpu_to_le16(in_pixel->g);
> > +	pixels[0] = (__force u16)cpu_to_le16(in_pixel->b);
> >   }
> >   static void argb_u16_to_XRGB16161616(u8 *dst_pixels, struct pixel_argb_u16 *in_pixel)
> > @@ -191,9 +191,9 @@ static void argb_u16_to_XRGB16161616(u8 *dst_pixels, struct pixel_argb_u16 *in_p
> >   	u16 *pixels = (u16 *)dst_pixels;
> >   	pixels[3] = 0xffff;
> > -	pixels[2] = cpu_to_le16(in_pixel->r);
> > -	pixels[1] = cpu_to_le16(in_pixel->g);
> > -	pixels[0] = cpu_to_le16(in_pixel->b);
> > +	pixels[2] = (__force u16)cpu_to_le16(in_pixel->r);
> > +	pixels[1] = (__force u16)cpu_to_le16(in_pixel->g);
> > +	pixels[0] = (__force u16)cpu_to_le16(in_pixel->b);
> >   }
> >   static void argb_u16_to_RGB565(u8 *dst_pixels, struct pixel_argb_u16 *in_pixel)
> > @@ -211,7 +211,7 @@ static void argb_u16_to_RGB565(u8 *dst_pixels, struct pixel_argb_u16 *in_pixel)
> >   	u16 g = drm_fixp2int(drm_fixp_div(fp_g, fp_g_ratio));
> >   	u16 b = drm_fixp2int(drm_fixp_div(fp_b, fp_rb_ratio));
> > -	*pixels = cpu_to_le16(r << 11 | g << 5 | b);
> > +	*pixels = (__force u16)cpu_to_le16(r << 11 | g << 5 | b);
> >   }
> >   void vkms_writeback_row(struct vkms_writeback_job *wb,
> 
> -- 
> --
> 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)
>
diff mbox series

Patch

diff --git a/drivers/gpu/drm/vkms/vkms_formats.c b/drivers/gpu/drm/vkms/vkms_formats.c
index 36046b12f296..053fa6ce41a9 100644
--- a/drivers/gpu/drm/vkms/vkms_formats.c
+++ b/drivers/gpu/drm/vkms/vkms_formats.c
@@ -77,10 +77,10 @@  static void ARGB16161616_to_argb_u16(u8 *src_pixels, struct pixel_argb_u16 *out_
 {
 	u16 *pixels = (u16 *)src_pixels;
 
-	out_pixel->a = le16_to_cpu(pixels[3]);
-	out_pixel->r = le16_to_cpu(pixels[2]);
-	out_pixel->g = le16_to_cpu(pixels[1]);
-	out_pixel->b = le16_to_cpu(pixels[0]);
+	out_pixel->a = le16_to_cpu((__force __le16)pixels[3]);
+	out_pixel->r = le16_to_cpu((__force __le16)pixels[2]);
+	out_pixel->g = le16_to_cpu((__force __le16)pixels[1]);
+	out_pixel->b = le16_to_cpu((__force __le16)pixels[0]);
 }
 
 static void XRGB16161616_to_argb_u16(u8 *src_pixels, struct pixel_argb_u16 *out_pixel)
@@ -88,9 +88,9 @@  static void XRGB16161616_to_argb_u16(u8 *src_pixels, struct pixel_argb_u16 *out_
 	u16 *pixels = (u16 *)src_pixels;
 
 	out_pixel->a = (u16)0xffff;
-	out_pixel->r = le16_to_cpu(pixels[2]);
-	out_pixel->g = le16_to_cpu(pixels[1]);
-	out_pixel->b = le16_to_cpu(pixels[0]);
+	out_pixel->r = le16_to_cpu((__force __le16)pixels[2]);
+	out_pixel->g = le16_to_cpu((__force __le16)pixels[1]);
+	out_pixel->b = le16_to_cpu((__force __le16)pixels[0]);
 }
 
 static void RGB565_to_argb_u16(u8 *src_pixels, struct pixel_argb_u16 *out_pixel)
@@ -100,7 +100,7 @@  static void RGB565_to_argb_u16(u8 *src_pixels, struct pixel_argb_u16 *out_pixel)
 	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));
 
-	u16 rgb_565 = le16_to_cpu(*pixels);
+	u16 rgb_565 = le16_to_cpu((__force __le16)*pixels);
 	s64 fp_r = drm_int2fixp((rgb_565 >> 11) & 0x1f);
 	s64 fp_g = drm_int2fixp((rgb_565 >> 5) & 0x3f);
 	s64 fp_b = drm_int2fixp(rgb_565 & 0x1f);
@@ -180,10 +180,10 @@  static void argb_u16_to_ARGB16161616(u8 *dst_pixels, struct pixel_argb_u16 *in_p
 {
 	u16 *pixels = (u16 *)dst_pixels;
 
-	pixels[3] = cpu_to_le16(in_pixel->a);
-	pixels[2] = cpu_to_le16(in_pixel->r);
-	pixels[1] = cpu_to_le16(in_pixel->g);
-	pixels[0] = cpu_to_le16(in_pixel->b);
+	pixels[3] = (__force u16)cpu_to_le16(in_pixel->a);
+	pixels[2] = (__force u16)cpu_to_le16(in_pixel->r);
+	pixels[1] = (__force u16)cpu_to_le16(in_pixel->g);
+	pixels[0] = (__force u16)cpu_to_le16(in_pixel->b);
 }
 
 static void argb_u16_to_XRGB16161616(u8 *dst_pixels, struct pixel_argb_u16 *in_pixel)
@@ -191,9 +191,9 @@  static void argb_u16_to_XRGB16161616(u8 *dst_pixels, struct pixel_argb_u16 *in_p
 	u16 *pixels = (u16 *)dst_pixels;
 
 	pixels[3] = 0xffff;
-	pixels[2] = cpu_to_le16(in_pixel->r);
-	pixels[1] = cpu_to_le16(in_pixel->g);
-	pixels[0] = cpu_to_le16(in_pixel->b);
+	pixels[2] = (__force u16)cpu_to_le16(in_pixel->r);
+	pixels[1] = (__force u16)cpu_to_le16(in_pixel->g);
+	pixels[0] = (__force u16)cpu_to_le16(in_pixel->b);
 }
 
 static void argb_u16_to_RGB565(u8 *dst_pixels, struct pixel_argb_u16 *in_pixel)
@@ -211,7 +211,7 @@  static void argb_u16_to_RGB565(u8 *dst_pixels, struct pixel_argb_u16 *in_pixel)
 	u16 g = drm_fixp2int(drm_fixp_div(fp_g, fp_g_ratio));
 	u16 b = drm_fixp2int(drm_fixp_div(fp_b, fp_rb_ratio));
 
-	*pixels = cpu_to_le16(r << 11 | g << 5 | b);
+	*pixels = (__force u16)cpu_to_le16(r << 11 | g << 5 | b);
 }
 
 void vkms_writeback_row(struct vkms_writeback_job *wb,