aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
Diffstat (limited to 'drivers')
-rw-r--r--drivers/char/drm/drm_sysfs.c43
1 files changed, 35 insertions, 8 deletions
diff --git a/drivers/char/drm/drm_sysfs.c b/drivers/char/drm/drm_sysfs.c
index 51ad98c685c3..ba4b8de83cf0 100644
--- a/drivers/char/drm/drm_sysfs.c
+++ b/drivers/char/drm/drm_sysfs.c
@@ -42,13 +42,24 @@ static CLASS_ATTR(version, S_IRUGO, version_show, NULL);
42struct class *drm_sysfs_create(struct module *owner, char *name) 42struct class *drm_sysfs_create(struct module *owner, char *name)
43{ 43{
44 struct class *class; 44 struct class *class;
45 int err;
45 46
46 class = class_create(owner, name); 47 class = class_create(owner, name);
47 if (!class) 48 if (!class) {
48 return class; 49 err = -ENOMEM;
50 goto err_out;
51 }
52
53 err = class_create_file(class, &class_attr_version);
54 if (err)
55 goto err_out_class;
49 56
50 class_create_file(class, &class_attr_version);
51 return class; 57 return class;
58
59err_out_class:
60 class_destroy(class);
61err_out:
62 return ERR_PTR(err);
52} 63}
53 64
54/** 65/**
@@ -96,20 +107,36 @@ static struct class_device_attribute class_device_attrs[] = {
96struct class_device *drm_sysfs_device_add(struct class *cs, drm_head_t *head) 107struct class_device *drm_sysfs_device_add(struct class *cs, drm_head_t *head)
97{ 108{
98 struct class_device *class_dev; 109 struct class_device *class_dev;
99 int i; 110 int i, j, err;
100 111
101 class_dev = class_device_create(cs, NULL, 112 class_dev = class_device_create(cs, NULL,
102 MKDEV(DRM_MAJOR, head->minor), 113 MKDEV(DRM_MAJOR, head->minor),
103 &(head->dev->pdev)->dev, 114 &(head->dev->pdev)->dev,
104 "card%d", head->minor); 115 "card%d", head->minor);
105 if (!class_dev) 116 if (!class_dev) {
106 return NULL; 117 err = -ENOMEM;
118 goto err_out;
119 }
107 120
108 class_set_devdata(class_dev, head); 121 class_set_devdata(class_dev, head);
109 122
110 for (i = 0; i < ARRAY_SIZE(class_device_attrs); i++) 123 for (i = 0; i < ARRAY_SIZE(class_device_attrs); i++) {
111 class_device_create_file(class_dev, &class_device_attrs[i]); 124 err = class_device_create_file(class_dev,
125 &class_device_attrs[i]);
126 if (err)
127 goto err_out_files;
128 }
129
112 return class_dev; 130 return class_dev;
131
132err_out_files:
133 if (i > 0)
134 for (j = 0; j < i; j++)
135 class_device_remove_file(class_dev,
136 &class_device_attrs[i]);
137 class_device_unregister(class_dev);
138err_out:
139 return ERR_PTR(err);
113} 140}
114 141
115/** 142/**