Commit 7f88a9be authored by Paulo Zanoni's avatar Paulo Zanoni Committed by Dave Airlie

drm: add 'count' to struct drm_object_properties

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: default avatarRob Clark <rob.clark@linaro.org>
Tested-by: default avatarRob Clark <rob.clark@linaro.org>
Signed-off-by: default avatarPaulo Zanoni <paulo.r.zanoni@intel.com>
Signed-off-by: default avatarDave Airlie <airlied@redhat.com>
parent 0057d8dd
...@@ -1425,11 +1425,7 @@ int drm_mode_getconnector(struct drm_device *dev, void *data, ...@@ -1425,11 +1425,7 @@ int drm_mode_getconnector(struct drm_device *dev, void *data,
} }
connector = obj_to_connector(obj); connector = obj_to_connector(obj);
for (i = 0; i < DRM_OBJECT_MAX_PROPERTY; i++) { props_count = connector->properties.count;
if (connector->properties.ids[i] != 0) {
props_count++;
}
}
for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++) { for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++) {
if (connector->encoder_ids[i] != 0) { if (connector->encoder_ids[i] != 0) {
...@@ -1482,8 +1478,7 @@ int drm_mode_getconnector(struct drm_device *dev, void *data, ...@@ -1482,8 +1478,7 @@ int drm_mode_getconnector(struct drm_device *dev, void *data,
copied = 0; copied = 0;
prop_ptr = (uint32_t __user *)(unsigned long)(out_resp->props_ptr); prop_ptr = (uint32_t __user *)(unsigned long)(out_resp->props_ptr);
prop_values = (uint64_t __user *)(unsigned long)(out_resp->prop_values_ptr); prop_values = (uint64_t __user *)(unsigned long)(out_resp->prop_values_ptr);
for (i = 0; i < DRM_OBJECT_MAX_PROPERTY; i++) { for (i = 0; i < connector->properties.count; i++) {
if (connector->properties.ids[i] != 0) {
if (put_user(connector->properties.ids[i], if (put_user(connector->properties.ids[i],
prop_ptr + copied)) { prop_ptr + copied)) {
ret = -EFAULT; ret = -EFAULT;
...@@ -1498,7 +1493,6 @@ int drm_mode_getconnector(struct drm_device *dev, void *data, ...@@ -1498,7 +1493,6 @@ int drm_mode_getconnector(struct drm_device *dev, void *data,
copied++; copied++;
} }
} }
}
out_resp->count_props = props_count; out_resp->count_props = props_count;
if ((out_resp->count_encoders >= encoders_count) && encoders_count) { if ((out_resp->count_encoders >= encoders_count) && encoders_count) {
...@@ -2845,19 +2839,19 @@ void drm_object_attach_property(struct drm_mode_object *obj, ...@@ -2845,19 +2839,19 @@ void drm_object_attach_property(struct drm_mode_object *obj,
struct drm_property *property, struct drm_property *property,
uint64_t init_val) uint64_t init_val)
{ {
int i; int count = obj->properties->count;
for (i = 0; i < DRM_OBJECT_MAX_PROPERTY; i++) { if (count == DRM_OBJECT_MAX_PROPERTY) {
if (obj->properties->ids[i] == 0) { WARN(1, "Failed to attach object property (type: 0x%x). Please "
obj->properties->ids[i] = property->base.id; "increase DRM_OBJECT_MAX_PROPERTY by 1 for each time "
obj->properties->values[i] = init_val; "you see this message on the same object type.\n",
obj->type);
return; return;
} }
}
WARN(1, "Failed to attach object property (type: 0x%x). Please " obj->properties->ids[count] = property->base.id;
"increase DRM_OBJECT_MAX_PROPERTY by 1 for each time you see " obj->properties->values[count] = init_val;
"this message on the same object type.\n", obj->type); obj->properties->count++;
} }
EXPORT_SYMBOL(drm_object_attach_property); EXPORT_SYMBOL(drm_object_attach_property);
...@@ -2866,7 +2860,7 @@ int drm_object_property_set_value(struct drm_mode_object *obj, ...@@ -2866,7 +2860,7 @@ int drm_object_property_set_value(struct drm_mode_object *obj,
{ {
int i; 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) { if (obj->properties->ids[i] == property->base.id) {
obj->properties->values[i] = val; obj->properties->values[i] = val;
return 0; return 0;
...@@ -2882,7 +2876,7 @@ int drm_object_property_get_value(struct drm_mode_object *obj, ...@@ -2882,7 +2876,7 @@ int drm_object_property_get_value(struct drm_mode_object *obj,
{ {
int i; 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) { if (obj->properties->ids[i] == property->base.id) {
*val = obj->properties->values[i]; *val = obj->properties->values[i];
return 0; return 0;
...@@ -3174,11 +3168,7 @@ int drm_mode_obj_get_properties_ioctl(struct drm_device *dev, void *data, ...@@ -3174,11 +3168,7 @@ int drm_mode_obj_get_properties_ioctl(struct drm_device *dev, void *data,
goto out; goto out;
} }
/* Assume [ prop, 0, prop ] won't happen (if we ever delete properties, props_count = obj->properties->count;
* 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++)
;
/* This ioctl is called twice, once to determine how much space is /* This ioctl is called twice, once to determine how much space is
* needed, and the 2nd time to fill it. */ * 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, ...@@ -3228,11 +3218,11 @@ int drm_mode_obj_set_property_ioctl(struct drm_device *dev, void *data,
if (!arg_obj->properties) if (!arg_obj->properties)
goto out; 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) if (arg_obj->properties->ids[i] == arg->prop_id)
break; break;
if (i == DRM_OBJECT_MAX_PROPERTY) if (i == arg_obj->properties->count)
goto out; goto out;
prop_obj = drm_mode_object_find(dev, arg->prop_id, prop_obj = drm_mode_object_find(dev, arg->prop_id,
......
...@@ -56,6 +56,7 @@ struct drm_mode_object { ...@@ -56,6 +56,7 @@ struct drm_mode_object {
#define DRM_OBJECT_MAX_PROPERTY 16 #define DRM_OBJECT_MAX_PROPERTY 16
struct drm_object_properties { struct drm_object_properties {
int count;
uint32_t ids[DRM_OBJECT_MAX_PROPERTY]; uint32_t ids[DRM_OBJECT_MAX_PROPERTY];
uint64_t values[DRM_OBJECT_MAX_PROPERTY]; uint64_t values[DRM_OBJECT_MAX_PROPERTY];
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment