From patchwork Sat May 24 18:30:18 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Rob Clark X-Patchwork-Id: 4237911 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 07B7C9F3D1 for ; Sat, 24 May 2014 18:31:12 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 3A17520211 for ; Sat, 24 May 2014 18:31:11 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id 6FB932020F for ; Sat, 24 May 2014 18:31:07 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id C6F386E45F; Sat, 24 May 2014 11:31:06 -0700 (PDT) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-qg0-f46.google.com (mail-qg0-f46.google.com [209.85.192.46]) by gabe.freedesktop.org (Postfix) with ESMTP id DBF0E6E467 for ; Sat, 24 May 2014 11:31:02 -0700 (PDT) Received: by mail-qg0-f46.google.com with SMTP id q108so9713350qgd.19 for ; Sat, 24 May 2014 11:31:02 -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=VwoTLDEu+cSfpuCFJMigQNF/7cbMb4WSYK2cTTbawAA=; b=JT/Hlq067JtAsoBpb4X6QNZMefltaDNDsvpRhnqrNR9ANUriZGsgEE6s7Sm5gjk52Q 9HLnfzuuHqT9g6d0JfcSdpFg0pxIRSBhOqFnhUR9WTyb1cOJmLIMqG3NLiGVTBmSGnrX 2Mop2bo+tCaxkEw8UCqVn2YYXyANyYB6GtBOv1/74pqWVu9iQDCpoi38NUC27Xem4Dc7 Ruyz8sJJPJ6DMgYhqmOgW5WxlhF7UNNGQue25ZVnRsH516mGkOkEXzulfu2c5/A+vHOU OYoFbEEkt5msYQftig4+K6kg6P8dV5/RrGcdQQQULVxqmZ+loBi7QmDbDdcqq98pELR6 Ciug== X-Received: by 10.140.88.112 with SMTP id s103mr17145764qgd.113.1400956262511; Sat, 24 May 2014 11:31:02 -0700 (PDT) Received: from localhost (pool-108-20-252-175.bstnma.east.verizon.net. [108.20.252.175]) by mx.google.com with ESMTPSA id s13sm11124287qay.39.2014.05.24.11.31.01 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 24 May 2014 11:31:01 -0700 (PDT) From: Rob Clark To: dri-devel@lists.freedesktop.org Subject: [PATCH 09/17] drm: Refactor object property check code Date: Sat, 24 May 2014 14:30:18 -0400 Message-Id: <1400956226-28053-10-git-send-email-robdclark@gmail.com> X-Mailer: git-send-email 1.9.0 In-Reply-To: <1400956226-28053-1-git-send-email-robdclark@gmail.com> References: <1400956226-28053-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.7 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=ham 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ä Signed-off-by: Rob Clark --- 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 511d33e..9b95601 100644 --- a/drivers/gpu/drm/drm_crtc.c +++ b/drivers/gpu/drm/drm_crtc.c @@ -3901,6 +3901,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, struct drm_atomic_state *state, @@ -3909,20 +3922,10 @@ static int drm_mode_set_obj_prop_id(struct drm_device *dev, { 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)