From patchwork Thu Mar 19 04:33:19 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Stone X-Patchwork-Id: 6045881 Return-Path: X-Original-To: patchwork-dri-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id ACEB3BF910 for ; Thu, 19 Mar 2015 04:34:11 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id D9A1C204C9 for ; Thu, 19 Mar 2015 04:34:10 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id CF5A5204B0 for ; Thu, 19 Mar 2015 04:34:09 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 2DDAB6E962; Wed, 18 Mar 2015 21:34:03 -0700 (PDT) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from bhuna.collabora.co.uk (bhuna.collabora.co.uk [93.93.135.160]) by gabe.freedesktop.org (Postfix) with ESMTP id 5DDD089C93 for ; Wed, 18 Mar 2015 21:33:55 -0700 (PDT) Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: daniels) with ESMTPSA id 43255600EAE From: Daniel Stone To: dri-devel@lists.freedesktop.org Subject: [RFC PATCH 20/37] DRM: mode: Rename and combine drm_crtc_convert_umode Date: Thu, 19 Mar 2015 04:33:19 +0000 Message-Id: <1426739616-10635-20-git-send-email-daniels@collabora.com> X-Mailer: git-send-email 2.3.2 In-Reply-To: <1426739616-10635-1-git-send-email-daniels@collabora.com> References: <1426739556-10429-1-git-send-email-daniels@collabora.com> <1426739616-10635-1-git-send-email-daniels@collabora.com> X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Change drm_crtc_convert_umode into a helper which creates a new mode object and also performs validation. Signed-off-by: Daniel Stone --- drivers/gpu/drm/drm_crtc.c | 40 +++++++++++++++++++++------------------- 1 file changed, 21 insertions(+), 19 deletions(-) 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; }