From: Thomas Zimmermann <tzimmermann@suse.de>
To: Geert Uytterhoeven <geert@linux-m68k.org>,
Javier Martinez Canillas <javierm@redhat.com>,
Maarten Lankhorst <maarten.lankhorst@linux.intel.com>,
Maxime Ripard <mripard@kernel.org>,
David Airlie <airlied@gmail.com>, Daniel Vetter <daniel@ffwll.ch>
Cc: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2 1/8] drm/dumb-buffers: Fix drm_mode_create_dumb() for bpp < 8
Date: Thu, 31 Aug 2023 09:40:19 +0200 [thread overview]
Message-ID: <1a98bb80-9990-dc65-5f14-066315a7e7d8@suse.de> (raw)
In-Reply-To: <16d488639e99f43ca3977ee7b8f76fc26c34aa86.1692888745.git.geert@linux-m68k.org>
[-- Attachment #1.1: Type: text/plain, Size: 2339 bytes --]
Hi
Am 24.08.23 um 17:08 schrieb Geert Uytterhoeven:
> 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>
> Reviewed-by: Javier Martinez Canillas <javierm@redhat.com>
> Tested-by: Javier Martinez Canillas <javierm@redhat.com>
> ---
> v2:
> - Add Reviewed-by, Tested-by.
> ---
> 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;
At first, I was confused by this. So I'd really prefer to outright
delete this code. As you say, it's incorrect and doesn't add anything.
The concept of cpp is somewhat wrong anyway.
> - stride = cpp * args->width;
> + stride = DIV_ROUND_UP(args->bpp * args->width, 8);
Do we need an overflow check for (bpp * width < U32_MAX) ?
Best regards
Thomas
> if (args->height > U32_MAX / stride)
> return -EINVAL;
>
--
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)
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 840 bytes --]
next prev parent reply other threads:[~2023-08-31 7:40 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-08-24 15:08 [PATCH v2 0/8] drm: fb-helper/ssd130x: Add support for DRM_FORMAT_R1 Geert Uytterhoeven
2023-08-24 15:08 ` [PATCH v2 1/8] drm/dumb-buffers: Fix drm_mode_create_dumb() for bpp < 8 Geert Uytterhoeven
2023-08-31 7:40 ` Thomas Zimmermann [this message]
2023-08-31 7:56 ` Geert Uytterhoeven
2023-08-24 15:08 ` [PATCH v2 2/8] drm/ssd130x: Fix screen clearing Geert Uytterhoeven
2023-08-29 8:40 ` Javier Martinez Canillas
2023-08-29 21:12 ` Javier Martinez Canillas
2023-08-24 15:08 ` [PATCH v2 3/8] drm/ssd130x: Use bool for ssd130x_deviceinfo flags Geert Uytterhoeven
2023-08-29 8:44 ` Javier Martinez Canillas
2023-08-29 21:16 ` Javier Martinez Canillas
2023-08-24 15:08 ` [PATCH v2 4/8] drm/ssd130x: Add support for DRM_FORMAT_R1 Geert Uytterhoeven
2023-08-29 9:01 ` Javier Martinez Canillas
2023-08-29 21:12 ` Javier Martinez Canillas
2023-08-31 8:01 ` Thomas Zimmermann
2023-08-31 8:22 ` Geert Uytterhoeven
2023-08-24 15:08 ` [PATCH v2 5/8] drm/client: Convert drm_client_buffer_addfb() to drm_mode_addfb2() Geert Uytterhoeven
2023-08-24 15:11 ` Daniel Stone
2023-08-24 15:22 ` Geert Uytterhoeven
2023-08-29 9:19 ` Javier Martinez Canillas
2023-08-31 8:15 ` Thomas Zimmermann
2023-08-24 15:08 ` [PATCH v2 6/8] drm/fb-helper: Pass buffer format via drm_fb_helper_surface_size Geert Uytterhoeven
2023-08-31 8:24 ` Thomas Zimmermann
2023-08-24 15:08 ` [PATCH v2 7/8] drm/fb-helper: Add support for DRM_FORMAT_R1 Geert Uytterhoeven
2023-08-31 8:57 ` Thomas Zimmermann
2023-08-24 15:08 ` [PATCH v2 8/8] drm/ssd130x: Switch preferred_bpp/depth to 1 Geert Uytterhoeven
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=1a98bb80-9990-dc65-5f14-066315a7e7d8@suse.de \
--to=tzimmermann@suse.de \
--cc=airlied@gmail.com \
--cc=daniel@ffwll.ch \
--cc=dri-devel@lists.freedesktop.org \
--cc=geert@linux-m68k.org \
--cc=javierm@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=maarten.lankhorst@linux.intel.com \
--cc=mripard@kernel.org \
/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®