drm: Make some resolution info unsigned
Subsystems (3)
v2 cover drm: Make some resolution info unsigned
During the review of some of my patches for KMS bindings in Rust, it was pointed out we have some areas of DRM that are storing resolutions as signed integers when it doesn't really make sense. Since Rust has arithematic overflow checking by default in the kernel, let's change these to unsigned so that we can take advantage of that.
Lyude Paul (2):
drm/edid: Use unsigned int in drm_add_modes_noedid() drm/mode_config: Make drm_mode_config.(max|min)_(width|height)
unsigned
drivers/gpu/drm/drm_edid.c | 10 ++-------- include/drm/drm_edid.h | 2 +- include/drm/drm_mode_config.h | 4 ++-- 3 files changed, 5 insertions(+), 11 deletions(-)
base-commit: cf05922d63e2ae6a9b1b52ff5236a44c3b29f78c
Signature · 1 line
2.48.1
PATCH v2 1/2 drm/edid: Use unsigned int in drm_add_modes_noedid()
A negative resolution doesn't really make any sense, so let's make these parameters unsigned. In C this doesn't make much of a difference, but Rust is stricter about signed/unsigned casts and additionally can check for arithmetic over/underflows if CONFIG_RUST_OVERFLOW_CHECKS is enabled.
---
V2:
* Remove h/vdisplay < 0 checks in drm_add_modes_noedid()
--- drivers/gpu/drm/drm_edid.c | 10 ++-------- include/drm/drm_edid.h | 2 +- 2 files changed, 3 insertions(+), 9 deletions(-)
drivers/gpu/drm/drm_edid.c +2 -8
@@ -7099,18 +7099,12 @@ EXPORT_SYMBOL(drm_add_edid_modes);* Return: The number of modes added or 0 if we couldn't find any. */ int drm_add_modes_noedid (struct drm_connector *connector, -int hdisplay,int vdisplay) +unsigned int hdisplay,unsigned int vdisplay) { -int i, count, num_modes =0 ; +int i, count =ARRAY_SIZE (drm_dmt_modes), num_modes =0 ;struct drm_display_mode *mode;struct drm_device *dev = connector->dev; - count =ARRAY_SIZE (drm_dmt_modes); -if (hdisplay <0 ) - hdisplay =0 ; -if (vdisplay <0 ) - vdisplay =0 ; -for (i =0 ; i < count; i++) {const struct drm_display_mode *ptr = &drm_dmt_modes[i];
include/drm/drm_edid.h +1 -1
@@ -437,7 +437,7 @@ bool drm_detect_monitor_audio(const struct edid *edid);enum hdmi_quantization_range drm_default_rgb_quant_range (const struct drm_display_mode *mode);int drm_add_modes_noedid (struct drm_connector *connector, -int hdisplay,int vdisplay); +unsigned int hdisplay,unsigned int vdisplay);int drm_edid_header_is_valid (const void *edid);bool drm_edid_is_valid (struct edid *edid);
Signature · 1 line
2.48.1
PATCH v2 2/2 drm/mode_config: Make drm_mode_config.(max|min)_(width|height) unsigned
In reply to Lyude PaulIt doesn't make much sense to allow devices to specify their min/max resolution as signed integers, and in Rust with CONFIG_RUST_OVERFLOW_CHECKS enabled this provides us actual over/underflow checks. Similarly, it doesn't really make much sense for us to allow devices to specify their minimum/maximum resolution as signed.
---
V2:
* No functional changes, just update the commit message w/r/t Thomas's comments.
--- include/drm/drm_mode_config.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
include/drm/drm_mode_config.h +2 -2
@@ -532,8 +532,8 @@ struct drm_mode_config {*/ struct list_head privobj_list; -int min_width, min_height; -int max_width, max_height; +unsigned int min_width, min_height; +unsigned int max_width, max_height;const struct drm_mode_config_funcs *funcs;/* output poll support */
Signature · 1 line
2.48.1
Hi
for the series.
Best regards
Thomas
Am 01.04.25 um 00:23 schrieb Lyude Paul:
Quoted 18 lines
During the review of some of my patches for KMS bindings in Rust, it was pointed out we have some areas of DRM that are storing resolutions as signed integers when it doesn't really make sense. Since Rust has arithematic overflow checking by default in the kernel, let's change these to unsigned so that we can take advantage of that.
Lyude Paul (2):
drm/edid: Use unsigned int indrm_add_modes_noedid()drm/mode_config: Make drm_mode_config.(max|min)_(width|height)
unsigneddrivers/gpu/drm/drm_edid.c | 10 ++-------- include/drm/drm_edid.h | 2 +- include/drm/drm_mode_config.h | 4 ++-- 3 files changed, 5 insertions(+), 11 deletions(-)base-commit:
cf05922d63e2ae6a9b1b52ff5236a44c3b29f78c
Signature · 7 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)