* [PATCH] gpu/drm/drm_framebuffer.c: Use Macro instead of actual number.
@ 2023-11-02 2:29 Peng Hao
2023-11-02 6:32 ` Dmitry Baryshkov
2023-11-02 13:27 ` Thomas Zimmermann
0 siblings, 2 replies; 3+ messages in thread
From: Peng Hao @ 2023-11-02 2:29 UTC (permalink / raw)
To: maarten.lankhorst, mripard, tzimmermann, airlied, daniel
Cc: dri-devel, linux-kernel, penghao
Use Macro DRM_FORMAT_MAX_PLANES instead of 4, to improve modifiability.
Signed-off-by: Peng Hao <penghao@dingdao.com>
---
drivers/gpu/drm/drm_framebuffer.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/gpu/drm/drm_framebuffer.c b/drivers/gpu/drm/drm_framebuffer.c
index 2dd97473ca10..bf283dae9090 100644
--- a/drivers/gpu/drm/drm_framebuffer.c
+++ b/drivers/gpu/drm/drm_framebuffer.c
@@ -254,7 +254,7 @@ static int framebuffer_check(struct drm_device *dev,
}
}
- for (i = info->num_planes; i < 4; i++) {
+ for (i = info->num_planes; i < DRM_FORMAT_MAX_PLANES; i++) {
if (r->modifier[i]) {
drm_dbg_kms(dev, "non-zero modifier for unused plane %d\n", i);
return -EINVAL;
--
2.37.1
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] gpu/drm/drm_framebuffer.c: Use Macro instead of actual number.
2023-11-02 2:29 [PATCH] gpu/drm/drm_framebuffer.c: Use Macro instead of actual number Peng Hao
@ 2023-11-02 6:32 ` Dmitry Baryshkov
2023-11-02 13:27 ` Thomas Zimmermann
1 sibling, 0 replies; 3+ messages in thread
From: Dmitry Baryshkov @ 2023-11-02 6:32 UTC (permalink / raw)
To: Peng Hao
Cc: maarten.lankhorst, mripard, tzimmermann, airlied, daniel,
linux-kernel, dri-devel
On Thu, 2 Nov 2023 at 04:35, Peng Hao <penghao@dingdao.com> wrote:
>
> Use Macro DRM_FORMAT_MAX_PLANES instead of 4, to improve modifiability.
>
> Signed-off-by: Peng Hao <penghao@dingdao.com>
> ---
> drivers/gpu/drm/drm_framebuffer.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
Reviewed-by: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>
--
With best wishes
Dmitry
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] gpu/drm/drm_framebuffer.c: Use Macro instead of actual number.
2023-11-02 2:29 [PATCH] gpu/drm/drm_framebuffer.c: Use Macro instead of actual number Peng Hao
2023-11-02 6:32 ` Dmitry Baryshkov
@ 2023-11-02 13:27 ` Thomas Zimmermann
1 sibling, 0 replies; 3+ messages in thread
From: Thomas Zimmermann @ 2023-11-02 13:27 UTC (permalink / raw)
To: Peng Hao, maarten.lankhorst, mripard, airlied, daniel
Cc: linux-kernel, dri-devel
[-- Attachment #1.1: Type: text/plain, Size: 1831 bytes --]
Hi
Am 02.11.23 um 03:29 schrieb Peng Hao:
> Use Macro DRM_FORMAT_MAX_PLANES instead of 4, to improve modifiability.
>
> Signed-off-by: Peng Hao <penghao@dingdao.com>
> ---
> drivers/gpu/drm/drm_framebuffer.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/gpu/drm/drm_framebuffer.c b/drivers/gpu/drm/drm_framebuffer.c
> index 2dd97473ca10..bf283dae9090 100644
> --- a/drivers/gpu/drm/drm_framebuffer.c
> +++ b/drivers/gpu/drm/drm_framebuffer.c
> @@ -254,7 +254,7 @@ static int framebuffer_check(struct drm_device *dev,
> }
> }
>
> - for (i = info->num_planes; i < 4; i++) {
> + for (i = info->num_planes; i < DRM_FORMAT_MAX_PLANES; i++) {
This change makes the code more fragile. '4' is a fixed constant in the
UAPI struct, while DRM_FORMAT_MAX_PLANES is an internal constant. I
agree that both should reasonably have the same value. But (potentially)
changing the value of DRM_FORMAT_MAX_PLANES will break these loops with
a possible OOB access.
To make make this code more robust, it might be better to rewrite the
tests like this
for (i = num_planes; i < ARRAY_SIZE(r->modifier); +i) {
// the test for modifier[i]
}
if (r->flags & DRM_MODE_FB_MODIFIERS) {
for (i < ARRAY_SIZE(handles)) {
// test for handles[i]
}
for (i < ARRAY_SIZE(pitches)) {
// test for pitches[i]
}
for (i < ARRAY_SIZE(offsets)) {
// test for offsets[i]
}
}
Best regards
Thomas
> if (r->modifier[i]) {
> drm_dbg_kms(dev, "non-zero modifier for unused plane %d\n", i);
> 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 --]
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2023-11-02 13:27 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-11-02 2:29 [PATCH] gpu/drm/drm_framebuffer.c: Use Macro instead of actual number Peng Hao
2023-11-02 6:32 ` Dmitry Baryshkov
2023-11-02 13:27 ` Thomas Zimmermann
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®