From patchwork Thu Mar 19 04:33:30 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Stone X-Patchwork-Id: 6046021 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 39350BF90F for ; Thu, 19 Mar 2015 04:34:22 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 529CB204C9 for ; Thu, 19 Mar 2015 04:34:21 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id 63F8120465 for ; Thu, 19 Mar 2015 04:34:20 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id B7E666E973; Wed, 18 Mar 2015 21:34:13 -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 EABCD6E964 for ; Wed, 18 Mar 2015 21:34:07 -0700 (PDT) Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: daniels) with ESMTPSA id 31844600621 From: Daniel Stone To: dri-devel@lists.freedesktop.org Subject: [RFC PATCH 31/37] drm: crtc_helper: Reference, not duplicate, modes Date: Thu, 19 Mar 2015 04:33:30 +0000 Message-Id: <1426739616-10635-31-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 Take a reference to existing modes, rather than duplicating them to create new ones. Signed-off-by: Daniel Stone --- drivers/gpu/drm/drm_crtc_helper.c | 43 ++++++++++++++++----------------------- 1 file changed, 17 insertions(+), 26 deletions(-) diff --git a/drivers/gpu/drm/drm_crtc_helper.c b/drivers/gpu/drm/drm_crtc_helper.c index c23f31f..08f0367 100644 --- a/drivers/gpu/drm/drm_crtc_helper.c +++ b/drivers/gpu/drm/drm_crtc_helper.c @@ -301,7 +301,7 @@ bool drm_crtc_helper_set_mode(struct drm_crtc *crtc, * setting. */ if (mode) - crtc->mode = drm_mode_duplicate(crtc->dev, mode); + crtc->mode = drm_mode_reference(mode); else crtc->mode = NULL; crtc->x = x; @@ -421,7 +421,8 @@ done: crtc->x = saved_x; crtc->y = saved_y; } else { - drm_mode_destroy(dev, saved_mode); + if (saved_mode) + drm_mode_destroy(dev, saved_mode); } return ret; @@ -547,7 +548,10 @@ int drm_crtc_helper_set_config(struct drm_mode_set *set) } save_set.crtc = set->crtc; - save_set.mode = set->crtc->mode; + if (set->crtc->mode) + save_set.mode = drm_mode_reference(set->crtc->mode); + else + save_set.mode = NULL; save_set.x = set->crtc->x; save_set.y = set->crtc->y; save_set.fb = set->crtc->primary->fb; @@ -718,6 +722,8 @@ fail: save_set.y, save_set.fb)) DRM_ERROR("failed to restore config after modeset failure\n"); + if (save_set.mode) + drm_mode_destroy(dev, save_set.mode); kfree(save_connectors); kfree(save_encoders); return ret; @@ -954,29 +960,9 @@ int drm_helper_crtc_mode_set(struct drm_crtc *crtc, else if (crtc->state) { crtc_state = kmemdup(crtc->state, sizeof(*crtc_state), GFP_KERNEL); - /* XXX: this is unpleasant: we should mandate dup instead */ - if (crtc_state) { - crtc_state->mode = - drm_mode_duplicate(crtc->dev, - crtc->state->mode); - if (!crtc_state->mode) { - kfree(crtc_state); - crtc_state = NULL; - } - } } - else { + else crtc_state = kzalloc(sizeof(*crtc_state), GFP_KERNEL); - if (crtc_state) { - crtc_state->mode = kzalloc(sizeof(*crtc_state->mode), - GFP_KERNEL); - /* XXX: as above, but mandate a new_state */ - if (!crtc_state->mode) { - kfree(crtc_state); - crtc_state = NULL; - } - } - } if (!crtc_state) return -ENOMEM; crtc_state->crtc = crtc; @@ -984,7 +970,12 @@ int drm_helper_crtc_mode_set(struct drm_crtc *crtc, crtc_state->enable = true; crtc_state->planes_changed = true; crtc_state->mode_changed = true; - drm_mode_copy(crtc_state->mode, mode); + if (crtc_state->mode) + drm_mode_destroy(crtc->dev, crtc_state->mode); + if (mode) + crtc_state->mode = drm_mode_reference(mode); + else + crtc_state->mode = NULL; drm_mode_copy(&crtc_state->adjusted_mode, adjusted_mode); if (crtc_funcs->atomic_check) { @@ -1006,7 +997,7 @@ int drm_helper_crtc_mode_set(struct drm_crtc *crtc, if (crtc->funcs->atomic_destroy_state) crtc->funcs->atomic_destroy_state(crtc, crtc_state); else { - kfree(crtc_state->mode); + drm_mode_destroy(crtc->dev, crtc_state->mode); kfree(crtc_state); } }