blob: 5667c2f02c51b2249fdac0d69fc7fd0a8fe4dfd0 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * class.c - basic device class management
3 *
4 * Copyright (c) 2002-3 Patrick Mochel
5 * Copyright (c) 2002-3 Open Source Development Labs
6 * Copyright (c) 2003-2004 Greg Kroah-Hartman
7 * Copyright (c) 2003-2004 IBM Corp.
8 *
9 * This file is released under the GPLv2
10 *
11 */
12
Linus Torvalds1da177e2005-04-16 15:20:36 -070013#include <linux/device.h>
14#include <linux/module.h>
15#include <linux/init.h>
16#include <linux/string.h>
17#include <linux/kdev_t.h>
gregkh@suse.dee9ba6362005-03-15 11:54:21 -080018#include <linux/err.h>
Tim Schmielau4e57b682005-10-30 15:03:48 -080019#include <linux/slab.h>
Kay Sieversedfaa7c2007-05-21 22:08:01 +020020#include <linux/genhd.h>
Dave Youngf75b1c62008-05-28 09:28:39 -070021#include <linux/mutex.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070022#include "base.h"
23
24#define to_class_attr(_attr) container_of(_attr, struct class_attribute, attr)
Linus Torvalds1da177e2005-04-16 15:20:36 -070025
Greg Kroah-Hartman4a3ad202008-01-24 22:50:12 -080026static ssize_t class_attr_show(struct kobject *kobj, struct attribute *attr,
27 char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -070028{
Greg Kroah-Hartman4a3ad202008-01-24 22:50:12 -080029 struct class_attribute *class_attr = to_class_attr(attr);
Greg Kroah-Hartman7c714482008-01-22 18:17:41 -050030 struct class_private *cp = to_class(kobj);
Dmitry Torokhov4a0c20b2005-04-29 01:23:47 -050031 ssize_t ret = -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -070032
33 if (class_attr->show)
Greg Kroah-Hartman7c714482008-01-22 18:17:41 -050034 ret = class_attr->show(cp->class, buf);
Linus Torvalds1da177e2005-04-16 15:20:36 -070035 return ret;
36}
37
Greg Kroah-Hartman4a3ad202008-01-24 22:50:12 -080038static ssize_t class_attr_store(struct kobject *kobj, struct attribute *attr,
39 const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -070040{
Greg Kroah-Hartman4a3ad202008-01-24 22:50:12 -080041 struct class_attribute *class_attr = to_class_attr(attr);
Greg Kroah-Hartman7c714482008-01-22 18:17:41 -050042 struct class_private *cp = to_class(kobj);
Dmitry Torokhov4a0c20b2005-04-29 01:23:47 -050043 ssize_t ret = -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -070044
45 if (class_attr->store)
Greg Kroah-Hartman7c714482008-01-22 18:17:41 -050046 ret = class_attr->store(cp->class, buf, count);
Linus Torvalds1da177e2005-04-16 15:20:36 -070047 return ret;
48}
49
Greg Kroah-Hartman4a3ad202008-01-24 22:50:12 -080050static void class_release(struct kobject *kobj)
Linus Torvalds1da177e2005-04-16 15:20:36 -070051{
Greg Kroah-Hartman7c714482008-01-22 18:17:41 -050052 struct class_private *cp = to_class(kobj);
53 struct class *class = cp->class;
Linus Torvalds1da177e2005-04-16 15:20:36 -070054
55 pr_debug("class '%s': release.\n", class->name);
56
57 if (class->class_release)
58 class->class_release(class);
59 else
60 pr_debug("class '%s' does not have a release() function, "
61 "be careful\n", class->name);
62}
63
64static struct sysfs_ops class_sysfs_ops = {
65 .show = class_attr_show,
66 .store = class_attr_store,
67};
68
Greg Kroah-Hartmanadc56802007-10-11 10:47:49 -060069static struct kobj_type class_ktype = {
Linus Torvalds1da177e2005-04-16 15:20:36 -070070 .sysfs_ops = &class_sysfs_ops,
71 .release = class_release,
72};
73
Greg Kroah-Hartman1fbfee62008-05-28 09:28:39 -070074/* Hotplug events for classes go to the class class_subsys */
Greg Kroah-Hartman443dbf92007-10-29 23:22:26 -050075static struct kset *class_kset;
Linus Torvalds1da177e2005-04-16 15:20:36 -070076
77
Greg Kroah-Hartman4a3ad202008-01-24 22:50:12 -080078int class_create_file(struct class *cls, const struct class_attribute *attr)
Linus Torvalds1da177e2005-04-16 15:20:36 -070079{
80 int error;
Greg Kroah-Hartman4a3ad202008-01-24 22:50:12 -080081 if (cls)
Greg Kroah-Hartman1fbfee62008-05-28 09:28:39 -070082 error = sysfs_create_file(&cls->p->class_subsys.kobj,
83 &attr->attr);
Greg Kroah-Hartman4a3ad202008-01-24 22:50:12 -080084 else
Linus Torvalds1da177e2005-04-16 15:20:36 -070085 error = -EINVAL;
86 return error;
87}
88
Greg Kroah-Hartman4a3ad202008-01-24 22:50:12 -080089void class_remove_file(struct class *cls, const struct class_attribute *attr)
Linus Torvalds1da177e2005-04-16 15:20:36 -070090{
91 if (cls)
Greg Kroah-Hartman1fbfee62008-05-28 09:28:39 -070092 sysfs_remove_file(&cls->p->class_subsys.kobj, &attr->attr);
Linus Torvalds1da177e2005-04-16 15:20:36 -070093}
94
Greg Kroah-Hartman17407572006-05-02 16:59:59 +020095static struct class *class_get(struct class *cls)
Linus Torvalds1da177e2005-04-16 15:20:36 -070096{
97 if (cls)
Greg Kroah-Hartman1fbfee62008-05-28 09:28:39 -070098 kset_get(&cls->p->class_subsys);
Greg Kroah-Hartman7c714482008-01-22 18:17:41 -050099 return cls;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100}
101
Greg Kroah-Hartman4a3ad202008-01-24 22:50:12 -0800102static void class_put(struct class *cls)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103{
Greg Kroah-Hartman51d172d2005-10-27 22:25:43 -0700104 if (cls)
Greg Kroah-Hartman1fbfee62008-05-28 09:28:39 -0700105 kset_put(&cls->p->class_subsys);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106}
107
Greg Kroah-Hartman4a3ad202008-01-24 22:50:12 -0800108static int add_class_attrs(struct class *cls)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109{
110 int i;
111 int error = 0;
112
113 if (cls->class_attrs) {
114 for (i = 0; attr_name(cls->class_attrs[i]); i++) {
Greg Kroah-Hartman4a3ad202008-01-24 22:50:12 -0800115 error = class_create_file(cls, &cls->class_attrs[i]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116 if (error)
Greg Kroah-Hartman4a3ad202008-01-24 22:50:12 -0800117 goto error;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118 }
119 }
Greg Kroah-Hartman4a3ad202008-01-24 22:50:12 -0800120done:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121 return error;
Greg Kroah-Hartman4a3ad202008-01-24 22:50:12 -0800122error:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123 while (--i >= 0)
Greg Kroah-Hartman4a3ad202008-01-24 22:50:12 -0800124 class_remove_file(cls, &cls->class_attrs[i]);
125 goto done;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126}
127
Greg Kroah-Hartman4a3ad202008-01-24 22:50:12 -0800128static void remove_class_attrs(struct class *cls)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129{
130 int i;
131
132 if (cls->class_attrs) {
133 for (i = 0; attr_name(cls->class_attrs[i]); i++)
Greg Kroah-Hartman4a3ad202008-01-24 22:50:12 -0800134 class_remove_file(cls, &cls->class_attrs[i]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135 }
136}
137
Matthew Wilcoxd2a3b912008-05-28 09:28:39 -0700138int __class_register(struct class *cls, struct lock_class_key *key)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139{
Greg Kroah-Hartman7c714482008-01-22 18:17:41 -0500140 struct class_private *cp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141 int error;
142
143 pr_debug("device class '%s': registering\n", cls->name);
144
Greg Kroah-Hartman7c714482008-01-22 18:17:41 -0500145 cp = kzalloc(sizeof(*cp), GFP_KERNEL);
146 if (!cp)
147 return -ENOMEM;
Greg Kroah-Hartman97ae69f2008-05-28 09:28:39 -0700148 INIT_LIST_HEAD(&cp->class_devices);
Greg Kroah-Hartman184f1f72008-05-28 09:28:39 -0700149 INIT_LIST_HEAD(&cp->class_interfaces);
Greg Kroah-Hartman7c714482008-01-22 18:17:41 -0500150 kset_init(&cp->class_dirs);
Dave Youngf75b1c62008-05-28 09:28:39 -0700151 __mutex_init(&cp->class_mutex, "struct class mutex", key);
Greg Kroah-Hartman1fbfee62008-05-28 09:28:39 -0700152 error = kobject_set_name(&cp->class_subsys.kobj, "%s", cls->name);
Greg Kroah-Hartman7c714482008-01-22 18:17:41 -0500153 if (error) {
154 kfree(cp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155 return error;
Greg Kroah-Hartman7c714482008-01-22 18:17:41 -0500156 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157
Dan Williamse105b8b2008-04-21 10:51:07 -0700158 /* set the default /sys/dev directory for devices of this class */
159 if (!cls->dev_kobj)
160 cls->dev_kobj = sysfs_dev_char_kobj;
161
Greg Kroah-Hartman4e886c22008-01-27 12:12:43 -0800162#if defined(CONFIG_SYSFS_DEPRECATED) && defined(CONFIG_BLOCK)
Kay Sieversedfaa7c2007-05-21 22:08:01 +0200163 /* let the block class directory show up in the root of sysfs */
164 if (cls != &block_class)
Greg Kroah-Hartman1fbfee62008-05-28 09:28:39 -0700165 cp->class_subsys.kobj.kset = class_kset;
Kay Sieversedfaa7c2007-05-21 22:08:01 +0200166#else
Greg Kroah-Hartman1fbfee62008-05-28 09:28:39 -0700167 cp->class_subsys.kobj.kset = class_kset;
Kay Sieversedfaa7c2007-05-21 22:08:01 +0200168#endif
Greg Kroah-Hartman1fbfee62008-05-28 09:28:39 -0700169 cp->class_subsys.kobj.ktype = &class_ktype;
Greg Kroah-Hartman7c714482008-01-22 18:17:41 -0500170 cp->class = cls;
171 cls->p = cp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172
Greg Kroah-Hartman1fbfee62008-05-28 09:28:39 -0700173 error = kset_register(&cp->class_subsys);
Greg Kroah-Hartman7c714482008-01-22 18:17:41 -0500174 if (error) {
175 kfree(cp);
176 return error;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177 }
Greg Kroah-Hartman7c714482008-01-22 18:17:41 -0500178 error = add_class_attrs(class_get(cls));
179 class_put(cls);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180 return error;
181}
Matthew Wilcoxd2a3b912008-05-28 09:28:39 -0700182EXPORT_SYMBOL_GPL(__class_register);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700183
Greg Kroah-Hartman4a3ad202008-01-24 22:50:12 -0800184void class_unregister(struct class *cls)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700185{
186 pr_debug("device class '%s': unregistering\n", cls->name);
187 remove_class_attrs(cls);
Greg Kroah-Hartman1fbfee62008-05-28 09:28:39 -0700188 kset_unregister(&cls->p->class_subsys);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189}
190
gregkh@suse.dee9ba6362005-03-15 11:54:21 -0800191static void class_create_release(struct class *cls)
192{
Harvey Harrison2b3a3022008-03-04 16:41:05 -0800193 pr_debug("%s called for %s\n", __func__, cls->name);
gregkh@suse.dee9ba6362005-03-15 11:54:21 -0800194 kfree(cls);
195}
196
gregkh@suse.de2fc68442005-03-23 10:02:56 -0800197/**
198 * class_create - create a struct class structure
199 * @owner: pointer to the module that is to "own" this struct class
200 * @name: pointer to a string for the name of this class.
Randy Dunlap0e241ff2008-07-24 16:58:42 -0700201 * @key: the lock_class_key for this class; used by mutex lock debugging
gregkh@suse.de2fc68442005-03-23 10:02:56 -0800202 *
203 * This is used to create a struct class pointer that can then be used
Kay Sieversc3b19ff2008-03-12 20:47:35 +0100204 * in calls to device_create().
gregkh@suse.de2fc68442005-03-23 10:02:56 -0800205 *
206 * Note, the pointer created here is to be destroyed when finished by
207 * making a call to class_destroy().
208 */
Matthew Wilcoxd2a3b912008-05-28 09:28:39 -0700209struct class *__class_create(struct module *owner, const char *name,
210 struct lock_class_key *key)
gregkh@suse.dee9ba6362005-03-15 11:54:21 -0800211{
212 struct class *cls;
213 int retval;
214
Jiri Slaby4aed0642005-09-13 01:25:01 -0700215 cls = kzalloc(sizeof(*cls), GFP_KERNEL);
gregkh@suse.dee9ba6362005-03-15 11:54:21 -0800216 if (!cls) {
217 retval = -ENOMEM;
218 goto error;
219 }
gregkh@suse.dee9ba6362005-03-15 11:54:21 -0800220
221 cls->name = name;
222 cls->owner = owner;
223 cls->class_release = class_create_release;
gregkh@suse.dee9ba6362005-03-15 11:54:21 -0800224
Matthew Wilcoxd2a3b912008-05-28 09:28:39 -0700225 retval = __class_register(cls, key);
gregkh@suse.dee9ba6362005-03-15 11:54:21 -0800226 if (retval)
227 goto error;
228
229 return cls;
230
231error:
232 kfree(cls);
233 return ERR_PTR(retval);
234}
Matthew Wilcoxd2a3b912008-05-28 09:28:39 -0700235EXPORT_SYMBOL_GPL(__class_create);
gregkh@suse.dee9ba6362005-03-15 11:54:21 -0800236
gregkh@suse.de2fc68442005-03-23 10:02:56 -0800237/**
238 * class_destroy - destroys a struct class structure
Rolf Eike Beer92a0f862006-09-29 01:59:13 -0700239 * @cls: pointer to the struct class that is to be destroyed
gregkh@suse.de2fc68442005-03-23 10:02:56 -0800240 *
241 * Note, the pointer to be destroyed must have been created with a call
242 * to class_create().
243 */
gregkh@suse.dee9ba6362005-03-15 11:54:21 -0800244void class_destroy(struct class *cls)
245{
246 if ((cls == NULL) || (IS_ERR(cls)))
247 return;
248
249 class_unregister(cls);
250}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700251
Kay Sievers805fab42006-09-14 11:23:28 +0200252#ifdef CONFIG_SYSFS_DEPRECATED
253char *make_class_name(const char *name, struct kobject *kobj)
254{
255 char *class_name;
256 int size;
257
258 size = strlen(name) + strlen(kobject_name(kobj)) + 2;
259
260 class_name = kmalloc(size, GFP_KERNEL);
261 if (!class_name)
Cornelia Huckcb360bb2006-11-27 10:35:05 +0100262 return NULL;
Kay Sievers805fab42006-09-14 11:23:28 +0200263
264 strcpy(class_name, name);
265 strcat(class_name, ":");
266 strcat(class_name, kobject_name(kobj));
267 return class_name;
268}
Kay Sievers805fab42006-09-14 11:23:28 +0200269#endif
270
Dave Youngfd048972008-01-22 15:27:08 +0800271/**
272 * class_for_each_device - device iterator
273 * @class: the class we're iterating
Greg Kroah-Hartman93562b52008-05-22 17:21:08 -0400274 * @start: the device to start with in the list, if any.
Dave Youngfd048972008-01-22 15:27:08 +0800275 * @data: data for the callback
276 * @fn: function to be called for each device
277 *
278 * Iterate over @class's list of devices, and call @fn for each,
Greg Kroah-Hartman93562b52008-05-22 17:21:08 -0400279 * passing it @data. If @start is set, the list iteration will start
280 * there, otherwise if it is NULL, the iteration starts at the
281 * beginning of the list.
Dave Youngfd048972008-01-22 15:27:08 +0800282 *
283 * We check the return of @fn each time. If it returns anything
284 * other than 0, we break out and return that value.
285 *
Dave Youngf75b1c62008-05-28 09:28:39 -0700286 * Note, we hold class->class_mutex in this function, so it can not be
Dave Youngfd048972008-01-22 15:27:08 +0800287 * re-acquired in @fn, otherwise it will self-deadlocking. For
288 * example, calls to add or remove class members would be verboten.
289 */
Greg Kroah-Hartman93562b52008-05-22 17:21:08 -0400290int class_for_each_device(struct class *class, struct device *start,
291 void *data, int (*fn)(struct device *, void *))
Dave Youngfd048972008-01-22 15:27:08 +0800292{
293 struct device *dev;
294 int error = 0;
295
296 if (!class)
297 return -EINVAL;
Dave Youngf75b1c62008-05-28 09:28:39 -0700298 mutex_lock(&class->p->class_mutex);
Greg Kroah-Hartman97ae69f2008-05-28 09:28:39 -0700299 list_for_each_entry(dev, &class->p->class_devices, node) {
Greg Kroah-Hartman93562b52008-05-22 17:21:08 -0400300 if (start) {
301 if (start == dev)
302 start = NULL;
303 continue;
304 }
Dave Youngfd048972008-01-22 15:27:08 +0800305 dev = get_device(dev);
Greg Kroah-Hartman93562b52008-05-22 17:21:08 -0400306 error = fn(dev, data);
307 put_device(dev);
Dave Youngfd048972008-01-22 15:27:08 +0800308 if (error)
309 break;
310 }
Dave Youngf75b1c62008-05-28 09:28:39 -0700311 mutex_unlock(&class->p->class_mutex);
Dave Youngfd048972008-01-22 15:27:08 +0800312
313 return error;
314}
315EXPORT_SYMBOL_GPL(class_for_each_device);
316
317/**
318 * class_find_device - device iterator for locating a particular device
319 * @class: the class we're iterating
Greg Kroah-Hartman695794a2008-05-22 17:21:08 -0400320 * @start: Device to begin with
Dave Youngfd048972008-01-22 15:27:08 +0800321 * @data: data for the match function
322 * @match: function to check device
323 *
324 * This is similar to the class_for_each_dev() function above, but it
325 * returns a reference to a device that is 'found' for later use, as
326 * determined by the @match callback.
327 *
328 * The callback should return 0 if the device doesn't match and non-zero
329 * if it does. If the callback returns non-zero, this function will
330 * return to the caller and not iterate over any more devices.
Randy Dunlapa63ca8f2008-01-30 11:51:08 -0800331 *
Dave Youngfd048972008-01-22 15:27:08 +0800332 * Note, you will need to drop the reference with put_device() after use.
333 *
Dave Youngf75b1c62008-05-28 09:28:39 -0700334 * We hold class->class_mutex in this function, so it can not be
Dave Youngfd048972008-01-22 15:27:08 +0800335 * re-acquired in @match, otherwise it will self-deadlocking. For
336 * example, calls to add or remove class members would be verboten.
337 */
Greg Kroah-Hartman695794a2008-05-22 17:21:08 -0400338struct device *class_find_device(struct class *class, struct device *start,
339 void *data,
340 int (*match)(struct device *, void *))
Dave Youngfd048972008-01-22 15:27:08 +0800341{
342 struct device *dev;
343 int found = 0;
344
345 if (!class)
346 return NULL;
347
Dave Youngf75b1c62008-05-28 09:28:39 -0700348 mutex_lock(&class->p->class_mutex);
Greg Kroah-Hartman97ae69f2008-05-28 09:28:39 -0700349 list_for_each_entry(dev, &class->p->class_devices, node) {
Greg Kroah-Hartman695794a2008-05-22 17:21:08 -0400350 if (start) {
351 if (start == dev)
352 start = NULL;
353 continue;
354 }
Dave Youngfd048972008-01-22 15:27:08 +0800355 dev = get_device(dev);
Greg Kroah-Hartman695794a2008-05-22 17:21:08 -0400356 if (match(dev, data)) {
357 found = 1;
Dave Youngfd048972008-01-22 15:27:08 +0800358 break;
Greg Kroah-Hartman695794a2008-05-22 17:21:08 -0400359 } else
360 put_device(dev);
Dave Youngfd048972008-01-22 15:27:08 +0800361 }
Dave Youngf75b1c62008-05-28 09:28:39 -0700362 mutex_unlock(&class->p->class_mutex);
Dave Youngfd048972008-01-22 15:27:08 +0800363
364 return found ? dev : NULL;
365}
366EXPORT_SYMBOL_GPL(class_find_device);
367
Linus Torvalds1da177e2005-04-16 15:20:36 -0700368int class_interface_register(struct class_interface *class_intf)
369{
370 struct class *parent;
Greg Kroah-Hartmanc47ed212006-09-13 15:34:05 +0200371 struct device *dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700372
373 if (!class_intf || !class_intf->class)
374 return -ENODEV;
375
376 parent = class_get(class_intf->class);
377 if (!parent)
378 return -EINVAL;
379
Dave Youngf75b1c62008-05-28 09:28:39 -0700380 mutex_lock(&parent->p->class_mutex);
Greg Kroah-Hartman184f1f72008-05-28 09:28:39 -0700381 list_add_tail(&class_intf->node, &parent->p->class_interfaces);
Greg Kroah-Hartmanc47ed212006-09-13 15:34:05 +0200382 if (class_intf->add_dev) {
Greg Kroah-Hartman97ae69f2008-05-28 09:28:39 -0700383 list_for_each_entry(dev, &parent->p->class_devices, node)
Greg Kroah-Hartmanc47ed212006-09-13 15:34:05 +0200384 class_intf->add_dev(dev, class_intf);
385 }
Dave Youngf75b1c62008-05-28 09:28:39 -0700386 mutex_unlock(&parent->p->class_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700387
388 return 0;
389}
390
391void class_interface_unregister(struct class_interface *class_intf)
392{
Greg Kroah-Hartman4a3ad202008-01-24 22:50:12 -0800393 struct class *parent = class_intf->class;
Greg Kroah-Hartmanc47ed212006-09-13 15:34:05 +0200394 struct device *dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700395
396 if (!parent)
397 return;
398
Dave Youngf75b1c62008-05-28 09:28:39 -0700399 mutex_lock(&parent->p->class_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700400 list_del_init(&class_intf->node);
Greg Kroah-Hartmanc47ed212006-09-13 15:34:05 +0200401 if (class_intf->remove_dev) {
Greg Kroah-Hartman97ae69f2008-05-28 09:28:39 -0700402 list_for_each_entry(dev, &parent->p->class_devices, node)
Greg Kroah-Hartmanc47ed212006-09-13 15:34:05 +0200403 class_intf->remove_dev(dev, class_intf);
404 }
Dave Youngf75b1c62008-05-28 09:28:39 -0700405 mutex_unlock(&parent->p->class_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700406
407 class_put(parent);
408}
409
Linus Torvalds1da177e2005-04-16 15:20:36 -0700410int __init classes_init(void)
411{
Greg Kroah-Hartman443dbf92007-10-29 23:22:26 -0500412 class_kset = kset_create_and_add("class", NULL, NULL);
413 if (!class_kset)
414 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700415 return 0;
416}
417
418EXPORT_SYMBOL_GPL(class_create_file);
419EXPORT_SYMBOL_GPL(class_remove_file);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700420EXPORT_SYMBOL_GPL(class_unregister);
gregkh@suse.dee9ba6362005-03-15 11:54:21 -0800421EXPORT_SYMBOL_GPL(class_destroy);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700422
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423EXPORT_SYMBOL_GPL(class_interface_register);
424EXPORT_SYMBOL_GPL(class_interface_unregister);