From patchwork Mon Nov 25 14:47:32 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Rob Clark X-Patchwork-Id: 3232651 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 3730D9F693 for ; Mon, 25 Nov 2013 14:48:47 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 89E6F20200 for ; Mon, 25 Nov 2013 14:48:42 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id 0F1F820220 for ; Mon, 25 Nov 2013 14:48:37 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 986F8FA852; Mon, 25 Nov 2013 06:48:31 -0800 (PST) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-qe0-f50.google.com (mail-qe0-f50.google.com [209.85.128.50]) by gabe.freedesktop.org (Postfix) with ESMTP id 9F86CFA65E for ; Mon, 25 Nov 2013 06:48:12 -0800 (PST) Received: by mail-qe0-f50.google.com with SMTP id 1so1895150qec.37 for ; Mon, 25 Nov 2013 06:48:12 -0800 (PST) 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=5+L+rtAEcjCFTz0d6CqJPel4fa2MkBrXy690JAXMS5Y=; b=TzCo70ch5ZdoHa0bxpiODGTwGV6Y9t4BFPNsMOvlPTwT3v1j1M5MDu2oqk4ocgKxlU 72nYM7cKc8/YG+8zi/zDDQ9KrvqcyYN3yMOFuWmlnK9dmvqEa4Z+JvXuXcTzv2UN0gV4 7bQwj7XLoevpcVFe5FVT97Wk8Mc5pFEbo7yznSRGfQnEztE2mC/0Bm7oEjSCkJ1U6t9g AVhSPk/EqIlq97xlMyOD6BUafaB6h3sN39g+ECiC8RgjUn+yVXRxFBBKNZ8wZ3+B5VQx yj6JZtK8T/MSyK6FliAY/rJSv8XyHFxMHRYgqCpaVFMZMi2XlHS13jVumdKlQi4ICSne HEbQ== X-Received: by 10.224.34.71 with SMTP id k7mr46067773qad.15.1385390892257; Mon, 25 Nov 2013 06:48:12 -0800 (PST) Received: from localhost (pool-108-20-250-166.bstnma.east.verizon.net. [108.20.250.166]) by mx.google.com with ESMTPSA id a9sm115304678qed.6.2013.11.25.06.48.10 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 25 Nov 2013 06:48:11 -0800 (PST) From: Rob Clark To: dri-devel@lists.freedesktop.org Subject: [RFCv4 08/14] drm: Refactor object property check code Date: Mon, 25 Nov 2013 09:47:32 -0500 Message-Id: <1385390858-4412-9-git-send-email-robdclark@gmail.com> X-Mailer: git-send-email 1.8.4.2 In-Reply-To: <1385390858-4412-1-git-send-email-robdclark@gmail.com> References: <1385390858-4412-1-git-send-email-robdclark@gmail.com> MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: dri-devel-bounces@lists.freedesktop.org Errors-To: dri-devel-bounces@lists.freedesktop.org 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, RP_MATCHES_RCVD, T_DKIM_INVALID, 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 5142599..8180499 100644 --- a/drivers/gpu/drm/drm_crtc.c +++ b/drivers/gpu/drm/drm_crtc.c @@ -3506,6 +3506,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, @@ -3513,20 +3526,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)