blob: 839d27cecb36c8acb3bf8e9e4880ba720e6fe53b [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.
201 *
202 * This is used to create a struct class pointer that can then be used
Kay Sieversc3b19ff2008-03-12 20:47:35 +0100203 * in calls to device_create().
gregkh@suse.de2fc68442005-03-23 10:02:56 -0800204 *
205 * Note, the pointer created here is to be destroyed when finished by
206 * making a call to class_destroy().
207 */
Matthew Wilcoxd2a3b912008-05-28 09:28:39 -0700208struct class *__class_create(struct module *owner, const char *name,
209 struct lock_class_key *key)
gregkh@suse.dee9ba6362005-03-15 11:54:21 -0800210{
211 struct class *cls;
212 int retval;
213
Jiri Slaby4aed0642005-09-13 01:25:01 -0700214 cls = kzalloc(sizeof(*cls), GFP_KERNEL);
gregkh@suse.dee9ba6362005-03-15 11:54:21 -0800215 if (!cls) {
216 retval = -ENOMEM;
217 goto error;
218 }
gregkh@suse.dee9ba6362005-03-15 11:54:21 -0800219
220 cls->name = name;
221 cls->owner = owner;
222 cls->class_release = class_create_release;
gregkh@suse.dee9ba6362005-03-15 11:54:21 -0800223
Matthew Wilcoxd2a3b912008-05-28 09:28:39 -0700224 retval = __class_register(cls, key);
gregkh@suse.dee9ba6362005-03-15 11:54:21 -0800225 if (retval)
226 goto error;
227
228 return cls;
229
230error:
231 kfree(cls);
232 return ERR_PTR(retval);
233}
Matthew Wilcoxd2a3b912008-05-28 09:28:39 -0700234EXPORT_SYMBOL_GPL(__class_create);
gregkh@suse.dee9ba6362005-03-15 11:54:21 -0800235
gregkh@suse.de2fc68442005-03-23 10:02:56 -0800236/**
237 * class_destroy - destroys a struct class structure
Rolf Eike Beer92a0f862006-09-29 01:59:13 -0700238 * @cls: pointer to the struct class that is to be destroyed
gregkh@suse.de2fc68442005-03-23 10:02:56 -0800239 *
240 * Note, the pointer to be destroyed must have been created with a call
241 * to class_create().
242 */
gregkh@suse.dee9ba6362005-03-15 11:54:21 -0800243void class_destroy(struct class *cls)
244{
245 if ((cls == NULL) || (IS_ERR(cls)))
246 return;
247
248 class_unregister(cls);
249}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700250
Kay Sievers805fab42006-09-14 11:23:28 +0200251#ifdef CONFIG_SYSFS_DEPRECATED
252char *make_class_name(const char *name, struct kobject *kobj)
253{
254 char *class_name;
255 int size;
256
257 size = strlen(name) + strlen(kobject_name(kobj)) + 2;
258
259 class_name = kmalloc(size, GFP_KERNEL);
260 if (!class_name)
Cornelia Huckcb360bb2006-11-27 10:35:05 +0100261 return NULL;
Kay Sievers805fab42006-09-14 11:23:28 +0200262
263 strcpy(class_name, name);
264 strcat(class_name, ":");
265 strcat(class_name, kobject_name(kobj));
266 return class_name;
267}
Kay Sievers805fab42006-09-14 11:23:28 +0200268#endif
269
Dave Youngfd048972008-01-22 15:27:08 +0800270/**
271 * class_for_each_device - device iterator
272 * @class: the class we're iterating
Greg Kroah-Hartman93562b52008-05-22 17:21:08 -0400273 * @start: the device to start with in the list, if any.
Dave Youngfd048972008-01-22 15:27:08 +0800274 * @data: data for the callback
275 * @fn: function to be called for each device
276 *
277 * Iterate over @class's list of devices, and call @fn for each,
Greg Kroah-Hartman93562b52008-05-22 17:21:08 -0400278 * passing it @data. If @start is set, the list iteration will start
279 * there, otherwise if it is NULL, the iteration starts at the
280 * beginning of the list.
Dave Youngfd048972008-01-22 15:27:08 +0800281 *
282 * We check the return of @fn each time. If it returns anything
283 * other than 0, we break out and return that value.
284 *
Dave Youngf75b1c62008-05-28 09:28:39 -0700285 * Note, we hold class->class_mutex in this function, so it can not be
Dave Youngfd048972008-01-22 15:27:08 +0800286 * re-acquired in @fn, otherwise it will self-deadlocking. For
287 * example, calls to add or remove class members would be verboten.
288 */
Greg Kroah-Hartman93562b52008-05-22 17:21:08 -0400289int class_for_each_device(struct class *class, struct device *start,
290 void *data, int (*fn)(struct device *, void *))
Dave Youngfd048972008-01-22 15:27:08 +0800291{
292 struct device *dev;
293 int error = 0;
294
295 if (!class)
296 return -EINVAL;
Dave Youngf75b1c62008-05-28 09:28:39 -0700297 mutex_lock(&class->p->class_mutex);
Greg Kroah-Hartman97ae69f2008-05-28 09:28:39 -0700298 list_for_each_entry(dev, &class->p->class_devices, node) {
Greg Kroah-Hartman93562b52008-05-22 17:21:08 -0400299 if (start) {
300 if (start == dev)
301 start = NULL;
302 continue;
303 }
Dave Youngfd048972008-01-22 15:27:08 +0800304 dev = get_device(dev);
Greg Kroah-Hartman93562b52008-05-22 17:21:08 -0400305 error = fn(dev, data);
306 put_device(dev);
Dave Youngfd048972008-01-22 15:27:08 +0800307 if (error)
308 break;
309 }
Dave Youngf75b1c62008-05-28 09:28:39 -0700310 mutex_unlock(&class->p->class_mutex);
Dave Youngfd048972008-01-22 15:27:08 +0800311
312 return error;
313}
314EXPORT_SYMBOL_GPL(class_for_each_device);
315
316/**
317 * class_find_device - device iterator for locating a particular device
318 * @class: the class we're iterating
Greg Kroah-Hartman695794a2008-05-22 17:21:08 -0400319 * @start: Device to begin with
Dave Youngfd048972008-01-22 15:27:08 +0800320 * @data: data for the match function
321 * @match: function to check device
322 *
323 * This is similar to the class_for_each_dev() function above, but it
324 * returns a reference to a device that is 'found' for later use, as
325 * determined by the @match callback.
326 *
327 * The callback should return 0 if the device doesn't match and non-zero
328 * if it does. If the callback returns non-zero, this function will
329 * return to the caller and not iterate over any more devices.
Randy Dunlapa63ca8f2008-01-30 11:51:08 -0800330 *
Dave Youngfd048972008-01-22 15:27:08 +0800331 * Note, you will need to drop the reference with put_device() after use.
332 *
Dave Youngf75b1c62008-05-28 09:28:39 -0700333 * We hold class->class_mutex in this function, so it can not be
Dave Youngfd048972008-01-22 15:27:08 +0800334 * re-acquired in @match, otherwise it will self-deadlocking. For
335 * example, calls to add or remove class members would be verboten.
336 */
Greg Kroah-Hartman695794a2008-05-22 17:21:08 -0400337struct device *class_find_device(struct class *class, struct device *start,
338 void *data,
339 int (*match)(struct device *, void *))
Dave Youngfd048972008-01-22 15:27:08 +0800340{
341 struct device *dev;
342 int found = 0;
343
344 if (!class)
345 return NULL;
346
Dave Youngf75b1c62008-05-28 09:28:39 -0700347 mutex_lock(&class->p->class_mutex);
Greg Kroah-Hartman97ae69f2008-05-28 09:28:39 -0700348 list_for_each_entry(dev, &class->p->class_devices, node) {
Greg Kroah-Hartman695794a2008-05-22 17:21:08 -0400349 if (start) {
350 if (start == dev)
351 start = NULL;
352 continue;
353 }
Dave Youngfd048972008-01-22 15:27:08 +0800354 dev = get_device(dev);
Greg Kroah-Hartman695794a2008-05-22 17:21:08 -0400355 if (match(dev, data)) {
356 found = 1;
Dave Youngfd048972008-01-22 15:27:08 +0800357 break;
Greg Kroah-Hartman695794a2008-05-22 17:21:08 -0400358 } else
359 put_device(dev);
Dave Youngfd048972008-01-22 15:27:08 +0800360 }
Dave Youngf75b1c62008-05-28 09:28:39 -0700361 mutex_unlock(&class->p->class_mutex);
Dave Youngfd048972008-01-22 15:27:08 +0800362
363 return found ? dev : NULL;
364}
365EXPORT_SYMBOL_GPL(class_find_device);
366
Linus Torvalds1da177e2005-04-16 15:20:36 -0700367int class_interface_register(struct class_interface *class_intf)
368{
369 struct class *parent;
Greg Kroah-Hartmanc47ed212006-09-13 15:34:05 +0200370 struct device *dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700371
372 if (!class_intf || !class_intf->class)
373 return -ENODEV;
374
375 parent = class_get(class_intf->class);
376 if (!parent)
377 return -EINVAL;
378
Dave Youngf75b1c62008-05-28 09:28:39 -0700379 mutex_lock(&parent->p->class_mutex);
Greg Kroah-Hartman184f1f72008-05-28 09:28:39 -0700380 list_add_tail(&class_intf->node, &parent->p->class_interfaces);
Greg Kroah-Hartmanc47ed212006-09-13 15:34:05 +0200381 if (class_intf->add_dev) {
Greg Kroah-Hartman97ae69f2008-05-28 09:28:39 -0700382 list_for_each_entry(dev, &parent->p->class_devices, node)
Greg Kroah-Hartmanc47ed212006-09-13 15:34:05 +0200383 class_intf->add_dev(dev, class_intf);
384 }
Dave Youngf75b1c62008-05-28 09:28:39 -0700385 mutex_unlock(&parent->p->class_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700386
387 return 0;
388}
389
390void class_interface_unregister(struct class_interface *class_intf)
391{
Greg Kroah-Hartman4a3ad202008-01-24 22:50:12 -0800392 struct class *parent = class_intf->class;
Greg Kroah-Hartmanc47ed212006-09-13 15:34:05 +0200393 struct device *dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700394
395 if (!parent)
396 return;
397
Dave Youngf75b1c62008-05-28 09:28:39 -0700398 mutex_lock(&parent->p->class_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700399 list_del_init(&class_intf->node);
Greg Kroah-Hartmanc47ed212006-09-13 15:34:05 +0200400 if (class_intf->remove_dev) {
Greg Kroah-Hartman97ae69f2008-05-28 09:28:39 -0700401 list_for_each_entry(dev, &parent->p->class_devices, node)
Greg Kroah-Hartmanc47ed212006-09-13 15:34:05 +0200402 class_intf->remove_dev(dev, class_intf);
403 }
Dave Youngf75b1c62008-05-28 09:28:39 -0700404 mutex_unlock(&parent->p->class_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700405
406 class_put(parent);
407}
408
Linus Torvalds1da177e2005-04-16 15:20:36 -0700409int __init classes_init(void)
410{
Greg Kroah-Hartman443dbf92007-10-29 23:22:26 -0500411 class_kset = kset_create_and_add("class", NULL, NULL);
412 if (!class_kset)
413 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700414 return 0;
415}
416
417EXPORT_SYMBOL_GPL(class_create_file);
418EXPORT_SYMBOL_GPL(class_remove_file);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700419EXPORT_SYMBOL_GPL(class_unregister);
gregkh@suse.dee9ba6362005-03-15 11:54:21 -0800420EXPORT_SYMBOL_GPL(class_destroy);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700421
Linus Torvalds1da177e2005-04-16 15:20:36 -0700422EXPORT_SYMBOL_GPL(class_interface_register);
423EXPORT_SYMBOL_GPL(class_interface_unregister);