drm: Fix drm_mode_attachmode_crtc()
authorVille Syrjälä <ville.syrjala@linux.intel.com>
Tue, 13 Mar 2012 10:35:46 +0000 (12:35 +0200)
committerDave Airlie <airlied@redhat.com>
Thu, 15 Mar 2012 09:51:42 +0000 (09:51 +0000)
Change drm_mode_attachmode_crtc() to take an "all or nothing" approach.
If an error is returned, there are no side effects visible.

Also change the function to always duplicate the mode passed in.

Also change the function to not give up when it finds the first
connector without and encoder.

A simpler approach would be to just remove the function completely as
it's unused currently.

Signed-off-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
Reviewed-by: Alex Deucher <alexander.deucher@amd.com>
Signed-off-by: Dave Airlie <airlied@redhat.com>
drivers/gpu/drm/drm_crtc.c
include/drm/drm_crtc.h

index 3f5c603f9a2cca249ffffcecc1188b74a70cf0fb..37d34ad3a0b82b089bb3d714382f67e09bd096f8 100644 (file)
@@ -2421,24 +2421,40 @@ static void drm_mode_attachmode(struct drm_device *dev,
 }
 
 int drm_mode_attachmode_crtc(struct drm_device *dev, struct drm_crtc *crtc,
-                            struct drm_display_mode *mode)
+                            const struct drm_display_mode *mode)
 {
        struct drm_connector *connector;
-       struct drm_display_mode *dup_mode;
-       int need_dup = 0;
+       int ret = 0;
+       struct drm_display_mode *dup_mode, *next;
+       LIST_HEAD(list);
+
        list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
                if (!connector->encoder)
-                       break;
+                       continue;
                if (connector->encoder->crtc == crtc) {
-                       if (need_dup)
-                               dup_mode = drm_mode_duplicate(dev, mode);
-                       else
-                               dup_mode = mode;
-                       drm_mode_attachmode(dev, connector, dup_mode);
-                       need_dup = 1;
+                       dup_mode = drm_mode_duplicate(dev, mode);
+                       if (!dup_mode) {
+                               ret = -ENOMEM;
+                               goto out;
+                       }
+                       list_add_tail(&dup_mode->head, &list);
                }
        }
-       return 0;
+
+       list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
+               if (!connector->encoder)
+                       continue;
+               if (connector->encoder->crtc == crtc)
+                       list_move_tail(list.next, &connector->user_modes);
+       }
+
+       WARN_ON(!list_empty(&list));
+
+ out:
+       list_for_each_entry_safe(dup_mode, next, &list, head)
+               drm_mode_destroy(dev, dup_mode);
+
+       return ret;
 }
 EXPORT_SYMBOL(drm_mode_attachmode_crtc);
 
index 31715bd4f42a1d1d88614668d9b40ef3aa69f319..fe7ebc6b8c93f304e90bfe290307ef44268aecc1 100644 (file)
@@ -869,7 +869,7 @@ extern int drm_mode_height(struct drm_display_mode *mode);
 /* for us by fb module */
 extern int drm_mode_attachmode_crtc(struct drm_device *dev,
                                    struct drm_crtc *crtc,
-                                   struct drm_display_mode *mode);
+                                   const struct drm_display_mode *mode);
 extern int drm_mode_detachmode_crtc(struct drm_device *dev, struct drm_display_mode *mode);
 
 extern struct drm_display_mode *drm_mode_create(struct drm_device *dev);