From patchwork Tue Mar 18 21:22:46 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Rob Clark X-Patchwork-Id: 3849481 Return-Path: X-Original-To: patchwork-dri-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 293B89F370 for ; Tue, 18 Mar 2014 21:23:41 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 616BD2038F for ; Tue, 18 Mar 2014 21:23:40 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id 8D1342038E for ; Tue, 18 Mar 2014 21:23:39 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id B80BE6F4D7; Tue, 18 Mar 2014 14:23:38 -0700 (PDT) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-qc0-f182.google.com (mail-qc0-f182.google.com [209.85.216.182]) by gabe.freedesktop.org (Postfix) with ESMTP id 33C6E6F27A for ; Tue, 18 Mar 2014 14:23:37 -0700 (PDT) Received: by mail-qc0-f182.google.com with SMTP id e16so8698968qcx.13 for ; Tue, 18 Mar 2014 14:23:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-type:content-transfer-encoding; bh=nX+D1gU6zGTIIXMRDGhVv1Qyld0ZMS44ae76GQP+TzM=; b=be14NPGSavEQX7s51tdvnyiiFJTZLyX5RVMHa6CK/dhdz7dUZMVcLt4tBvfiM8+Qvv OZVrPFDZ+RJG5ixk5GA3lcKghfwJks3Y6YmxmVp6lemDJoU1To/aMhLvfhsszjlrOtyW ZBeCKhD+rYKsZJdX4P+oBl8F1D/MZBrV4AzbbhhKA5Qdb/rJyY0pX6ew3INLJP5MKY5Y qD1Ui4O/xCa/mbGkYkld2vhWNn0I6t49hyUr+v5Rsk4/HhhaQlfiJzmUcFmobyDKIchM 5uveJRjEY6d0DrOz2+jgkus9vuEzW7oqsqqAkdC/OGftBzbbcf4kCSr6IhWGz76+LMZ9 JDJQ== X-Received: by 10.140.97.137 with SMTP id m9mr12050019qge.95.1395177816762; Tue, 18 Mar 2014 14:23:36 -0700 (PDT) Received: from localhost (pool-108-20-254-15.bstnma.east.verizon.net. [108.20.254.15]) by mx.google.com with ESMTPSA id 21sm23757313qgh.23.2014.03.18.14.23.34 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 18 Mar 2014 14:23:35 -0700 (PDT) From: Rob Clark To: dri-devel@lists.freedesktop.org Subject: [PATCH 09/16] drm: Refactor object property check code Date: Tue, 18 Mar 2014 17:22:46 -0400 Message-Id: <1395177773-800-10-git-send-email-robdclark@gmail.com> X-Mailer: git-send-email 1.8.5.3 In-Reply-To: <1395177773-800-1-git-send-email-robdclark@gmail.com> References: <1395177773-800-1-git-send-email-robdclark@gmail.com> MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.15 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-Spam-Status: No, score=-4.1 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_MED, T_DKIM_INVALID, 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 From: Ville Syrjälä Refactor the code to check whether an object has a specific property to a new function. v1: original v2: rebase on atomic -- Rob Clark v3: EINVAL->ENOENT Signed-off-by: Ville Syrjälä --- drivers/gpu/drm/drm_crtc.c | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/drivers/gpu/drm/drm_crtc.c b/drivers/gpu/drm/drm_crtc.c index a8d99be..d5a2469 100644 --- a/drivers/gpu/drm/drm_crtc.c +++ b/drivers/gpu/drm/drm_crtc.c @@ -3800,6 +3800,19 @@ static int drm_mode_set_obj_prop(struct drm_mode_object *obj, return -EINVAL; } +static bool object_has_prop(const struct drm_mode_object *obj, u32 prop_id) +{ + int i; + + if (!obj->properties) + return false; + + for (i = 0; i < obj->properties->count; i++) + if (obj->properties->ids[i] == prop_id) + return true; + return false; +} + /* call with mode_config mutex held */ static int drm_mode_set_obj_prop_id(struct drm_device *dev, void *state, uint32_t obj_id, uint32_t obj_type, @@ -3807,20 +3820,10 @@ static int drm_mode_set_obj_prop_id(struct drm_device *dev, void *state, { struct drm_mode_object *arg_obj; struct drm_property *property; - int i; arg_obj = drm_mode_object_find(dev, obj_id, obj_type); - if (!arg_obj) + if (!(arg_obj && object_has_prop(arg_obj, prop_id))) return -ENOENT; - if (!arg_obj->properties) - return -EINVAL; - - for (i = 0; i < arg_obj->properties->count; i++) - if (arg_obj->properties->ids[i] == prop_id) - break; - - if (i == arg_obj->properties->count) - return -EINVAL; property = drm_property_find(dev, prop_id); if (!property)