Commit fcc90213 authored by David Herrmann's avatar David Herrmann Committed by Daniel Vetter

drm: move drm_class into drm_sysfs.c

Right now, drm_sysfs_create() returns the newly allocated "struct class"
to the caller (which is drm_core_init()), which then has to set the
global variable 'drm_class'. During cleanup, though, we call
drm_sysfs_destroy() which implicitly uses the global 'drm_class'. This is
confusing, as ownership of the global 'drm_class' is non-obvious.

This patch changes drm_sysfs_create() to drm_sysfs_init() and makes it
initialize the 'drm_class' object directly, rather than returning it.
This way, both drm_sysfs_init() and drm_sysfs_destroy() work in a similar
fashion and manage the global drm class.
Signed-off-by: default avatarDavid Herrmann <dh.herrmann@gmail.com>
Signed-off-by: default avatarDaniel Vetter <daniel.vetter@ffwll.ch>
parent 26b91ae4
...@@ -55,7 +55,6 @@ module_param_named(debug, drm_debug, int, 0600); ...@@ -55,7 +55,6 @@ module_param_named(debug, drm_debug, int, 0600);
static DEFINE_SPINLOCK(drm_minor_lock); static DEFINE_SPINLOCK(drm_minor_lock);
static struct idr drm_minors_idr; static struct idr drm_minors_idr;
struct class *drm_class;
static struct dentry *drm_debugfs_root; static struct dentry *drm_debugfs_root;
void drm_err(const char *format, ...) void drm_err(const char *format, ...)
...@@ -841,10 +840,9 @@ static int __init drm_core_init(void) ...@@ -841,10 +840,9 @@ static int __init drm_core_init(void)
if (register_chrdev(DRM_MAJOR, "drm", &drm_stub_fops)) if (register_chrdev(DRM_MAJOR, "drm", &drm_stub_fops))
goto err_p1; goto err_p1;
drm_class = drm_sysfs_create(THIS_MODULE, "drm"); ret = drm_sysfs_init();
if (IS_ERR(drm_class)) { if (ret < 0) {
printk(KERN_ERR "DRM: Error creating drm class.\n"); printk(KERN_ERR "DRM: Error creating drm class.\n");
ret = PTR_ERR(drm_class);
goto err_p2; goto err_p2;
} }
......
...@@ -73,7 +73,7 @@ int drm_authmagic(struct drm_device *dev, void *data, ...@@ -73,7 +73,7 @@ int drm_authmagic(struct drm_device *dev, void *data,
/* drm_sysfs.c */ /* drm_sysfs.c */
extern struct class *drm_class; extern struct class *drm_class;
struct class *drm_sysfs_create(struct module *owner, char *name); int drm_sysfs_init(void);
void drm_sysfs_destroy(void); void drm_sysfs_destroy(void);
struct device *drm_sysfs_minor_alloc(struct drm_minor *minor); struct device *drm_sysfs_minor_alloc(struct drm_minor *minor);
int drm_sysfs_connector_add(struct drm_connector *connector); int drm_sysfs_connector_add(struct drm_connector *connector);
......
...@@ -30,6 +30,8 @@ static struct device_type drm_sysfs_device_minor = { ...@@ -30,6 +30,8 @@ static struct device_type drm_sysfs_device_minor = {
.name = "drm_minor" .name = "drm_minor"
}; };
struct class *drm_class;
/** /**
* __drm_class_suspend - internal DRM class suspend routine * __drm_class_suspend - internal DRM class suspend routine
* @dev: Linux device to suspend * @dev: Linux device to suspend
...@@ -112,41 +114,34 @@ static CLASS_ATTR_STRING(version, S_IRUGO, ...@@ -112,41 +114,34 @@ static CLASS_ATTR_STRING(version, S_IRUGO,
CORE_DATE); CORE_DATE);
/** /**
* drm_sysfs_create - create a struct drm_sysfs_class structure * drm_sysfs_init - initialize sysfs helpers
* @owner: pointer to the module that is to "own" this struct drm_sysfs_class *
* @name: pointer to a string for the name of this class. * This is used to create the DRM class, which is the implicit parent of any
* other top-level DRM sysfs objects.
* *
* This is used to create DRM class pointer that can then be used * You must call drm_sysfs_destroy() to release the allocated resources.
* in calls to drm_sysfs_device_add().
* *
* Note, the pointer created here is to be destroyed when finished by making a * Return: 0 on success, negative error code on failure.
* call to drm_sysfs_destroy().
*/ */
struct class *drm_sysfs_create(struct module *owner, char *name) int drm_sysfs_init(void)
{ {
struct class *class;
int err; int err;
class = class_create(owner, name); drm_class = class_create(THIS_MODULE, "drm");
if (IS_ERR(class)) { if (IS_ERR(drm_class))
err = PTR_ERR(class); return PTR_ERR(drm_class);
goto err_out;
}
class->pm = &drm_class_dev_pm_ops;
err = class_create_file(class, &class_attr_version.attr); drm_class->pm = &drm_class_dev_pm_ops;
if (err)
goto err_out_class;
class->devnode = drm_devnode; err = class_create_file(drm_class, &class_attr_version.attr);
if (err) {
return class; class_destroy(drm_class);
drm_class = NULL;
return err;
}
err_out_class: drm_class->devnode = drm_devnode;
class_destroy(class); return 0;
err_out:
return ERR_PTR(err);
} }
/** /**
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment