Skip to contentSkip to conversation

drm/i915: Clamp cursor coordinates to int16_t range

PATCH Applied [email protected] 3 participants 5 messages Oct 21, 2013 – Oct 28, 2013

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drm/i915: Clamp cursor coordinates to int16_t range

From: Ville Syrjälä <[email protected]>

We store cursor_x/y as int16_t internally, but the user provided coordinates are int32_t. Clamp the coordinates so that they don't overflow the int16_t. Since the cursor is only 64x64 in size, the clamping can't cause any visual changes.

---
 drivers/gpu/drm/i915/intel_display.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/i915/intel_display.c +2 -2
index d4a480c..8f554f3 100644
@@ -7272,8 +7272,8 @@ static int intel_crtc_cursor_move(struct drm_crtc *crtc, int x, int y)
 {
 	struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
 
-	intel_crtc->cursor_x = x;
-	intel_crtc->cursor_y = y;
+	intel_crtc->cursor_x = clamp_t(int, x, SHRT_MIN, SHRT_MAX);
+	intel_crtc->cursor_y = clamp_t(int, y, SHRT_MIN, SHRT_MAX);
 
 	if (intel_crtc->active)
 		intel_crtc_update_cursor(crtc, intel_crtc->cursor_bo != NULL);
Signature · 6 lines
1.8.1.5

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Reviewed-by on v1 1/1
#1 lore raw
Quoted 6 lines · On Mon, Oct 21, 2013 at 07:01:58PM +0300, [email protected] wrote:

From: Ville Syrjälä <[email protected]>

We store cursor_x/y as int16_t internally, but the user provided coordinates are int32_t. Clamp the coordinates so that they don't overflow the int16_t. Since the cursor is only 64x64 in size, the clamping can't cause any visual changes.

EINVAL? That would appear to be a nuisance as we don't already tell the user off for being silly with the cursor position.

Bump the internal range? Future proof against tomorrow's 64k super-ultra-high definition monitors?

The valid range for cursor is currently (-64, 8192) and we don't compute relative cursor position, so we will be fine for a few years yet with int16_t.

Quoted 1 line

-Chris

Signature · 1 line
Chris Wilson, Intel Open Source Technology Centre
#2 lore raw
Quoted 14 lines · Chris Wilson
Quoted 6 lines · On Mon, Oct 21, 2013 at 07:01:58PM +0300, [email protected] wrote:

From: Ville Syrjälä <[email protected]>

We store cursor_x/y as int16_t internally, but the user provided coordinates are int32_t. Clamp the coordinates so that they don't overflow the int16_t. Since the cursor is only 64x64 in size, the clamping can't cause any visual changes.

EINVAL? That would appear to be a nuisance as we don't already tell the user off for being silly with the cursor position.

Bump the internal range? Future proof against tomorrow's 64k super-ultra-high definition monitors?

Quoted 6 lines

The valid range for cursor is currently (-64, 8192) and we don't compute relative cursor position, so we will be fine for a few years yet with int16_t.

Quoted 1 line

Queued for -next, thanks for the patch.
-Daniel

Signature · 3 lines
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch
#3 lore raw
In reply to [email protected]
Quoted 8 lines · On Mon, Oct 21, 2013 at 6:01 PM, <[email protected]> wrote:

From: Ville Syrjälä <[email protected]>

We store cursor_x/y as int16_t internally, but the user provided coordinates are int32_t. Clamp the coordinates so that they don't overflow the int16_t. Since the cursor is only 64x64 in size, the clamping can't cause any visual changes.

For shits&giggles: You've bothered with a subtest for this in your crc cursor test? Should be a one-liner and would neatly test whether QA catches it ...
-Daniel

Signature · 3 lines
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch
#4 lore raw
Quoted 8 lines · Daniel Vetter
Quoted 7 lines · On Mon, Oct 21, 2013 at 6:01 PM, <[email protected]> wrote:

From: Ville Syrjälä <[email protected]>

We store cursor_x/y as int16_t internally, but the user provided coordinates are int32_t. Clamp the coordinates so that they don't overflow the int16_t. Since the cursor is only 64x64 in size, the clamping can't cause any visual changes.

Quoted 6 lines
Quoted 1 line

For shits&giggles: You've bothered with a subtest for this in your crc cursor test? Should be a one-liner and would neatly test whether QA catches it ...

Yeah it's there. Actually I added the test before I knew the bug existed. The test is what found the bug for me.

It's not a specific subtest though, but part of all the bigger cursor-offscreen subtests. The subtest split I'm using there isn't very fine grained. Maybe I should change that actually. It would help in pinpointing the failing cases more accurately.

Signature · 2 lines
Ville Syrjälä
Intel OTC