From patchwork Fri Mar 29 02:39:29 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Simon Horman X-Patchwork-Id: 2360551 Return-Path: X-Original-To: patchwork-ltsi-dev@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from mail.linuxfoundation.org (mail.linuxfoundation.org [140.211.169.12]) by patchwork2.kernel.org (Postfix) with ESMTP id DB088DF2A1 for ; Fri, 29 Mar 2013 02:47:05 +0000 (UTC) Received: from mail.linux-foundation.org (localhost [IPv6:::1]) by mail.linuxfoundation.org (Postfix) with ESMTP id 758D3B25; Fri, 29 Mar 2013 02:45:46 +0000 (UTC) X-Original-To: ltsi-dev@lists.linuxfoundation.org Delivered-To: ltsi-dev@mail.linuxfoundation.org Received: from smtp1.linuxfoundation.org (smtp1.linux-foundation.org [172.17.192.35]) by mail.linuxfoundation.org (Postfix) with ESMTP id F16E3B03 for ; Fri, 29 Mar 2013 02:45:42 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from kirsty.vergenet.net (kirsty.vergenet.net [202.4.237.240]) by smtp1.linuxfoundation.org (Postfix) with ESMTP id 8BBD120177 for ; Fri, 29 Mar 2013 02:45:37 +0000 (UTC) Received: from ayumi.akashicho.tokyo.vergenet.net (p8120-ipbfp1001kobeminato.hyogo.ocn.ne.jp [118.10.137.120]) by kirsty.vergenet.net (Postfix) with ESMTP id 3E57B26717B; Fri, 29 Mar 2013 13:45:32 +1100 (EST) Received: by ayumi.akashicho.tokyo.vergenet.net (Postfix, from userid 7100) id 14026EDEA2C; Fri, 29 Mar 2013 11:45:29 +0900 (JST) From: Simon Horman To: ltsi-dev@lists.linuxfoundation.org Date: Fri, 29 Mar 2013 11:39:29 +0900 Message-Id: <1364525119-31791-41-git-send-email-horms+renesas@verge.net.au> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1364525119-31791-1-git-send-email-horms+renesas@verge.net.au> References: <1364525119-31791-1-git-send-email-horms+renesas@verge.net.au> MIME-Version: 1.0 X-Spam-Status: No, score=-3.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_LOW, RP_MATCHES_RCVD autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on smtp1.linux-foundation.org Cc: Magnus Damm Subject: [LTSI-dev] [PATCH/RFC 040/390] drm: add 'count' to struct drm_object_properties X-BeenThere: ltsi-dev@lists.linuxfoundation.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: "A list to discuss patches, development, and other things related to the LTSI project" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: ltsi-dev-bounces@lists.linuxfoundation.org Errors-To: ltsi-dev-bounces@lists.linuxfoundation.org From: Paulo Zanoni This way, we don't need to count every time, so we're a little bit faster and code is a little bit smaller. Change suggested by Ville Syrjälä. Reviewed-by: Rob Clark Tested-by: Rob Clark Signed-off-by: Paulo Zanoni Signed-off-by: Dave Airlie (cherry picked from commit 7f88a9bedfb814a2d4d537db8295c524298256cb) Signed-off-by: Simon Horman --- drivers/gpu/drm/drm_crtc.c | 64 +++++++++++++++++++------------------------- include/drm/drm_crtc.h | 1 + 2 files changed, 28 insertions(+), 37 deletions(-) diff --git a/drivers/gpu/drm/drm_crtc.c b/drivers/gpu/drm/drm_crtc.c index 7bed4a5..571eefa 100644 --- a/drivers/gpu/drm/drm_crtc.c +++ b/drivers/gpu/drm/drm_crtc.c @@ -1425,11 +1425,7 @@ int drm_mode_getconnector(struct drm_device *dev, void *data, } connector = obj_to_connector(obj); - for (i = 0; i < DRM_OBJECT_MAX_PROPERTY; i++) { - if (connector->properties.ids[i] != 0) { - props_count++; - } - } + props_count = connector->properties.count; for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++) { if (connector->encoder_ids[i] != 0) { @@ -1482,21 +1478,19 @@ int drm_mode_getconnector(struct drm_device *dev, void *data, copied = 0; prop_ptr = (uint32_t __user *)(unsigned long)(out_resp->props_ptr); prop_values = (uint64_t __user *)(unsigned long)(out_resp->prop_values_ptr); - for (i = 0; i < DRM_OBJECT_MAX_PROPERTY; i++) { - if (connector->properties.ids[i] != 0) { - if (put_user(connector->properties.ids[i], - prop_ptr + copied)) { - ret = -EFAULT; - goto out; - } + for (i = 0; i < connector->properties.count; i++) { + if (put_user(connector->properties.ids[i], + prop_ptr + copied)) { + ret = -EFAULT; + goto out; + } - if (put_user(connector->properties.values[i], - prop_values + copied)) { - ret = -EFAULT; - goto out; - } - copied++; + if (put_user(connector->properties.values[i], + prop_values + copied)) { + ret = -EFAULT; + goto out; } + copied++; } } out_resp->count_props = props_count; @@ -2845,19 +2839,19 @@ void drm_object_attach_property(struct drm_mode_object *obj, struct drm_property *property, uint64_t init_val) { - int i; + int count = obj->properties->count; - for (i = 0; i < DRM_OBJECT_MAX_PROPERTY; i++) { - if (obj->properties->ids[i] == 0) { - obj->properties->ids[i] = property->base.id; - obj->properties->values[i] = init_val; - return; - } + if (count == DRM_OBJECT_MAX_PROPERTY) { + WARN(1, "Failed to attach object property (type: 0x%x). Please " + "increase DRM_OBJECT_MAX_PROPERTY by 1 for each time " + "you see this message on the same object type.\n", + obj->type); + return; } - WARN(1, "Failed to attach object property (type: 0x%x). Please " - "increase DRM_OBJECT_MAX_PROPERTY by 1 for each time you see " - "this message on the same object type.\n", obj->type); + obj->properties->ids[count] = property->base.id; + obj->properties->values[count] = init_val; + obj->properties->count++; } EXPORT_SYMBOL(drm_object_attach_property); @@ -2866,7 +2860,7 @@ int drm_object_property_set_value(struct drm_mode_object *obj, { int i; - for (i = 0; i < DRM_OBJECT_MAX_PROPERTY; i++) { + for (i = 0; i < obj->properties->count; i++) { if (obj->properties->ids[i] == property->base.id) { obj->properties->values[i] = val; return 0; @@ -2882,7 +2876,7 @@ int drm_object_property_get_value(struct drm_mode_object *obj, { int i; - for (i = 0; i < DRM_OBJECT_MAX_PROPERTY; i++) { + for (i = 0; i < obj->properties->count; i++) { if (obj->properties->ids[i] == property->base.id) { *val = obj->properties->values[i]; return 0; @@ -3174,11 +3168,7 @@ int drm_mode_obj_get_properties_ioctl(struct drm_device *dev, void *data, goto out; } - /* Assume [ prop, 0, prop ] won't happen (if we ever delete properties, - * we need to remove the gap inside the array). */ - for (props_count = 0; props_count < DRM_OBJECT_MAX_PROPERTY && - obj->properties->ids[props_count] != 0; props_count++) - ; + props_count = obj->properties->count; /* This ioctl is called twice, once to determine how much space is * needed, and the 2nd time to fill it. */ @@ -3228,11 +3218,11 @@ int drm_mode_obj_set_property_ioctl(struct drm_device *dev, void *data, if (!arg_obj->properties) goto out; - for (i = 0; i < DRM_OBJECT_MAX_PROPERTY; i++) + for (i = 0; i < arg_obj->properties->count; i++) if (arg_obj->properties->ids[i] == arg->prop_id) break; - if (i == DRM_OBJECT_MAX_PROPERTY) + if (i == arg_obj->properties->count) goto out; prop_obj = drm_mode_object_find(dev, arg->prop_id, diff --git a/include/drm/drm_crtc.h b/include/drm/drm_crtc.h index b0c3249..6d36552 100644 --- a/include/drm/drm_crtc.h +++ b/include/drm/drm_crtc.h @@ -56,6 +56,7 @@ struct drm_mode_object { #define DRM_OBJECT_MAX_PROPERTY 16 struct drm_object_properties { + int count; uint32_t ids[DRM_OBJECT_MAX_PROPERTY]; uint64_t values[DRM_OBJECT_MAX_PROPERTY]; };