drm: add drm_property_change_is_valid
authorPaulo Zanoni <paulo.r.zanoni@intel.com>
Tue, 15 May 2012 21:08:59 +0000 (18:08 -0300)
committerDave Airlie <airlied@redhat.com>
Thu, 17 May 2012 10:10:55 +0000 (11:10 +0100)
Move code from drm_mode_connector_property_set_ioctl to a new
function, so we can reuse this code when we add crtc properties.

Reviewed-by: Eugeni Dodonov <eugeni.dodonov@intel.com>
Reviewed-by: Rob Clark <rob.clark@linaro.org>
Tested-by: Rob Clark <rob.clark@linaro.org>
Signed-off-by: Paulo Zanoni <paulo.r.zanoni@intel.com>
Signed-off-by: Dave Airlie <airlied@redhat.com>
drivers/gpu/drm/drm_crtc.c

index ee63a123235cf3b632f73ab0b02c2368cc7ef987..0a22ef80d28e4318ebbf10b0b22734adf0cce00b 100644 (file)
@@ -3074,6 +3074,24 @@ int drm_mode_connector_update_edid_property(struct drm_connector *connector,
 }
 EXPORT_SYMBOL(drm_mode_connector_update_edid_property);
 
+static bool drm_property_change_is_valid(struct drm_property *property,
+                                        __u64 value)
+{
+       if (property->flags & DRM_MODE_PROP_IMMUTABLE)
+               return false;
+       if (property->flags & DRM_MODE_PROP_RANGE) {
+               if (value < property->values[0] || value > property->values[1])
+                       return false;
+               return true;
+       } else {
+               int i;
+               for (i = 0; i < property->num_values; i++)
+                       if (property->values[i] == value)
+                               return true;
+               return false;
+       }
+}
+
 int drm_mode_connector_property_set_ioctl(struct drm_device *dev,
                                       void *data, struct drm_file *file_priv)
 {
@@ -3110,28 +3128,9 @@ int drm_mode_connector_property_set_ioctl(struct drm_device *dev,
        }
        property = obj_to_property(obj);
 
-       if (property->flags & DRM_MODE_PROP_IMMUTABLE)
+       if (!drm_property_change_is_valid(property, out_resp->value))
                goto out;
 
-       if (property->flags & DRM_MODE_PROP_RANGE) {
-               if (out_resp->value < property->values[0])
-                       goto out;
-
-               if (out_resp->value > property->values[1])
-                       goto out;
-       } else {
-               int found = 0;
-               for (i = 0; i < property->num_values; i++) {
-                       if (property->values[i] == out_resp->value) {
-                               found = 1;
-                               break;
-                       }
-               }
-               if (!found) {
-                       goto out;
-               }
-       }
-
        /* Do DPMS ourselves */
        if (property == connector->dev->mode_config.dpms_property) {
                if (connector->funcs->dpms)