summaryrefslogtreecommitdiff
path: root/drivers/gpu/drm/drm_stub.c
diff options
context:
space:
mode:
authorDavid Herrmann <dh.herrmann@gmail.com>2014-07-23 11:38:38 +0200
committerDavid Herrmann <dh.herrmann@gmail.com>2014-08-05 16:08:21 +0200
commite17280758cc0b4f3d7065554006adcb87448f6c0 (patch)
tree71641f392c6ab39518ac56b2efa4763e7f5ecdd8 /drivers/gpu/drm/drm_stub.c
parentf1b8596283f681b82546d6302bc7c372fdb2d422 (diff)
drm: make sysfs device always available for minors
For each minor we allocate a sysfs device as minor->kdev. Currently, this is allocated and registered in drm_minor_register(). This makes it impossible to add sysfs-attributes to the device before it is registered. Therefore, they are not added atomically, nor can we move device_add() *after* ->load() is called. This patch makes minor->kdev available early, but only adds the device during minor-registration. Note that the registration is still called before ->load() as debugfs needs to be split, too. This will be fixed in follow-ups. Reviewed-by: Daniel Vetter <daniel.vetter@ffwll.ch> Reviewed-by: Alex Deucher <alexander.deucher@amd.com> Signed-off-by: David Herrmann <dh.herrmann@gmail.com>
Diffstat (limited to 'drivers/gpu/drm/drm_stub.c')
-rw-r--r--drivers/gpu/drm/drm_stub.c22
1 files changed, 16 insertions, 6 deletions
diff --git a/drivers/gpu/drm/drm_stub.c b/drivers/gpu/drm/drm_stub.c
index 8b24db51116e..09c6bfb86a66 100644
--- a/drivers/gpu/drm/drm_stub.c
+++ b/drivers/gpu/drm/drm_stub.c
@@ -281,9 +281,19 @@ static int drm_minor_alloc(struct drm_device *dev, unsigned int type)
minor->index = r;
+ minor->kdev = drm_sysfs_minor_alloc(minor);
+ if (IS_ERR(minor->kdev)) {
+ r = PTR_ERR(minor->kdev);
+ goto err_index;
+ }
+
*drm_minor_get_slot(dev, type) = minor;
return 0;
+err_index:
+ spin_lock_irqsave(&drm_minor_lock, flags);
+ idr_remove(&drm_minors_idr, minor->index);
+ spin_unlock_irqrestore(&drm_minor_lock, flags);
err_free:
kfree(minor);
return r;
@@ -300,6 +310,7 @@ static void drm_minor_free(struct drm_device *dev, unsigned int type)
return;
drm_mode_group_destroy(&minor->mode_group);
+ put_device(minor->kdev);
spin_lock_irqsave(&drm_minor_lock, flags);
idr_remove(&drm_minors_idr, minor->index);
@@ -327,11 +338,9 @@ static int drm_minor_register(struct drm_device *dev, unsigned int type)
return ret;
}
- ret = drm_sysfs_device_add(minor);
- if (ret) {
- DRM_ERROR("DRM: Error sysfs_device_add.\n");
+ ret = device_add(minor->kdev);
+ if (ret)
goto err_debugfs;
- }
/* replace NULL with @minor so lookups will succeed from now on */
spin_lock_irqsave(&drm_minor_lock, flags);
@@ -352,7 +361,7 @@ static void drm_minor_unregister(struct drm_device *dev, unsigned int type)
unsigned long flags;
minor = *drm_minor_get_slot(dev, type);
- if (!minor || !minor->kdev)
+ if (!minor || !device_is_registered(minor->kdev))
return;
/* replace @minor with NULL so lookups will fail from now on */
@@ -360,8 +369,9 @@ static void drm_minor_unregister(struct drm_device *dev, unsigned int type)
idr_replace(&drm_minors_idr, NULL, minor->index);
spin_unlock_irqrestore(&drm_minor_lock, flags);
+ device_del(minor->kdev);
+ dev_set_drvdata(minor->kdev, NULL); /* safety belt */
drm_debugfs_cleanup(minor);
- drm_sysfs_device_remove(minor);
}
/**