[PATCH 1/3] drm: add drm_property_change_is_valid

2012-01-16 Thread Paulo Zanoni
From: Paulo Zanoni 

Move code from drm_mode_connector_property_set_ioctl to a new
function, so we can reuse this code when we add crtc properties.

Signed-off-by: Paulo Zanoni 
---
 drivers/gpu/drm/drm_crtc.c |   41 +
 1 files changed, 21 insertions(+), 20 deletions(-)

diff --git a/drivers/gpu/drm/drm_crtc.c b/drivers/gpu/drm/drm_crtc.c
index 5e818a8..cd155e9 100644
--- a/drivers/gpu/drm/drm_crtc.c
+++ b/drivers/gpu/drm/drm_crtc.c
@@ -2917,6 +2917,26 @@ int drm_mode_connector_update_edid_property(struct 
drm_connector *connector,
 }
 EXPORT_SYMBOL(drm_mode_connector_update_edid_property);

+static int drm_property_change_is_valid(struct drm_property *property,
+   __u64 value)
+{
+   if (property->flags & DRM_MODE_PROP_IMMUTABLE)
+   return 0;
+   if (property->flags & DRM_MODE_PROP_RANGE) {
+   if (value < property->values[0])
+   return 0;
+   if (value > property->values[1])
+   return 0;
+   return 1;
+   } else {
+   int i;
+   for (i = 0; i < property->num_values; i++)
+   if (property->values[i] == value)
+   return 1;
+   return 0;
+   }
+}
+
 int drm_mode_connector_property_set_ioctl(struct drm_device *dev,
   void *data, struct drm_file *file_priv)
 {
@@ -2953,28 +2973,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)
-- 
1.7.8.3



[PATCH 1/3] drm: add drm_property_change_is_valid

2012-01-16 Thread Paulo Zanoni
From: Paulo Zanoni paulo.r.zan...@intel.com

Move code from drm_mode_connector_property_set_ioctl to a new
function, so we can reuse this code when we add crtc properties.

Signed-off-by: Paulo Zanoni paulo.r.zan...@intel.com
---
 drivers/gpu/drm/drm_crtc.c |   41 +
 1 files changed, 21 insertions(+), 20 deletions(-)

diff --git a/drivers/gpu/drm/drm_crtc.c b/drivers/gpu/drm/drm_crtc.c
index 5e818a8..cd155e9 100644
--- a/drivers/gpu/drm/drm_crtc.c
+++ b/drivers/gpu/drm/drm_crtc.c
@@ -2917,6 +2917,26 @@ int drm_mode_connector_update_edid_property(struct 
drm_connector *connector,
 }
 EXPORT_SYMBOL(drm_mode_connector_update_edid_property);
 
+static int drm_property_change_is_valid(struct drm_property *property,
+   __u64 value)
+{
+   if (property-flags  DRM_MODE_PROP_IMMUTABLE)
+   return 0;
+   if (property-flags  DRM_MODE_PROP_RANGE) {
+   if (value  property-values[0])
+   return 0;
+   if (value  property-values[1])
+   return 0;
+   return 1;
+   } else {
+   int i;
+   for (i = 0; i  property-num_values; i++)
+   if (property-values[i] == value)
+   return 1;
+   return 0;
+   }
+}
+
 int drm_mode_connector_property_set_ioctl(struct drm_device *dev,
   void *data, struct drm_file *file_priv)
 {
@@ -2953,28 +2973,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)
-- 
1.7.8.3

___
dri-devel mailing list
dri-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/dri-devel