From patchwork Mon Oct 14 17:26:44 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Rob Clark X-Patchwork-Id: 3038071 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 2CADD9F2B6 for ; Mon, 14 Oct 2013 17:44:39 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 4CB6C2020A for ; Mon, 14 Oct 2013 17:44:38 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id 54CBD2012B for ; Mon, 14 Oct 2013 17:44:37 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 1F767E71BB for ; Mon, 14 Oct 2013 10:44:37 -0700 (PDT) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-qa0-f49.google.com (mail-qa0-f49.google.com [209.85.216.49]) by gabe.freedesktop.org (Postfix) with ESMTP id A4865E7187 for ; Mon, 14 Oct 2013 10:27:14 -0700 (PDT) Received: by mail-qa0-f49.google.com with SMTP id i13so2559391qae.8 for ; Mon, 14 Oct 2013 10:27:14 -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=3WnrKyXGLBWBuZJNVWfVKES6lrrHjm2oSj4VL23U3e0=; b=XvdEycoJCv5dVNdINzcRC5n+eQqkf+wyr+fNi4KNihHvJGgnt4XtZfGBMCPgcOOYGC RqF21CPK92GnqrE1jB9u2N0zsyi6rjWk7lDFWMZy9XSxxpSZz6meUtTf8H+4C0QlxYvo IGvjtvN4QLFzrsbSkwmTjhyQDq6s6WKBY/BdK86vFpn6D7zFDY0oZYRQQNXdWrLszYyC MnTrpidRphhkPH131hee1Qdk6qxBSqN9vS57Aih/PFpHs5HrPG3tFxAD1QxCGI1TIicW 18GhTReW7gwinaejhwC+8As+P1AjzByrLRyptu7dzOZXs6zR3E4bj8WbTWEKCn5sEhMb dOSQ== X-Received: by 10.224.80.4 with SMTP id r4mr15821646qak.69.1381771634319; Mon, 14 Oct 2013 10:27:14 -0700 (PDT) Received: from localhost (nat-pool-bos-t.redhat.com. [66.187.233.206]) by mx.google.com with ESMTPSA id g2sm146083671qaf.12.1969.12.31.16.00.00 (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Mon, 14 Oct 2013 10:27:13 -0700 (PDT) From: Rob Clark To: dri-devel@lists.freedesktop.org Subject: [RFCv2 09/13] drm: Refactor object property check code Date: Mon, 14 Oct 2013 13:26:44 -0400 Message-Id: <1381771608-15237-10-git-send-email-robdclark@gmail.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1381771608-15237-1-git-send-email-robdclark@gmail.com> References: <1381771608-15237-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+patchwork-dri-devel=patchwork.kernel.org@lists.freedesktop.org Errors-To: dri-devel-bounces+patchwork-dri-devel=patchwork.kernel.org@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 | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/drivers/gpu/drm/drm_crtc.c b/drivers/gpu/drm/drm_crtc.c index da641fb..9f46f3b 100644 --- a/drivers/gpu/drm/drm_crtc.c +++ b/drivers/gpu/drm/drm_crtc.c @@ -3375,6 +3375,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, @@ -3383,20 +3396,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) - return -EINVAL; - 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; + if (!(arg_obj && object_has_prop(arg_obj, prop_id))) + return -ENOENT; prop_obj = drm_mode_object_find(dev, prop_id, DRM_MODE_OBJECT_PROPERTY);