From patchwork Sun Oct 6 00:45:46 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Rob Clark X-Patchwork-Id: 2992141 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 EFF889F1C3 for ; Sun, 6 Oct 2013 00:54:59 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 28CA620254 for ; Sun, 6 Oct 2013 00:54:59 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id 5B5172024A for ; Sun, 6 Oct 2013 00:54:58 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 43EF3E62EF for ; Sat, 5 Oct 2013 17:54:58 -0700 (PDT) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-qc0-f178.google.com (mail-qc0-f178.google.com [209.85.216.178]) by gabe.freedesktop.org (Postfix) with ESMTP id E6D57E5EB4 for ; Sat, 5 Oct 2013 17:46:22 -0700 (PDT) Received: by mail-qc0-f178.google.com with SMTP id r5so3875055qcx.9 for ; Sat, 05 Oct 2013 17:46:22 -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=gMh4g9TT1YsxFF/962LTnkEJgtJr8RzKW7Ct13aF3as=; b=er5JV5UDv2kQWy6IqHak3DKaYEosOq/QXOk+7ODvWEvmeX16re+nJJF0A22l+73x3X tOn5TK5Tx88VIQDrderOW2EU4PJFOsBB57YhYflFKHCwdSsKioVJ6MhhRalTpaYYZtmc wekkcYU+vvjoeVtWcUvThWSduF7XwOVjEWMVJSdSL7QFTTrD3uWahEfaIcmad96lrFDj qkh37/Aj/BuFPnJQFsn4IMDEI7WVHFxqUVseD2uDDeTDIyHGI2ONI8lir+tu5WUZ90G2 NmaC+oWDekemHlXDzg+y8LZj23iCIr4FWo8JPN+N/QxS7W8ALh+5tQZskHrNstm+SFb8 eIdw== X-Received: by 10.224.64.74 with SMTP id d10mr28668358qai.62.1381020381971; Sat, 05 Oct 2013 17:46:21 -0700 (PDT) Received: from localhost (pool-108-20-247-120.bstnma.east.verizon.net. [108.20.247.120]) by mx.google.com with ESMTPSA id l4sm45637517qae.4.1969.12.31.16.00.00 (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Sat, 05 Oct 2013 17:46:21 -0700 (PDT) From: Rob Clark To: dri-devel@lists.freedesktop.org Subject: [RFCv1 08/12] drm: Refactor object property check code Date: Sat, 5 Oct 2013 20:45:46 -0400 Message-Id: <1381020350-1125-9-git-send-email-robdclark@gmail.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1381020350-1125-1-git-send-email-robdclark@gmail.com> References: <1381020350-1125-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.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=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 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 c0546e8..776edf3 100644 --- a/drivers/gpu/drm/drm_crtc.c +++ b/drivers/gpu/drm/drm_crtc.c @@ -3374,6 +3374,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, @@ -3382,19 +3395,9 @@ 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) + if (!(arg_obj && object_has_prop(arg_obj, prop_id))) return -EINVAL; prop_obj = drm_mode_object_find(dev, prop_id,