mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Javier Martinez Canillas <javierm@redhat.com>
To: Geert Uytterhoeven <geert@linux-m68k.org>,
	Maarten Lankhorst <maarten.lankhorst@linux.intel.com>,
	Maxime Ripard <mripard@kernel.org>,
	Thomas Zimmermann <tzimmermann@suse.de>,
	David Airlie <airlied@gmail.com>, Daniel Vetter <daniel@ffwll.ch>
Cc: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org,
	Geert Uytterhoeven <geert@linux-m68k.org>
Subject: Re: [PATCH 2/8] drm/dumb-buffers: Fix drm_mode_create_dumb() for bpp < 8
Date: Fri, 14 Jul 2023 11:50:11 +0200	[thread overview]
Message-ID: <87o7keu8j0.fsf@minerva.mail-host-address-is-not-set> (raw)
In-Reply-To: <5ba8ac5e465121b646a59487dc75b27017e0c769.1689252746.git.geert@linux-m68k.org>

Geert Uytterhoeven <geert@linux-m68k.org> writes:

> drm_mode_create_dumb() calculates the number of characters per pixel
> from the number of bits per pixel by rounding up, which is not correct
> as the actual value of cpp may be non-integer.  While we do not need to
> care here about complex formats like YUV, bpp < 8 is a valid use case.
>
>   - The overflow check for the buffer width is not correct if bpp < 8.
>     However, it doesn't hurt, as widths larger than U32_MAX / 8 should
>     not happen for real anyway.  Add a comment to clarify.
>   - Calculating the stride from the number of characters per pixel is
>     not correct.  Fix this by calculating it from the number of bits per
>     pixel instead.
>
> Signed-off-by: Geert Uytterhoeven <geert@linux-m68k.org>
> ---
> Why is drm_mode_create_dumb.size __u64?  The test for "args->height >

I don't think can be changed since is a DRM_IOCTL_MODE_CREATE_DUMB uAPI ?

> U32_MAX / stride" rejects all sizes not fitting in __u32 anyway.

Hmm, wonder if should be U64_MAX instead ?

> ---
>  drivers/gpu/drm/drm_dumb_buffers.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/gpu/drm/drm_dumb_buffers.c b/drivers/gpu/drm/drm_dumb_buffers.c
> index 70032bba1c97e787..21a04c32a5e3d785 100644
> --- a/drivers/gpu/drm/drm_dumb_buffers.c
> +++ b/drivers/gpu/drm/drm_dumb_buffers.c
> @@ -71,10 +71,11 @@ int drm_mode_create_dumb(struct drm_device *dev,
>  	/* overflow checks for 32bit size calculations */
>  	if (args->bpp > U32_MAX - 8)
>  		return -EINVAL;
> +	/* Incorrect (especially if bpp < 8), but doesn't hurt much */
>  	cpp = DIV_ROUND_UP(args->bpp, 8);
>  	if (cpp > U32_MAX / args->width)
>  		return -EINVAL;
> -	stride = cpp * args->width;
> +	stride = DIV_ROUND_UP(args->bpp * args->width, 8);
>  	if (args->height > U32_MAX / stride)
>  		return -EINVAL;
>  

Good catch.

Reviewed-by: Javier Martinez Canillas <javierm@redhat.com>

-- 
Best regards,

Javier Martinez Canillas
Core Platforms
Red Hat


  reply	other threads:[~2023-07-14  9:51 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-07-13 13:17 [PATCH 0/8] drm: fb-helper/ssd130x: Add support for DRM_FORMAT_R1 Geert Uytterhoeven
2023-07-13 13:17 ` [PATCH 1/8] drm/ssd130x: Fix pitch calculation in ssd130x_fb_blit_rect() Geert Uytterhoeven
2023-07-14  9:34   ` Javier Martinez Canillas
2023-07-14  9:41     ` Geert Uytterhoeven
2023-07-14  9:48       ` Javier Martinez Canillas
2023-07-21 22:39         ` Javier Martinez Canillas
2023-07-13 13:17 ` [PATCH 2/8] drm/dumb-buffers: Fix drm_mode_create_dumb() for bpp < 8 Geert Uytterhoeven
2023-07-14  9:50   ` Javier Martinez Canillas [this message]
2023-07-13 13:17 ` [PATCH/RFC 3/8] drm/ssd130x: Bail out early if data_array is not yet available Geert Uytterhoeven
2023-07-14  9:53   ` Javier Martinez Canillas
2023-07-13 13:17 ` [PATCH 4/8] drm/ssd130x: Add support for DRM_FORMAT_R1 Geert Uytterhoeven
2023-07-14 10:14   ` Javier Martinez Canillas
2023-07-14 11:26     ` Geert Uytterhoeven
2023-07-14 12:35       ` Javier Martinez Canillas
2023-07-14 12:43         ` Geert Uytterhoeven
2023-07-14 13:08           ` Javier Martinez Canillas
2023-07-13 13:17 ` [PATCH 5/8] drm/client: Convert drm_mode_create_dumb() to drm_mode_addfb2() Geert Uytterhoeven
2023-07-14 10:16   ` Javier Martinez Canillas
2023-07-14 11:01   ` Simon Ser
2023-07-14 11:29     ` Geert Uytterhoeven
2023-07-13 13:17 ` [PATCH 6/8] drm/fb-helper: Pass buffer format via drm_fb_helper_surface_size Geert Uytterhoeven
2023-07-14 10:25   ` Javier Martinez Canillas
2023-07-14 11:32     ` Geert Uytterhoeven
2023-07-13 13:17 ` [PATCH 7/8] drm/fb-helper: Add support for DRM_FORMAT_R1 Geert Uytterhoeven
2023-07-14 10:31   ` Javier Martinez Canillas
2023-07-13 13:17 ` [PATCH 8/8] drm/ssd130x: Switch preferred_bpp/depth to 1 Geert Uytterhoeven
2023-07-14 10:32   ` Javier Martinez Canillas
2023-07-16 13:30 ` [PATCH 0/8] drm: fb-helper/ssd130x: Add support for DRM_FORMAT_R1 Javier Martinez Canillas
2023-07-17  8:07   ` Geert Uytterhoeven
2023-07-17  9:13     ` Javier Martinez Canillas
2023-07-17  9:19       ` Geert Uytterhoeven
2023-07-17  9:33         ` Javier Martinez Canillas
2023-07-17 10:03           ` Geert Uytterhoeven
2023-07-17 10:11             ` Javier Martinez Canillas

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=87o7keu8j0.fsf@minerva.mail-host-address-is-not-set \
    --to=javierm@redhat.com \
    --cc=airlied@gmail.com \
    --cc=daniel@ffwll.ch \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=geert@linux-m68k.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=maarten.lankhorst@linux.intel.com \
    --cc=mripard@kernel.org \
    --cc=tzimmermann@suse.de \
    /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

Powered by JetHome