diff mbox series

[01/10] drm/fourcc: Add warning for bad bpp

Message ID 20241204-xilinx-formats-v1-1-0bf2c5147db1@ideasonboard.com (mailing list archive)
State New
Headers show
Series drm: Add new pixel formats for Xilinx Zynqmp | expand

Commit Message

Tomi Valkeinen Dec. 4, 2024, 9:31 a.m. UTC
drm_format_info_bpp() cannot be used for formats which do not have an
integer bits-per-pixel. Handle wrong calls by printing a warning and
returning 0.

Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
---
 drivers/gpu/drm/drm_fourcc.c | 7 +++++++
 1 file changed, 7 insertions(+)

Comments

Sagar, Vishal Dec. 4, 2024, 4:26 p.m. UTC | #1
[AMD Official Use Only - AMD Internal Distribution Only]

Hi Tomi,

Thanks for the patch.

> -----Original Message-----
> From: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
> Sent: Wednesday, December 4, 2024 10:31 AM
> To: Sagar, Vishal <vishal.sagar@amd.com>; Klymenko, Anatoliy
> <Anatoliy.Klymenko@amd.com>; Maarten Lankhorst
> <maarten.lankhorst@linux.intel.com>; Maxime Ripard <mripard@kernel.org>;
> Thomas Zimmermann <tzimmermann@suse.de>; David Airlie
> <airlied@gmail.com>; Simona Vetter <simona@ffwll.ch>; Laurent Pinchart
> <laurent.pinchart@ideasonboard.com>; Simek, Michal <michal.simek@amd.com>
> Cc: dri-devel@lists.freedesktop.org; linux-kernel@vger.kernel.org; linux-arm-
> kernel@lists.infradead.org; Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
> Subject: [PATCH 01/10] drm/fourcc: Add warning for bad bpp
>
> drm_format_info_bpp() cannot be used for formats which do not have an
> integer bits-per-pixel. Handle wrong calls by printing a warning and
> returning 0.

It would be good to add an example of pixel format that may cause this issue.

>
> Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
> ---
>  drivers/gpu/drm/drm_fourcc.c | 7 +++++++
>  1 file changed, 7 insertions(+)
>
> diff --git a/drivers/gpu/drm/drm_fourcc.c b/drivers/gpu/drm/drm_fourcc.c
> index 193cf8ed7912..e84c4ed6928c 100644
> --- a/drivers/gpu/drm/drm_fourcc.c
> +++ b/drivers/gpu/drm/drm_fourcc.c
> @@ -429,6 +429,13 @@ unsigned int drm_format_info_bpp(const struct
> drm_format_info *info, int plane)
>       if (!info || plane < 0 || plane >= info->num_planes)
>               return 0;
>
> +     if (info->char_per_block[plane] * 8 %
> +         (drm_format_info_block_width(info, plane) *
> +          drm_format_info_block_height(info, plane))) {
> +             pr_warn("unable to return an integer bpp\n");
> +             return 0;
> +     }
> +
>       return info->char_per_block[plane] * 8 /
>              (drm_format_info_block_width(info, plane) *
>               drm_format_info_block_height(info, plane));
>
> --
> 2.43.0

Regards
Vishal Sagar
Tomi Valkeinen Dec. 18, 2024, 11:49 a.m. UTC | #2
Hi Vishal,

On 04/12/2024 18:26, Sagar, Vishal wrote:
> [AMD Official Use Only - AMD Internal Distribution Only]
> 
> Hi Tomi,
> 
> Thanks for the patch.
> 
>> -----Original Message-----
>> From: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
>> Sent: Wednesday, December 4, 2024 10:31 AM
>> To: Sagar, Vishal <vishal.sagar@amd.com>; Klymenko, Anatoliy
>> <Anatoliy.Klymenko@amd.com>; Maarten Lankhorst
>> <maarten.lankhorst@linux.intel.com>; Maxime Ripard <mripard@kernel.org>;
>> Thomas Zimmermann <tzimmermann@suse.de>; David Airlie
>> <airlied@gmail.com>; Simona Vetter <simona@ffwll.ch>; Laurent Pinchart
>> <laurent.pinchart@ideasonboard.com>; Simek, Michal <michal.simek@amd.com>
>> Cc: dri-devel@lists.freedesktop.org; linux-kernel@vger.kernel.org; linux-arm-
>> kernel@lists.infradead.org; Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
>> Subject: [PATCH 01/10] drm/fourcc: Add warning for bad bpp
>>
>> drm_format_info_bpp() cannot be used for formats which do not have an
>> integer bits-per-pixel. Handle wrong calls by printing a warning and
>> returning 0.
> 
> It would be good to add an example of pixel format that may cause this issue.

Indeed, the description is perhaps a bit lacking. I'll change it to:

drm_format_info_bpp() cannot be used for formats which do not have an
integer bits-per-pixel in a pixel block.

E.g. DRM_FORMAT_XV15's (not yet in upstream) plane 0 has three 10-bit 
pixels (Y components), and two padding bits, in a 4 byte block. That is 
10.666... bits per pixel when considering the whole 4 byte block, which 
is what drm_format_info_bpp() does. Thus a driver that supports such 
formats cannot use drm_format_info_bpp(),

It is a driver bug if this happens, but so handle wrong calls by 
printing a warning and returning 0.

  Tomi

>>
>> Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
>> ---
>>   drivers/gpu/drm/drm_fourcc.c | 7 +++++++
>>   1 file changed, 7 insertions(+)
>>
>> diff --git a/drivers/gpu/drm/drm_fourcc.c b/drivers/gpu/drm/drm_fourcc.c
>> index 193cf8ed7912..e84c4ed6928c 100644
>> --- a/drivers/gpu/drm/drm_fourcc.c
>> +++ b/drivers/gpu/drm/drm_fourcc.c
>> @@ -429,6 +429,13 @@ unsigned int drm_format_info_bpp(const struct
>> drm_format_info *info, int plane)
>>        if (!info || plane < 0 || plane >= info->num_planes)
>>                return 0;
>>
>> +     if (info->char_per_block[plane] * 8 %
>> +         (drm_format_info_block_width(info, plane) *
>> +          drm_format_info_block_height(info, plane))) {
>> +             pr_warn("unable to return an integer bpp\n");
>> +             return 0;
>> +     }
>> +
>>        return info->char_per_block[plane] * 8 /
>>               (drm_format_info_block_width(info, plane) *
>>                drm_format_info_block_height(info, plane));
>>
>> --
>> 2.43.0
> 
> Regards
> Vishal Sagar
Sagar, Vishal Dec. 18, 2024, 2:35 p.m. UTC | #3
[AMD Official Use Only - AMD Internal Distribution Only]

Hi Tomi

> -----Original Message-----
> From: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
> Sent: Wednesday, December 18, 2024 12:49 PM
> To: Sagar, Vishal <vishal.sagar@amd.com>
> Cc: dri-devel@lists.freedesktop.org; linux-kernel@vger.kernel.org; linux-arm-
> kernel@lists.infradead.org; Klymenko, Anatoliy <Anatoliy.Klymenko@amd.com>;
> Maarten Lankhorst <maarten.lankhorst@linux.intel.com>; Maxime Ripard
> <mripard@kernel.org>; Thomas Zimmermann <tzimmermann@suse.de>; David
> Airlie <airlied@gmail.com>; Simona Vetter <simona@ffwll.ch>; Laurent Pinchart
> <laurent.pinchart@ideasonboard.com>; Simek, Michal <michal.simek@amd.com>
> Subject: Re: [PATCH 01/10] drm/fourcc: Add warning for bad bpp
>
> Hi Vishal,
>
> On 04/12/2024 18:26, Sagar, Vishal wrote:
> > [AMD Official Use Only - AMD Internal Distribution Only]
> >
> > Hi Tomi,
> >
> > Thanks for the patch.
> >
> >> -----Original Message-----
> >> From: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
> >> Sent: Wednesday, December 4, 2024 10:31 AM
> >> To: Sagar, Vishal <vishal.sagar@amd.com>; Klymenko, Anatoliy
> >> <Anatoliy.Klymenko@amd.com>; Maarten Lankhorst
> >> <maarten.lankhorst@linux.intel.com>; Maxime Ripard <mripard@kernel.org>;
> >> Thomas Zimmermann <tzimmermann@suse.de>; David Airlie
> >> <airlied@gmail.com>; Simona Vetter <simona@ffwll.ch>; Laurent Pinchart
> >> <laurent.pinchart@ideasonboard.com>; Simek, Michal
> <michal.simek@amd.com>
> >> Cc: dri-devel@lists.freedesktop.org; linux-kernel@vger.kernel.org; linux-arm-
> >> kernel@lists.infradead.org; Tomi Valkeinen
> <tomi.valkeinen@ideasonboard.com>
> >> Subject: [PATCH 01/10] drm/fourcc: Add warning for bad bpp
> >>
> >> drm_format_info_bpp() cannot be used for formats which do not have an
> >> integer bits-per-pixel. Handle wrong calls by printing a warning and
> >> returning 0.
> >
> > It would be good to add an example of pixel format that may cause this issue.
>
> Indeed, the description is perhaps a bit lacking. I'll change it to:
>
> drm_format_info_bpp() cannot be used for formats which do not have an
> integer bits-per-pixel in a pixel block.
>
> E.g. DRM_FORMAT_XV15's (not yet in upstream) plane 0 has three 10-bit
> pixels (Y components), and two padding bits, in a 4 byte block. That is
> 10.666... bits per pixel when considering the whole 4 byte block, which
> is what drm_format_info_bpp() does. Thus a driver that supports such
> formats cannot use drm_format_info_bpp(),
>
> It is a driver bug if this happens, but so handle wrong calls by
> printing a warning and returning 0.
>

This looks good to me.

Vishal

>   Tomi
>
> >>
> >> Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
> >> ---
> >>   drivers/gpu/drm/drm_fourcc.c | 7 +++++++
> >>   1 file changed, 7 insertions(+)
> >>
> >> diff --git a/drivers/gpu/drm/drm_fourcc.c b/drivers/gpu/drm/drm_fourcc.c
> >> index 193cf8ed7912..e84c4ed6928c 100644
> >> --- a/drivers/gpu/drm/drm_fourcc.c
> >> +++ b/drivers/gpu/drm/drm_fourcc.c
> >> @@ -429,6 +429,13 @@ unsigned int drm_format_info_bpp(const struct
> >> drm_format_info *info, int plane)
> >>        if (!info || plane < 0 || plane >= info->num_planes)
> >>                return 0;
> >>
> >> +     if (info->char_per_block[plane] * 8 %
> >> +         (drm_format_info_block_width(info, plane) *
> >> +          drm_format_info_block_height(info, plane))) {
> >> +             pr_warn("unable to return an integer bpp\n");
> >> +             return 0;
> >> +     }
> >> +
> >>        return info->char_per_block[plane] * 8 /
> >>               (drm_format_info_block_width(info, plane) *
> >>                drm_format_info_block_height(info, plane));
> >>
> >> --
> >> 2.43.0
> >
> > Regards
> > Vishal Sagar
diff mbox series

Patch

diff --git a/drivers/gpu/drm/drm_fourcc.c b/drivers/gpu/drm/drm_fourcc.c
index 193cf8ed7912..e84c4ed6928c 100644
--- a/drivers/gpu/drm/drm_fourcc.c
+++ b/drivers/gpu/drm/drm_fourcc.c
@@ -429,6 +429,13 @@  unsigned int drm_format_info_bpp(const struct drm_format_info *info, int plane)
 	if (!info || plane < 0 || plane >= info->num_planes)
 		return 0;
 
+	if (info->char_per_block[plane] * 8 %
+	    (drm_format_info_block_width(info, plane) *
+	     drm_format_info_block_height(info, plane))) {
+		pr_warn("unable to return an integer bpp\n");
+		return 0;
+	}
+
 	return info->char_per_block[plane] * 8 /
 	       (drm_format_info_block_width(info, plane) *
 		drm_format_info_block_height(info, plane));