From patchwork Wed Nov 20 20:48:08 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Rob Clark X-Patchwork-Id: 3215461 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 3C8DC9F26C for ; Wed, 20 Nov 2013 20:49:01 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 6CE142076C for ; Wed, 20 Nov 2013 20:49:00 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id 9F1AA20752 for ; Wed, 20 Nov 2013 20:48:59 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id E2483105A66; Wed, 20 Nov 2013 12:48:52 -0800 (PST) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-qe0-f44.google.com (mail-qe0-f44.google.com [209.85.128.44]) by gabe.freedesktop.org (Postfix) with ESMTP id DCCEBFD428 for ; Wed, 20 Nov 2013 12:48:44 -0800 (PST) Received: by mail-qe0-f44.google.com with SMTP id b10so683720qen.3 for ; Wed, 20 Nov 2013 12:48:44 -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=TpzHD8wAtvAGsYA8E1wy95AfQrcxxMSiPSpb5rNYkTM=; b=Ve9XMJhF8OFsCOOvsuG4iYLHqfYOw+EokDcaLRN5jSQwDigDGA8P0NndfDqGo/kSji Ruhc36JzJs4WZkcqua9XYh+ZvH3ospP7RkBoDX4meThrSurRABM/nMQG0T74hQ1WLqHg PIqXNEjQ7AeWeh/EGwwcN/iob9nT45vym8jm1qYaI5YI9E9FclZzC0anlgZr+vZsvkg5 S0szTo7r6JjWq3tF4zxsjpNWRQk+smsTemW1DqMrNRFCTHb5ZUx9pmEgh9fn8xOWZusZ 3XFFdUoluNSo7aleqFtL6cmI1/u2NAUsUfcUd+68qvWDr0qJpcitq//oreLP8rhF6o/I 7+hQ== X-Received: by 10.224.94.8 with SMTP id x8mr5196856qam.1.1384980524436; Wed, 20 Nov 2013 12:48:44 -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 r5sm68729775qaj.13.2013.11.20.12.48.43 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 20 Nov 2013 12:48:43 -0800 (PST) From: Rob Clark To: dri-devel@lists.freedesktop.org Subject: [RFCv3 09/14] drm: Refactor object property check code Date: Wed, 20 Nov 2013 15:48:08 -0500 Message-Id: <1384980493-25499-10-git-send-email-robdclark@gmail.com> X-Mailer: git-send-email 1.8.4.2 In-Reply-To: <1384980493-25499-1-git-send-email-robdclark@gmail.com> References: <1384980493-25499-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.6 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 8fc2ab4..2f8ab02 100644 --- a/drivers/gpu/drm/drm_crtc.c +++ b/drivers/gpu/drm/drm_crtc.c @@ -3427,6 +3427,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, @@ -3435,20 +3448,10 @@ static int drm_mode_set_obj_prop_id(struct drm_device *dev, void *state, struct drm_mode_object *arg_obj; struct drm_mode_object *prop_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; prop_obj = drm_mode_object_find(dev, prop_id, DRM_MODE_OBJECT_PROPERTY);