aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMaarten Lankhorst <maarten.lankhorst@linux.intel.com>2016-09-08 06:30:01 -0400
committerSean Paul <seanpaul@chromium.org>2016-09-12 10:32:49 -0400
commitf92f053bb60924297afb8a1bd9166712c0fe5e88 (patch)
tree36757ced97dcccda57022260ccc53c96e9945f8a
parentd25a4cbba4b9da7c2d674b2f8ecf84af1b24988e (diff)
drm: Move property validation to a helper, v2.
Property lifetimes are equal to the device lifetime, so the separate drm_property_find is not needed. The pointer can be retrieved from the properties member, which saves us some locking and a extra lookup. The lifetime for properties is until the device is destroyed, which happens late in the device unload path. kms_atomic is also testing for invalid properties which returns -ENOENT, to be consistent return -ENOENT for valid properties that don't appear on the object property list. Changes since v1: - Return -ENOENT for invalid properties to make kms_atomic pass. - Change commit message slightly to take this into account. Testcase: kms_atomic Testcase: kms_properties Fixes: 4e9951d96093 ("drm/atomic: Reject properties not part of the object.") Suggested-by: Ville Syrjälä <ville.syrjala@linux.intel.com> Signed-off-by: Maarten Lankhorst <maarten.lankhorst@linux.intel.com> Signed-off-by: Sean Paul <seanpaul@chromium.org> Link: http://patchwork.freedesktop.org/patch/msgid/599c7fa8-b6fd-a42b-c619-a9e4a9c5c244@linux.intel.com
-rw-r--r--drivers/gpu/drm/drm_atomic.c13
-rw-r--r--drivers/gpu/drm/drm_crtc_internal.h2
-rw-r--r--drivers/gpu/drm/drm_mode_object.c31
3 files changed, 20 insertions, 26 deletions
diff --git a/drivers/gpu/drm/drm_atomic.c b/drivers/gpu/drm/drm_atomic.c
index a5126e5c05ee..904d29c012ad 100644
--- a/drivers/gpu/drm/drm_atomic.c
+++ b/drivers/gpu/drm/drm_atomic.c
@@ -1609,7 +1609,7 @@ int drm_mode_atomic_ioctl(struct drm_device *dev,
1609 struct drm_crtc_state *crtc_state; 1609 struct drm_crtc_state *crtc_state;
1610 unsigned plane_mask; 1610 unsigned plane_mask;
1611 int ret = 0; 1611 int ret = 0;
1612 unsigned int i, j, k; 1612 unsigned int i, j;
1613 1613
1614 /* disallow for drivers not supporting atomic: */ 1614 /* disallow for drivers not supporting atomic: */
1615 if (!drm_core_check_feature(dev, DRIVER_ATOMIC)) 1615 if (!drm_core_check_feature(dev, DRIVER_ATOMIC))
@@ -1691,16 +1691,7 @@ retry:
1691 goto out; 1691 goto out;
1692 } 1692 }
1693 1693
1694 for (k = 0; k < obj->properties->count; k++) 1694 prop = drm_mode_obj_find_prop_id(obj, prop_id);
1695 if (obj->properties->properties[k]->base.id == prop_id)
1696 break;
1697
1698 if (k == obj->properties->count) {
1699 ret = -EINVAL;
1700 goto out;
1701 }
1702
1703 prop = drm_property_find(dev, prop_id);
1704 if (!prop) { 1695 if (!prop) {
1705 drm_mode_object_unreference(obj); 1696 drm_mode_object_unreference(obj);
1706 ret = -ENOENT; 1697 ret = -ENOENT;
diff --git a/drivers/gpu/drm/drm_crtc_internal.h b/drivers/gpu/drm/drm_crtc_internal.h
index a3622644bccf..444e609078cc 100644
--- a/drivers/gpu/drm/drm_crtc_internal.h
+++ b/drivers/gpu/drm/drm_crtc_internal.h
@@ -115,6 +115,8 @@ int drm_mode_object_get_properties(struct drm_mode_object *obj, bool atomic,
115 uint32_t __user *prop_ptr, 115 uint32_t __user *prop_ptr,
116 uint64_t __user *prop_values, 116 uint64_t __user *prop_values,
117 uint32_t *arg_count_props); 117 uint32_t *arg_count_props);
118struct drm_property *drm_mode_obj_find_prop_id(struct drm_mode_object *obj,
119 uint32_t prop_id);
118 120
119/* IOCTL */ 121/* IOCTL */
120 122
diff --git a/drivers/gpu/drm/drm_mode_object.c b/drivers/gpu/drm/drm_mode_object.c
index 6edda8382a4c..9f17085b1fdd 100644
--- a/drivers/gpu/drm/drm_mode_object.c
+++ b/drivers/gpu/drm/drm_mode_object.c
@@ -372,14 +372,25 @@ out:
372 return ret; 372 return ret;
373} 373}
374 374
375struct drm_property *drm_mode_obj_find_prop_id(struct drm_mode_object *obj,
376 uint32_t prop_id)
377{
378 int i;
379
380 for (i = 0; i < obj->properties->count; i++)
381 if (obj->properties->properties[i]->base.id == prop_id)
382 return obj->properties->properties[i];
383
384 return NULL;
385}
386
375int drm_mode_obj_set_property_ioctl(struct drm_device *dev, void *data, 387int drm_mode_obj_set_property_ioctl(struct drm_device *dev, void *data,
376 struct drm_file *file_priv) 388 struct drm_file *file_priv)
377{ 389{
378 struct drm_mode_obj_set_property *arg = data; 390 struct drm_mode_obj_set_property *arg = data;
379 struct drm_mode_object *arg_obj; 391 struct drm_mode_object *arg_obj;
380 struct drm_mode_object *prop_obj;
381 struct drm_property *property; 392 struct drm_property *property;
382 int i, ret = -EINVAL; 393 int ret = -EINVAL;
383 struct drm_mode_object *ref; 394 struct drm_mode_object *ref;
384 395
385 if (!drm_core_check_feature(dev, DRIVER_MODESET)) 396 if (!drm_core_check_feature(dev, DRIVER_MODESET))
@@ -392,23 +403,13 @@ int drm_mode_obj_set_property_ioctl(struct drm_device *dev, void *data,
392 ret = -ENOENT; 403 ret = -ENOENT;
393 goto out; 404 goto out;
394 } 405 }
395 if (!arg_obj->properties)
396 goto out_unref;
397
398 for (i = 0; i < arg_obj->properties->count; i++)
399 if (arg_obj->properties->properties[i]->base.id == arg->prop_id)
400 break;
401 406
402 if (i == arg_obj->properties->count) 407 if (!arg_obj->properties)
403 goto out_unref; 408 goto out_unref;
404 409
405 prop_obj = drm_mode_object_find(dev, arg->prop_id, 410 property = drm_mode_obj_find_prop_id(arg_obj, arg->prop_id);
406 DRM_MODE_OBJECT_PROPERTY); 411 if (!property)
407 if (!prop_obj) {
408 ret = -ENOENT;
409 goto out_unref; 412 goto out_unref;
410 }
411 property = obj_to_property(prop_obj);
412 413
413 if (!drm_property_change_valid_get(property, arg->value, &ref)) 414 if (!drm_property_change_valid_get(property, arg->value, &ref))
414 goto out_unref; 415 goto out_unref;