gpu/drm/drm_framebuffer.c: Use Macro instead of actual number.
Subsystems (2)
PATCH 1/1 gpu/drm/drm_framebuffer.c: Use Macro instead of actual number.
Use Macro DRM_FORMAT_MAX_PLANES instead of 4, to improve modifiability.
--- drivers/gpu/drm/drm_framebuffer.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/drm_framebuffer.c +1 -1
@@ -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 ;
Signature · 1 line
2.37.1
Quoted 7 lines · Peng Hao
Use Macro
DRM_FORMAT_MAX_PLANESinstead of 4, to improve modifiability.Signed-off-by Peng Hao <[email protected]>--- drivers/gpu/drm/drm_framebuffer.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Signature · 2 lines
With best wishes Dmitry
Thomas Zimmermann
maintainerHi
Am 02.11.23 um 03:29 schrieb Peng Hao:
Quoted 12 lines
Use Macro
DRM_FORMAT_MAX_PLANESinstead of 4, to improve modifiability.Signed-off-by Peng Hao <[email protected]>--- drivers/gpu/drm/drm_framebuffer.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/gpu/drm/drm_framebuffer.c +0
-0
drivers/gpu/drm/drm_framebuffer.c static int framebuffer_check(struct drm_device *dev, · line 257
Quoted 5 lines
drivers/gpu/drm/drm_framebuffer.c +1
-1@@ -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
Quoted 3 lines
drivers/gpu/drm/drm_framebuffer.c +0
-0if (r->modifier[i]) {drm_dbg_kms (dev,"non-zero modifier for unused plane %d\n" , i);return -EINVAL ;
Signature · 6 lines
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)
Good idea!
Quoted 65 lines
From: "Thomas Zimmermann"<[email protected]> Date: Thu, Nov 2, 2023, 21:27 Subject: Re: [PATCH] gpu/drm/drm_framebuffer.c: Use Macro instead of actual number. To: "Peng Hao"<[email protected]>, <[email protected]>, <[email protected]>, <[email protected]>, <[email protected]>Cc: <[email protected]>, <[email protected]> Hi
Am 02.11.23 um 03:29 schrieb Peng Hao:
Quoted 12 lines
Use Macro
DRM_FORMAT_MAX_PLANESinstead of 4, to improve modifiability.Signed-off-by Peng Hao <[email protected]>--- drivers/gpu/drm/drm_framebuffer.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/gpu/drm/drm_framebuffer.c +0
-0drivers/gpu/drm/drm_framebuffer.c static int framebuffer_check(struct drm_device *dev, · line 257
Quoted 5 lines
drivers/gpu/drm/drm_framebuffer.c +1
-1@@ -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_PLANESis an internal constant. I agree that both should reasonably have the same value. But (potentially) changing the value ofDRM_FORMAT_MAX_PLANESwill 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
ThomasQuoted 3 lines
drivers/gpu/drm/drm_framebuffer.c +0
-0if (r->modifier[i]) {drm_dbg_kms (dev,"non-zero modifier for unused plane %d\n" , i);return -EINVAL ;Signature · 6 lines
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)