diff mbox

[RFC,20/37] DRM: mode: Rename and combine drm_crtc_convert_umode

Message ID 1426739616-10635-20-git-send-email-daniels@collabora.com (mailing list archive)
State New, archived
Headers show

Commit Message

Daniel Stone March 19, 2015, 4:33 a.m. UTC
Change drm_crtc_convert_umode into a helper which creates a new mode
object and also performs validation.

Signed-off-by: Daniel Stone <daniels@collabora.com>
---
 drivers/gpu/drm/drm_crtc.c | 40 +++++++++++++++++++++-------------------
 1 file changed, 21 insertions(+), 19 deletions(-)
diff mbox

Patch

diff --git a/drivers/gpu/drm/drm_crtc.c b/drivers/gpu/drm/drm_crtc.c
index cf44403..c7ee172 100644
--- a/drivers/gpu/drm/drm_crtc.c
+++ b/drivers/gpu/drm/drm_crtc.c
@@ -1747,24 +1747,30 @@  static void drm_crtc_convert_to_umode(struct drm_mode_modeinfo *out,
 }
 
 /**
- * drm_crtc_convert_umode - convert a modeinfo into a drm_display_mode
- * @out: drm_display_mode to return to the user
+ * drm_mode_new_from_umode - convert a modeinfo into a drm_display_mode
+ * @dev: DRM device to create mode for
  * @in: drm_mode_modeinfo to use
  *
  * Convert a drm_mode_modeinfo into a drm_display_mode structure to return to
  * the caller.
  *
  * Returns:
- * Zero on success, negative errno on failure.
+ * New drm_display_mode on success, NULL on failure
  */
-static int drm_crtc_convert_umode(struct drm_display_mode *out,
+static struct drm_display_mode *drm_mode_new_from_umode(struct drm_device *dev,
 				  const struct drm_mode_modeinfo *in)
 {
+	struct drm_display_mode *out;
+
+	out = drm_mode_create(dev);
+	if (!out)
+		return NULL;
+
 	if (in->clock > INT_MAX || in->vrefresh > INT_MAX)
-		return -ERANGE;
+		goto err;
 
 	if ((in->flags & DRM_MODE_FLAG_3D_MASK) > DRM_MODE_FLAG_3D_MAX)
-		return -EINVAL;
+		goto err;
 
 	out->clock = in->clock;
 	out->hdisplay = in->hdisplay;
@@ -1783,7 +1789,14 @@  static int drm_crtc_convert_umode(struct drm_display_mode *out,
 	strncpy(out->name, in->name, DRM_DISPLAY_MODE_LEN);
 	out->name[DRM_DISPLAY_MODE_LEN-1] = 0;
 
-	return 0;
+	out->status = drm_mode_validate_basic(out);
+	if (out->status != MODE_OK)
+		goto err;
+
+	return out;
+err:
+	drm_mode_destroy(dev, out);
+	return NULL;
 }
 
 /**
@@ -2785,20 +2798,9 @@  int drm_mode_setcrtc(struct drm_device *dev, void *data,
 			}
 		}
 
-		mode = drm_mode_create(dev);
+		mode = drm_mode_new_from_umode(dev, &crtc_req->mode);
 		if (!mode) {
-			ret = -ENOMEM;
-			goto out;
-		}
-
-		ret = drm_crtc_convert_umode(mode, &crtc_req->mode);
-		if (ret) {
 			DRM_DEBUG_KMS("Invalid mode\n");
-			goto out;
-		}
-
-		mode->status = drm_mode_validate_basic(mode);
-		if (mode->status != MODE_OK) {
 			ret = -EINVAL;
 			goto out;
 		}