* [PATCH v2 1/2] drm/edid: Use unsigned int in drm_add_modes_noedid()
2025-03-31 22:23 [PATCH v2 0/2] drm: Make some resolution info unsigned Lyude Paul
@ 2025-03-31 22:23 ` Lyude Paul
2025-03-31 22:23 ` [PATCH v2 2/2] drm/mode_config: Make drm_mode_config.(max|min)_(width|height) unsigned Lyude Paul
2025-04-01 7:15 ` [PATCH v2 0/2] drm: Make some resolution info unsigned Thomas Zimmermann
2 siblings, 0 replies; 4+ messages in thread
From: Lyude Paul @ 2025-03-31 22:23 UTC (permalink / raw)
To: Maxime Ripard, Greg Kroah-Hartman, dri-devel, linux-kernel,
Thomas Zimmermann
Cc: Maarten Lankhorst, David Airlie, Simona Vetter, Miguel Ojeda,
Alex Gaynor, Boqun Feng, Gary Guo, Björn Roy Baron,
Benno Lossin, Andreas Hindborg, Alice Ryhl, Trevor Gross,
open list:RUST:Keyword:b(?i:rust)b
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.
Signed-off-by: Lyude Paul <lyude@redhat.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Maxime Ripard <mripard@kernel.org>
Cc: Thomas Zimmermann <tzimmermann@suse.de>
---
V2:
* Remove h/vdisplay < 0 checks in drm_add_modes_noedid()
Signed-off-by: Lyude Paul <lyude@redhat.com>
---
drivers/gpu/drm/drm_edid.c | 10 ++--------
include/drm/drm_edid.h | 2 +-
2 files changed, 3 insertions(+), 9 deletions(-)
diff --git a/drivers/gpu/drm/drm_edid.c b/drivers/gpu/drm/drm_edid.c
index 13bc4c290b17d..1e69326283dce 100644
--- a/drivers/gpu/drm/drm_edid.c
+++ b/drivers/gpu/drm/drm_edid.c
@@ -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];
diff --git a/include/drm/drm_edid.h b/include/drm/drm_edid.h
index eaac5e665892a..b38409670868d 100644
--- a/include/drm/drm_edid.h
+++ b/include/drm/drm_edid.h
@@ -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);
--
2.48.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH v2 2/2] drm/mode_config: Make drm_mode_config.(max|min)_(width|height) unsigned
2025-03-31 22:23 [PATCH v2 0/2] drm: Make some resolution info unsigned Lyude Paul
2025-03-31 22:23 ` [PATCH v2 1/2] drm/edid: Use unsigned int in drm_add_modes_noedid() Lyude Paul
@ 2025-03-31 22:23 ` Lyude Paul
2025-04-01 7:15 ` [PATCH v2 0/2] drm: Make some resolution info unsigned Thomas Zimmermann
2 siblings, 0 replies; 4+ messages in thread
From: Lyude Paul @ 2025-03-31 22:23 UTC (permalink / raw)
To: Maxime Ripard, Greg Kroah-Hartman, dri-devel, linux-kernel,
Thomas Zimmermann
Cc: Maarten Lankhorst, David Airlie, Simona Vetter, Miguel Ojeda,
Alex Gaynor, Boqun Feng, Gary Guo, Björn Roy Baron,
Benno Lossin, Andreas Hindborg, Alice Ryhl, Trevor Gross,
open list:RUST:Keyword:b(?i:rust)b
It 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.
Signed-off-by: Lyude Paul <lyude@redhat.com>
Reviewed-by: Maxime Ripard <mripard@kernel.org>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Thomas Zimmermann <tzimmermann@suse.de>
---
V2:
* No functional changes, just update the commit message w/r/t Thomas's
comments.
Signed-off-by: Lyude Paul <lyude@redhat.com>
---
include/drm/drm_mode_config.h | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/include/drm/drm_mode_config.h b/include/drm/drm_mode_config.h
index 271765e2e9f2d..4b8f0370b79bf 100644
--- a/include/drm/drm_mode_config.h
+++ b/include/drm/drm_mode_config.h
@@ -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 */
--
2.48.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH v2 0/2] drm: Make some resolution info unsigned
2025-03-31 22:23 [PATCH v2 0/2] drm: Make some resolution info unsigned Lyude Paul
2025-03-31 22:23 ` [PATCH v2 1/2] drm/edid: Use unsigned int in drm_add_modes_noedid() Lyude Paul
2025-03-31 22:23 ` [PATCH v2 2/2] drm/mode_config: Make drm_mode_config.(max|min)_(width|height) unsigned Lyude Paul
@ 2025-04-01 7:15 ` Thomas Zimmermann
2 siblings, 0 replies; 4+ messages in thread
From: Thomas Zimmermann @ 2025-04-01 7:15 UTC (permalink / raw)
To: Lyude Paul, Maxime Ripard, Greg Kroah-Hartman, dri-devel,
linux-kernel
Cc: Miguel Ojeda, Alex Gaynor, Boqun Feng, Gary Guo,
Björn Roy Baron, Benno Lossin, Andreas Hindborg, Alice Ryhl,
Trevor Gross, open list:RUST:Keyword:b(?i:rust)b
Hi
Reviewed-by: Thomas Zimmermann <tzimmermann@suse.de>
for the series.
Best regards
Thomas
Am 01.04.25 um 00:23 schrieb Lyude Paul:
> 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
--
--
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)
^ permalink raw reply [flat|nested] 4+ messages in thread