diff mbox series

[v3] drm/vkms: Fix cpu_to_le16()/le16_to_cpu() warnings

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

Commit Message

José Expósito July 16, 2024, 4:17 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

Declare the target buffer as __le16 to fix both warnings.

Reviewed-by: Thomas Zimmermann <tzimmermann@suse.de>
Reviewed-by: Louis Chauvet <louis.chauvet@bootlin.com>
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.

v2 -> v3: https://lore.kernel.org/dri-devel/20240715151625.6968-2-jose.exposito89@gmail.com/

 - Thomas Zimmermann: Use cpu_to_le16() instead of casting 0xffff
 - Reviewed-by Thomas and Louis
---
 drivers/gpu/drm/vkms/vkms_formats.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

Comments

José Expósito Aug. 4, 2024, 5:14 p.m. UTC | #1
On Tue, Jul 16, 2024 at 06:17:26PM +0200, José Expósito wrote:
> 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.
> 
> Reviewed-by: Thomas Zimmermann <tzimmermann@suse.de>
> Reviewed-by: Louis Chauvet <louis.chauvet@bootlin.com>
> 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.
> 
> v2 -> v3: https://lore.kernel.org/dri-devel/20240715151625.6968-2-jose.exposito89@gmail.com/
> 
>  - Thomas Zimmermann: Use cpu_to_le16() instead of casting 0xffff
>  - Reviewed-by Thomas and Louis
> ---

Would it be possible to get an ACK from the maintainers? It is a very simple patch
and it already has 2 reviewed-by, hopefully we can get it merged.

Thanks a lot in advance!

>  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..040b7f113a3b 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] = cpu_to_le16(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);
> @@ -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));
> -- 
> 2.45.2
>
Maíra Canal Aug. 4, 2024, 8:46 p.m. UTC | #2
Hi José,

On 8/4/24 14:14, José Expósito wrote:
> On Tue, Jul 16, 2024 at 06:17:26PM +0200, José Expósito wrote:
>> 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.
>>
>> Reviewed-by: Thomas Zimmermann <tzimmermann@suse.de>
>> Reviewed-by: Louis Chauvet <louis.chauvet@bootlin.com>
>> 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.
>>
>> v2 -> v3: https://lore.kernel.org/dri-devel/20240715151625.6968-2-jose.exposito89@gmail.com/
>>
>>   - Thomas Zimmermann: Use cpu_to_le16() instead of casting 0xffff
>>   - Reviewed-by Thomas and Louis
>> ---
> 
> Would it be possible to get an ACK from the maintainers? It is a very simple patch
> and it already has 2 reviewed-by, hopefully we can get it merged.

Acked-by: Maíra Canal <mcanal@igalia.com>

Could you please apply it to drm-misc-next?

Best Regards,
- Maíra

> 
> Thanks a lot in advance!
> 
>>   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..040b7f113a3b 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] = cpu_to_le16(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);
>> @@ -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));
>> -- 
>> 2.45.2
>>
José Expósito Aug. 8, 2024, 8:09 a.m. UTC | #3
On Sun, Aug 04, 2024 at 05:46:55PM -0300, Maíra Canal wrote:
> Hi José,
> 
> On 8/4/24 14:14, José Expósito wrote:
> > On Tue, Jul 16, 2024 at 06:17:26PM +0200, José Expósito wrote:
> > > 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.
> > > 
> > > Reviewed-by: Thomas Zimmermann <tzimmermann@suse.de>
> > > Reviewed-by: Louis Chauvet <louis.chauvet@bootlin.com>
> > > 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.
> > > 
> > > v2 -> v3: https://lore.kernel.org/dri-devel/20240715151625.6968-2-jose.exposito89@gmail.com/
> > > 
> > >   - Thomas Zimmermann: Use cpu_to_le16() instead of casting 0xffff
> > >   - Reviewed-by Thomas and Louis
> > > ---
> > 
> > Would it be possible to get an ACK from the maintainers? It is a very simple patch
> > and it already has 2 reviewed-by, hopefully we can get it merged.
> 
> Acked-by: Maíra Canal <mcanal@igalia.com>
> 
> Could you please apply it to drm-misc-next?

Applied, thanks a lot for the ack Maíra.

Jose

> 
> Best Regards,
> - Maíra
> 
> > 
> > Thanks a lot in advance!
> > 
> > >   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..040b7f113a3b 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] = cpu_to_le16(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);
> > > @@ -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));
> > > -- 
> > > 2.45.2
> > >
diff mbox series

Patch

diff --git a/drivers/gpu/drm/vkms/vkms_formats.c b/drivers/gpu/drm/vkms/vkms_formats.c
index 36046b12f296..040b7f113a3b 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] = cpu_to_le16(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);
@@ -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));