<html><head></head><body><div id="editor_version_1.17.2_RNzdUoaq" style="word-break:break-word;"><div data-zone-id="0" data-line-index="0" data-line="true" style="margin-top: 4px; margin-bottom: 4px; line-height: 1.6;"><div class="" style="font-size: 16px;">Good idea!</div></div></div><div class="history-quote-wrapper" id="lark-mail-quote-169893376"><div style="list-style-position: inside" data-html-block="quote" data-mail-html-ignore=""><div id="lark-mail-quote-169893332" class="history-quote-wrapper"></div><div style="border-left: none; padding-left: 0px;" class="adit-html-block adit-html-block--collapsed"><div><div style="padding: 12px; background: rgb(245, 246, 247); color: rgb(31, 35, 41); border-radius: 4px; margin-top: 24px; margin-bottom: 12px;" id="lark-mail-quote-meta-Pa9tx2gji" class="adit-html-block__attr history-quote-meta-wrapper history-quote-gap-tag"><div id="lark-mail-quote-c270949e0fca8af28c4d54bd92c63a0d"><div style="word-break: break-word;"><div style=""><span style="white-space:nowrap;">From: </span><span style="white-space: nowrap;">"Thomas Zimmermann"<<a data-mailto="mailto:tzimmermann@suse.de" class="quote-head-meta-mailto" href="mailto:tzimmermann@suse.de" style="overflow-wrap: break-word; white-space: pre-wrap; hyphens: none; word-break: break-word; cursor: pointer; text-decoration: none; color: inherit;">tzimmermann@suse.de</a>></span></div><div style=""><span style="white-space:nowrap;">Date: </span> Thu, Nov 2, 2023, 21:27</div><div style=""><span style="white-space:nowrap;">Subject: </span> Re: [PATCH] gpu/drm/drm_framebuffer.c: Use Macro instead of actual number.</div><div style=""><span style="white-space:nowrap;">To: </span><span style="white-space: nowrap;">"Peng Hao"<<a data-mailto="mailto:penghao@dingdao.com" class="quote-head-meta-mailto" href="mailto:penghao@dingdao.com" style="overflow-wrap: break-word; white-space: pre-wrap; hyphens: none; word-break: break-word; cursor: pointer; text-decoration: none; color: inherit;">penghao@dingdao.com</a>></span>, <span style="white-space: nowrap;"><<a data-mailto="mailto:maarten.lankhorst@linux.intel.com" class="quote-head-meta-mailto" href="mailto:maarten.lankhorst@linux.intel.com" style="overflow-wrap: break-word; white-space: pre-wrap; hyphens: none; word-break: break-word; cursor: pointer; text-decoration: none; color: inherit;">maarten.lankhorst@linux.intel.com</a>></span>, <span style="white-space: nowrap;"><<a data-mailto="mailto:mripard@kernel.org" class="quote-head-meta-mailto" href="mailto:mripard@kernel.org" style="overflow-wrap: break-word; white-space: pre-wrap; hyphens: none; word-break: break-word; cursor: pointer; text-decoration: none; color: inherit;">mripard@kernel.org</a>></span>, <span style="white-space: nowrap;"><<a data-mailto="mailto:airlied@gmail.com" class="quote-head-meta-mailto" href="mailto:airlied@gmail.com" style="overflow-wrap: break-word; white-space: pre-wrap; hyphens: none; word-break: break-word; cursor: pointer; text-decoration: none; color: inherit;">airlied@gmail.com</a>></span>, <span style="white-space: nowrap;"><<a data-mailto="mailto:daniel@ffwll.ch" class="quote-head-meta-mailto" href="mailto:daniel@ffwll.ch" style="overflow-wrap: break-word; white-space: pre-wrap; hyphens: none; word-break: break-word; cursor: pointer; text-decoration: none; color: inherit;">daniel@ffwll.ch</a>></span></div><div style=""><span style="white-space:nowrap;">Cc: </span><span style="white-space: nowrap;"><<a data-mailto="mailto:linux-kernel@vger.kernel.org" class="quote-head-meta-mailto" href="mailto:linux-kernel@vger.kernel.org" style="overflow-wrap: break-word; white-space: pre-wrap; hyphens: none; word-break: break-word; cursor: pointer; text-decoration: none; color: inherit;">linux-kernel@vger.kernel.org</a>></span>, <span style="white-space: nowrap;"><<a data-mailto="mailto:dri-devel@lists.freedesktop.org" class="quote-head-meta-mailto" href="mailto:dri-devel@lists.freedesktop.org" style="overflow-wrap: break-word; white-space: pre-wrap; hyphens: none; word-break: break-word; cursor: pointer; text-decoration: none; color: inherit;">dri-devel@lists.freedesktop.org</a>></span></div></div></div></div><div><div style="white-space: pre-wrap" data-type="plainText"><span>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 <<a href="mailto:penghao@dingdao.com" target="_blank" ref="noopener noreferrer">penghao@dingdao.com</a>>
> ---
> 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)</span></div></div></div></div></div></div></body></html>