From patchwork Fri Dec 9 14:19:43 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Vetter X-Patchwork-Id: 9468315 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 D897160586 for ; Fri, 9 Dec 2016 14:20:05 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CB65028619 for ; Fri, 9 Dec 2016 14:20:05 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C06442861F; Fri, 9 Dec 2016 14:20:05 +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.1 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED, T_DKIM_INVALID autolearn=unavailable version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 8D3A628619 for ; Fri, 9 Dec 2016 14:20:05 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 968756EA01; Fri, 9 Dec 2016 14:19:49 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-wm0-x242.google.com (mail-wm0-x242.google.com [IPv6:2a00:1450:400c:c09::242]) by gabe.freedesktop.org (Postfix) with ESMTPS id 8388B6E9F5 for ; Fri, 9 Dec 2016 14:19:46 +0000 (UTC) Received: by mail-wm0-x242.google.com with SMTP id u144so4298886wmu.0 for ; Fri, 09 Dec 2016 06:19:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ffwll.ch; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=c6hgVjsMy7WyfkMiMv0JECQOBoasArtPHLqqeKB94E0=; b=GEaTwoFO0c/HWMVg7yCp2wvU33iAeiVPOdus2NjmcN5AGMqdxm3GG/oRlDntAT7drC 04MqIVAI/MCEwHDBvKTMB+L3t+ZykpAxAcVPMhBNQjIfurDEIbxJMgnD9MH/zxM3s3rP 9r2g4Mc247QsUbc6YDlLnyA7HR+LJyY1zv8Ec= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=c6hgVjsMy7WyfkMiMv0JECQOBoasArtPHLqqeKB94E0=; b=EeYozacRp7dQ8d2xDoK+9rYdWfW2o6PdD03S+xP5G/Dqw3THcqO6wkMDhuCrSd2REC PnBHVInwtJ3+N4UU48v5Wri/OE3gJTZyOQdhG8bvqtwECDapOAlRChitAooiokCSMlWp GvJK4YmuRks6LMn5T7hwV5+kctAND+egK7Fa6z200hEHF53xQ3ydJb4nlvCCDikhfs1B e5EynfA1x+2ES9ZB9Dtfb5XAUk09Eh1pQzbl8H9qU4f6tYIJpZJSisx+JjJITIRM+C/I rEKF2ZU7jGsX90iYGOfi1nd1X7OcPRHhiIo2mNZQlbb2N80AhoMsg/GgCywhWTh8w+bQ tcCQ== X-Gm-Message-State: AKaTC00ZpjkXH8gb+5UHdwtRO0HjfRuQw6teY1HA4uLGL25NqDu/v9SFV3iCJ8TIGHQT8w== X-Received: by 10.28.37.2 with SMTP id l2mr7533477wml.86.1481293184832; Fri, 09 Dec 2016 06:19:44 -0800 (PST) Received: from phenom.ffwll.local ([2a02:168:56b5:0:ac27:b86c:7764:9429]) by smtp.gmail.com with ESMTPSA id y4sm42573752wjp.0.2016.12.09.06.19.43 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 09 Dec 2016 06:19:44 -0800 (PST) From: Daniel Vetter To: DRI Development Subject: [PATCH 6/7] drm: Don't walk fb list twice in getresources Date: Fri, 9 Dec 2016 15:19:43 +0100 Message-Id: <20161209141944.22121-6-daniel.vetter@ffwll.ch> X-Mailer: git-send-email 2.10.2 In-Reply-To: <20161209141944.22121-1-daniel.vetter@ffwll.ch> References: <20161209141944.22121-1-daniel.vetter@ffwll.ch> Cc: Daniel Vetter , Intel Graphics Development , Daniel Vetter 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-Virus-Scanned: ClamAV using ClamSMTP We can be more clever than that and merge the 2 list walking loops. It's all under the one mutex critical section anyway, so nothing funny can happen. Signed-off-by: Daniel Vetter --- drivers/gpu/drm/drm_mode_config.c | 28 +++++++++++----------------- 1 file changed, 11 insertions(+), 17 deletions(-) diff --git a/drivers/gpu/drm/drm_mode_config.c b/drivers/gpu/drm/drm_mode_config.c index 64c2971478db..a6205a92dfee 100644 --- a/drivers/gpu/drm/drm_mode_config.c +++ b/drivers/gpu/drm/drm_mode_config.c @@ -84,7 +84,6 @@ int drm_mode_getresources(struct drm_device *dev, void *data, struct drm_file *file_priv) { struct drm_mode_card_res *card_res = data; - struct list_head *lh; struct drm_framebuffer *fb; struct drm_connector *connector; struct drm_crtc *crtc; @@ -105,25 +104,20 @@ int drm_mode_getresources(struct drm_device *dev, void *data, mutex_lock(&file_priv->fbs_lock); - /* - * For the non-control nodes we need to limit the list of resources - * by IDs in the group list for this node - */ - list_for_each(lh, &file_priv->fbs) - fb_count++; - /* handle this in 4 parts */ /* FBs */ - if (card_res->count_fbs >= fb_count) { - copied = 0; - fb_id = (uint32_t __user *)(unsigned long)card_res->fb_id_ptr; - list_for_each_entry(fb, &file_priv->fbs, filp_head) { - if (put_user(fb->base.id, fb_id + copied)) { - mutex_unlock(&file_priv->fbs_lock); - return -EFAULT; - } - copied++; + copied = 0; + fb_id = (uint32_t __user *)(unsigned long)card_res->fb_id_ptr; + list_for_each_entry(fb, &file_priv->fbs, filp_head) { + fb_count++; + if (fb_count > card_res->count_fbs) + continue; + + if (put_user(fb->base.id, fb_id + copied)) { + mutex_unlock(&file_priv->fbs_lock); + return -EFAULT; } + copied++; } card_res->count_fbs = fb_count; mutex_unlock(&file_priv->fbs_lock);