From patchwork Tue May 31 09:17:22 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomi Valkeinen X-Patchwork-Id: 9143999 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 88AE160777 for ; Tue, 31 May 2016 09:17:50 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7BD332793B for ; Tue, 31 May 2016 09:17:50 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7095F28185; Tue, 31 May 2016 09:17:50 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2C49A2793B for ; Tue, 31 May 2016 09:17:50 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 80A7E6E346; Tue, 31 May 2016 09:17:48 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from comal.ext.ti.com (comal.ext.ti.com [198.47.26.152]) by gabe.freedesktop.org (Postfix) with ESMTPS id A99B46E346 for ; Tue, 31 May 2016 09:17:44 +0000 (UTC) Received: from dlelxv90.itg.ti.com ([172.17.2.17]) by comal.ext.ti.com (8.13.7/8.13.7) with ESMTP id u4V9HcGo013808; Tue, 31 May 2016 04:17:38 -0500 Received: from DFLE72.ent.ti.com (dfle72.ent.ti.com [128.247.5.109]) by dlelxv90.itg.ti.com (8.14.3/8.13.8) with ESMTP id u4V9Hfgb019568; Tue, 31 May 2016 04:17:41 -0500 Received: from dflp33.itg.ti.com (10.64.6.16) by DFLE72.ent.ti.com (128.247.5.109) with Microsoft SMTP Server id 14.3.294.0; Tue, 31 May 2016 04:17:41 -0500 Received: from deskari.ti.com (ileax41-snat.itg.ti.com [10.172.224.153]) by dflp33.itg.ti.com (8.14.3/8.13.8) with ESMTP id u4V9HYNI026897; Tue, 31 May 2016 04:17:40 -0500 From: Tomi Valkeinen To: , Dave Airlie , Daniel Vetter Subject: [PATCH 3/4] drm: make drm_atomic_set_mode_prop_for_crtc() more reliable Date: Tue, 31 May 2016 12:17:22 +0300 Message-ID: <1464686243-25418-4-git-send-email-tomi.valkeinen@ti.com> X-Mailer: git-send-email 2.5.0 In-Reply-To: <1464686243-25418-1-git-send-email-tomi.valkeinen@ti.com> References: <1464686243-25418-1-git-send-email-tomi.valkeinen@ti.com> MIME-Version: 1.0 Cc: Tomi Valkeinen 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: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP drm_atomic_set_mode_prop_for_crtc() has a few issues: - it doesn't clear the state->mode, so old data may be left there when a new mode is set. - if an error happens, state->mode is left in a partially updated state. This patch improves the situation by: - bail out early if blob is of wrong length. - construct drm_display_mode first in an initialized local variable, and copy it to state->mode only when we know the call has succeeded. Signed-off-by: Tomi Valkeinen --- drivers/gpu/drm/drm_atomic.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/drivers/gpu/drm/drm_atomic.c b/drivers/gpu/drm/drm_atomic.c index 3ff1ed7b33db..5bfecb2bbedf 100644 --- a/drivers/gpu/drm/drm_atomic.c +++ b/drivers/gpu/drm/drm_atomic.c @@ -348,16 +348,24 @@ int drm_atomic_set_mode_prop_for_crtc(struct drm_crtc_state *state, if (blob == state->mode_blob) return 0; + if (blob && blob->length != sizeof(struct drm_mode_modeinfo)) + return -EINVAL; + drm_property_unreference_blob(state->mode_blob); state->mode_blob = NULL; if (blob) { - if (blob->length != sizeof(struct drm_mode_modeinfo) || - drm_mode_convert_umode(&state->mode, - (const struct drm_mode_modeinfo *) - blob->data)) + const struct drm_mode_modeinfo *umode = + (const struct drm_mode_modeinfo *)blob->data; + struct drm_display_mode mode; + + memset(&mode, 0, sizeof(mode)); + + if (drm_mode_convert_umode(&mode, umode)) return -EINVAL; + state->mode = mode; + state->mode_blob = drm_property_reference_blob(blob); state->enable = true; DRM_DEBUG_ATOMIC("Set [MODE:%s] for CRTC state %p\n",