From a40bd08d5271472e60e8195479788f7d77569bfc Mon Sep 17 00:00:00 2001
From: Dave Stevenson <dave.stevenson@raspberrypi.com>
Date: Thu, 12 Dec 2024 11:59:52 +0000
Subject: [PATCH] drm: Validate connector rotation has one bit set in the
 rotation property

Copy the same validation logic as from the plane rotation property.

Fixes: 8fec3ff87049 ("drm: Add a rotation parameter to connectors.")
Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com>
---
 drivers/gpu/drm/drm_atomic_uapi.c | 6 ++++++
 1 file changed, 6 insertions(+)

--- a/drivers/gpu/drm/drm_atomic_uapi.c
+++ b/drivers/gpu/drm/drm_atomic_uapi.c
@@ -792,6 +792,12 @@ static int drm_atomic_connector_set_prop
 	} else if (property == connector->broadcast_rgb_property) {
 		state->hdmi.broadcast_rgb = val;
 	} else if (property == connector->rotation_property) {
+		if (!is_power_of_2(val & DRM_MODE_ROTATE_MASK)) {
+			drm_dbg_atomic(connector->dev,
+				       "[CONNECTOR:%d:%s] bad rotation bitmask: 0x%llx\n",
+				       connector->base.id, connector->name, val);
+			return -EINVAL;
+		}
 		state->rotation = val;
 	} else if (connector->funcs->atomic_set_property) {
 		return connector->funcs->atomic_set_property(connector,
