class.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788
  1. /*
  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. #include <linux/config.h>
  13. #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>
  18. #include <linux/err.h>
  19. #include "base.h"
  20. #define to_class_attr(_attr) container_of(_attr, struct class_attribute, attr)
  21. #define to_class(obj) container_of(obj, struct class, subsys.kset.kobj)
  22. static ssize_t
  23. class_attr_show(struct kobject * kobj, struct attribute * attr, char * buf)
  24. {
  25. struct class_attribute * class_attr = to_class_attr(attr);
  26. struct class * dc = to_class(kobj);
  27. ssize_t ret = -EIO;
  28. if (class_attr->show)
  29. ret = class_attr->show(dc, buf);
  30. return ret;
  31. }
  32. static ssize_t
  33. class_attr_store(struct kobject * kobj, struct attribute * attr,
  34. const char * buf, size_t count)
  35. {
  36. struct class_attribute * class_attr = to_class_attr(attr);
  37. struct class * dc = to_class(kobj);
  38. ssize_t ret = -EIO;
  39. if (class_attr->store)
  40. ret = class_attr->store(dc, buf, count);
  41. return ret;
  42. }
  43. static void class_release(struct kobject * kobj)
  44. {
  45. struct class *class = to_class(kobj);
  46. pr_debug("class '%s': release.\n", class->name);
  47. if (class->class_release)
  48. class->class_release(class);
  49. else
  50. pr_debug("class '%s' does not have a release() function, "
  51. "be careful\n", class->name);
  52. }
  53. static struct sysfs_ops class_sysfs_ops = {
  54. .show = class_attr_show,
  55. .store = class_attr_store,
  56. };
  57. static struct kobj_type ktype_class = {
  58. .sysfs_ops = &class_sysfs_ops,
  59. .release = class_release,
  60. };
  61. /* Hotplug events for classes go to the class_obj subsys */
  62. static decl_subsys(class, &ktype_class, NULL);
  63. int class_create_file(struct class * cls, const struct class_attribute * attr)
  64. {
  65. int error;
  66. if (cls) {
  67. error = sysfs_create_file(&cls->subsys.kset.kobj, &attr->attr);
  68. } else
  69. error = -EINVAL;
  70. return error;
  71. }
  72. void class_remove_file(struct class * cls, const struct class_attribute * attr)
  73. {
  74. if (cls)
  75. sysfs_remove_file(&cls->subsys.kset.kobj, &attr->attr);
  76. }
  77. struct class * class_get(struct class * cls)
  78. {
  79. if (cls)
  80. return container_of(subsys_get(&cls->subsys), struct class, subsys);
  81. return NULL;
  82. }
  83. void class_put(struct class * cls)
  84. {
  85. subsys_put(&cls->subsys);
  86. }
  87. static int add_class_attrs(struct class * cls)
  88. {
  89. int i;
  90. int error = 0;
  91. if (cls->class_attrs) {
  92. for (i = 0; attr_name(cls->class_attrs[i]); i++) {
  93. error = class_create_file(cls,&cls->class_attrs[i]);
  94. if (error)
  95. goto Err;
  96. }
  97. }
  98. Done:
  99. return error;
  100. Err:
  101. while (--i >= 0)
  102. class_remove_file(cls,&cls->class_attrs[i]);
  103. goto Done;
  104. }
  105. static void remove_class_attrs(struct class * cls)
  106. {
  107. int i;
  108. if (cls->class_attrs) {
  109. for (i = 0; attr_name(cls->class_attrs[i]); i++)
  110. class_remove_file(cls,&cls->class_attrs[i]);
  111. }
  112. }
  113. int class_register(struct class * cls)
  114. {
  115. int error;
  116. pr_debug("device class '%s': registering\n", cls->name);
  117. INIT_LIST_HEAD(&cls->children);
  118. INIT_LIST_HEAD(&cls->interfaces);
  119. init_MUTEX(&cls->sem);
  120. error = kobject_set_name(&cls->subsys.kset.kobj, "%s", cls->name);
  121. if (error)
  122. return error;
  123. subsys_set_kset(cls, class_subsys);
  124. error = subsystem_register(&cls->subsys);
  125. if (!error) {
  126. error = add_class_attrs(class_get(cls));
  127. class_put(cls);
  128. }
  129. return error;
  130. }
  131. void class_unregister(struct class * cls)
  132. {
  133. pr_debug("device class '%s': unregistering\n", cls->name);
  134. remove_class_attrs(cls);
  135. subsystem_unregister(&cls->subsys);
  136. }
  137. static void class_create_release(struct class *cls)
  138. {
  139. kfree(cls);
  140. }
  141. static void class_device_create_release(struct class_device *class_dev)
  142. {
  143. kfree(class_dev);
  144. }
  145. /**
  146. * class_create - create a struct class structure
  147. * @owner: pointer to the module that is to "own" this struct class
  148. * @name: pointer to a string for the name of this class.
  149. *
  150. * This is used to create a struct class pointer that can then be used
  151. * in calls to class_device_create().
  152. *
  153. * Note, the pointer created here is to be destroyed when finished by
  154. * making a call to class_destroy().
  155. */
  156. struct class *class_create(struct module *owner, char *name)
  157. {
  158. struct class *cls;
  159. int retval;
  160. cls = kmalloc(sizeof(struct class), GFP_KERNEL);
  161. if (!cls) {
  162. retval = -ENOMEM;
  163. goto error;
  164. }
  165. memset(cls, 0x00, sizeof(struct class));
  166. cls->name = name;
  167. cls->owner = owner;
  168. cls->class_release = class_create_release;
  169. cls->release = class_device_create_release;
  170. retval = class_register(cls);
  171. if (retval)
  172. goto error;
  173. return cls;
  174. error:
  175. kfree(cls);
  176. return ERR_PTR(retval);
  177. }
  178. /**
  179. * class_destroy - destroys a struct class structure
  180. * @cs: pointer to the struct class that is to be destroyed
  181. *
  182. * Note, the pointer to be destroyed must have been created with a call
  183. * to class_create().
  184. */
  185. void class_destroy(struct class *cls)
  186. {
  187. if ((cls == NULL) || (IS_ERR(cls)))
  188. return;
  189. class_unregister(cls);
  190. }
  191. /* Class Device Stuff */
  192. int class_device_create_file(struct class_device * class_dev,
  193. const struct class_device_attribute * attr)
  194. {
  195. int error = -EINVAL;
  196. if (class_dev)
  197. error = sysfs_create_file(&class_dev->kobj, &attr->attr);
  198. return error;
  199. }
  200. void class_device_remove_file(struct class_device * class_dev,
  201. const struct class_device_attribute * attr)
  202. {
  203. if (class_dev)
  204. sysfs_remove_file(&class_dev->kobj, &attr->attr);
  205. }
  206. int class_device_create_bin_file(struct class_device *class_dev,
  207. struct bin_attribute *attr)
  208. {
  209. int error = -EINVAL;
  210. if (class_dev)
  211. error = sysfs_create_bin_file(&class_dev->kobj, attr);
  212. return error;
  213. }
  214. void class_device_remove_bin_file(struct class_device *class_dev,
  215. struct bin_attribute *attr)
  216. {
  217. if (class_dev)
  218. sysfs_remove_bin_file(&class_dev->kobj, attr);
  219. }
  220. static ssize_t
  221. class_device_attr_show(struct kobject * kobj, struct attribute * attr,
  222. char * buf)
  223. {
  224. struct class_device_attribute * class_dev_attr = to_class_dev_attr(attr);
  225. struct class_device * cd = to_class_dev(kobj);
  226. ssize_t ret = 0;
  227. if (class_dev_attr->show)
  228. ret = class_dev_attr->show(cd, buf);
  229. return ret;
  230. }
  231. static ssize_t
  232. class_device_attr_store(struct kobject * kobj, struct attribute * attr,
  233. const char * buf, size_t count)
  234. {
  235. struct class_device_attribute * class_dev_attr = to_class_dev_attr(attr);
  236. struct class_device * cd = to_class_dev(kobj);
  237. ssize_t ret = 0;
  238. if (class_dev_attr->store)
  239. ret = class_dev_attr->store(cd, buf, count);
  240. return ret;
  241. }
  242. static struct sysfs_ops class_dev_sysfs_ops = {
  243. .show = class_device_attr_show,
  244. .store = class_device_attr_store,
  245. };
  246. static void class_dev_release(struct kobject * kobj)
  247. {
  248. struct class_device *cd = to_class_dev(kobj);
  249. struct class * cls = cd->class;
  250. pr_debug("device class '%s': release.\n", cd->class_id);
  251. kfree(cd->devt_attr);
  252. cd->devt_attr = NULL;
  253. if (cls->release)
  254. cls->release(cd);
  255. else {
  256. printk(KERN_ERR "Device class '%s' does not have a release() function, "
  257. "it is broken and must be fixed.\n",
  258. cd->class_id);
  259. WARN_ON(1);
  260. }
  261. }
  262. static struct kobj_type ktype_class_device = {
  263. .sysfs_ops = &class_dev_sysfs_ops,
  264. .release = class_dev_release,
  265. };
  266. static int class_hotplug_filter(struct kset *kset, struct kobject *kobj)
  267. {
  268. struct kobj_type *ktype = get_ktype(kobj);
  269. if (ktype == &ktype_class_device) {
  270. struct class_device *class_dev = to_class_dev(kobj);
  271. if (class_dev->class)
  272. return 1;
  273. }
  274. return 0;
  275. }
  276. static const char *class_hotplug_name(struct kset *kset, struct kobject *kobj)
  277. {
  278. struct class_device *class_dev = to_class_dev(kobj);
  279. return class_dev->class->name;
  280. }
  281. static int class_hotplug(struct kset *kset, struct kobject *kobj, char **envp,
  282. int num_envp, char *buffer, int buffer_size)
  283. {
  284. struct class_device *class_dev = to_class_dev(kobj);
  285. int i = 0;
  286. int length = 0;
  287. int retval = 0;
  288. pr_debug("%s - name = %s\n", __FUNCTION__, class_dev->class_id);
  289. if (class_dev->dev) {
  290. /* add physical device, backing this device */
  291. struct device *dev = class_dev->dev;
  292. char *path = kobject_get_path(&dev->kobj, GFP_KERNEL);
  293. add_hotplug_env_var(envp, num_envp, &i, buffer, buffer_size,
  294. &length, "PHYSDEVPATH=%s", path);
  295. kfree(path);
  296. if (dev->bus)
  297. add_hotplug_env_var(envp, num_envp, &i,
  298. buffer, buffer_size, &length,
  299. "PHYSDEVBUS=%s", dev->bus->name);
  300. if (dev->driver)
  301. add_hotplug_env_var(envp, num_envp, &i,
  302. buffer, buffer_size, &length,
  303. "PHYSDEVDRIVER=%s", dev->driver->name);
  304. }
  305. if (MAJOR(class_dev->devt)) {
  306. add_hotplug_env_var(envp, num_envp, &i,
  307. buffer, buffer_size, &length,
  308. "MAJOR=%u", MAJOR(class_dev->devt));
  309. add_hotplug_env_var(envp, num_envp, &i,
  310. buffer, buffer_size, &length,
  311. "MINOR=%u", MINOR(class_dev->devt));
  312. }
  313. /* terminate, set to next free slot, shrink available space */
  314. envp[i] = NULL;
  315. envp = &envp[i];
  316. num_envp -= i;
  317. buffer = &buffer[length];
  318. buffer_size -= length;
  319. if (class_dev->class->hotplug) {
  320. /* have the bus specific function add its stuff */
  321. retval = class_dev->class->hotplug (class_dev, envp, num_envp,
  322. buffer, buffer_size);
  323. if (retval) {
  324. pr_debug ("%s - hotplug() returned %d\n",
  325. __FUNCTION__, retval);
  326. }
  327. }
  328. return retval;
  329. }
  330. static struct kset_hotplug_ops class_hotplug_ops = {
  331. .filter = class_hotplug_filter,
  332. .name = class_hotplug_name,
  333. .hotplug = class_hotplug,
  334. };
  335. static decl_subsys(class_obj, &ktype_class_device, &class_hotplug_ops);
  336. static int class_device_add_attrs(struct class_device * cd)
  337. {
  338. int i;
  339. int error = 0;
  340. struct class * cls = cd->class;
  341. if (cls->class_dev_attrs) {
  342. for (i = 0; attr_name(cls->class_dev_attrs[i]); i++) {
  343. error = class_device_create_file(cd,
  344. &cls->class_dev_attrs[i]);
  345. if (error)
  346. goto Err;
  347. }
  348. }
  349. Done:
  350. return error;
  351. Err:
  352. while (--i >= 0)
  353. class_device_remove_file(cd,&cls->class_dev_attrs[i]);
  354. goto Done;
  355. }
  356. static void class_device_remove_attrs(struct class_device * cd)
  357. {
  358. int i;
  359. struct class * cls = cd->class;
  360. if (cls->class_dev_attrs) {
  361. for (i = 0; attr_name(cls->class_dev_attrs[i]); i++)
  362. class_device_remove_file(cd,&cls->class_dev_attrs[i]);
  363. }
  364. }
  365. static ssize_t show_dev(struct class_device *class_dev, char *buf)
  366. {
  367. return print_dev_t(buf, class_dev->devt);
  368. }
  369. void class_device_initialize(struct class_device *class_dev)
  370. {
  371. kobj_set_kset_s(class_dev, class_obj_subsys);
  372. kobject_init(&class_dev->kobj);
  373. INIT_LIST_HEAD(&class_dev->node);
  374. }
  375. static char *make_class_name(struct class_device *class_dev)
  376. {
  377. char *name;
  378. int size;
  379. size = strlen(class_dev->class->name) +
  380. strlen(kobject_name(&class_dev->kobj)) + 2;
  381. name = kmalloc(size, GFP_KERNEL);
  382. if (!name)
  383. return ERR_PTR(-ENOMEM);
  384. strcpy(name, class_dev->class->name);
  385. strcat(name, ":");
  386. strcat(name, kobject_name(&class_dev->kobj));
  387. return name;
  388. }
  389. int class_device_add(struct class_device *class_dev)
  390. {
  391. struct class * parent = NULL;
  392. struct class_interface * class_intf;
  393. char *class_name = NULL;
  394. int error;
  395. class_dev = class_device_get(class_dev);
  396. if (!class_dev)
  397. return -EINVAL;
  398. if (!strlen(class_dev->class_id)) {
  399. error = -EINVAL;
  400. goto register_done;
  401. }
  402. parent = class_get(class_dev->class);
  403. pr_debug("CLASS: registering class device: ID = '%s'\n",
  404. class_dev->class_id);
  405. /* first, register with generic layer. */
  406. kobject_set_name(&class_dev->kobj, "%s", class_dev->class_id);
  407. if (parent)
  408. class_dev->kobj.parent = &parent->subsys.kset.kobj;
  409. if ((error = kobject_add(&class_dev->kobj)))
  410. goto register_done;
  411. /* add the needed attributes to this device */
  412. if (MAJOR(class_dev->devt)) {
  413. struct class_device_attribute *attr;
  414. attr = kmalloc(sizeof(*attr), GFP_KERNEL);
  415. if (!attr) {
  416. error = -ENOMEM;
  417. kobject_del(&class_dev->kobj);
  418. goto register_done;
  419. }
  420. memset(attr, sizeof(*attr), 0x00);
  421. attr->attr.name = "dev";
  422. attr->attr.mode = S_IRUGO;
  423. attr->attr.owner = parent->owner;
  424. attr->show = show_dev;
  425. attr->store = NULL;
  426. class_device_create_file(class_dev, attr);
  427. class_dev->devt_attr = attr;
  428. }
  429. class_device_add_attrs(class_dev);
  430. if (class_dev->dev) {
  431. class_name = make_class_name(class_dev);
  432. sysfs_create_link(&class_dev->kobj,
  433. &class_dev->dev->kobj, "device");
  434. sysfs_create_link(&class_dev->dev->kobj, &class_dev->kobj,
  435. class_name);
  436. }
  437. /* notify any interfaces this device is now here */
  438. if (parent) {
  439. down(&parent->sem);
  440. list_add_tail(&class_dev->node, &parent->children);
  441. list_for_each_entry(class_intf, &parent->interfaces, node)
  442. if (class_intf->add)
  443. class_intf->add(class_dev);
  444. up(&parent->sem);
  445. }
  446. kobject_hotplug(&class_dev->kobj, KOBJ_ADD);
  447. register_done:
  448. if (error && parent)
  449. class_put(parent);
  450. class_device_put(class_dev);
  451. kfree(class_name);
  452. return error;
  453. }
  454. int class_device_register(struct class_device *class_dev)
  455. {
  456. class_device_initialize(class_dev);
  457. return class_device_add(class_dev);
  458. }
  459. /**
  460. * class_device_create - creates a class device and registers it with sysfs
  461. * @cs: pointer to the struct class that this device should be registered to.
  462. * @dev: the dev_t for the char device to be added.
  463. * @device: a pointer to a struct device that is assiociated with this class device.
  464. * @fmt: string for the class device's name
  465. *
  466. * This function can be used by char device classes. A struct
  467. * class_device will be created in sysfs, registered to the specified
  468. * class. A "dev" file will be created, showing the dev_t for the
  469. * device. The pointer to the struct class_device will be returned from
  470. * the call. Any further sysfs files that might be required can be
  471. * created using this pointer.
  472. *
  473. * Note: the struct class passed to this function must have previously
  474. * been created with a call to class_create().
  475. */
  476. struct class_device *class_device_create(struct class *cls, dev_t devt,
  477. struct device *device, char *fmt, ...)
  478. {
  479. va_list args;
  480. struct class_device *class_dev = NULL;
  481. int retval = -ENODEV;
  482. if (cls == NULL || IS_ERR(cls))
  483. goto error;
  484. class_dev = kmalloc(sizeof(struct class_device), GFP_KERNEL);
  485. if (!class_dev) {
  486. retval = -ENOMEM;
  487. goto error;
  488. }
  489. memset(class_dev, 0x00, sizeof(struct class_device));
  490. class_dev->devt = devt;
  491. class_dev->dev = device;
  492. class_dev->class = cls;
  493. va_start(args, fmt);
  494. vsnprintf(class_dev->class_id, BUS_ID_SIZE, fmt, args);
  495. va_end(args);
  496. retval = class_device_register(class_dev);
  497. if (retval)
  498. goto error;
  499. return class_dev;
  500. error:
  501. kfree(class_dev);
  502. return ERR_PTR(retval);
  503. }
  504. void class_device_del(struct class_device *class_dev)
  505. {
  506. struct class * parent = class_dev->class;
  507. struct class_interface * class_intf;
  508. char *class_name = NULL;
  509. if (parent) {
  510. down(&parent->sem);
  511. list_del_init(&class_dev->node);
  512. list_for_each_entry(class_intf, &parent->interfaces, node)
  513. if (class_intf->remove)
  514. class_intf->remove(class_dev);
  515. up(&parent->sem);
  516. }
  517. if (class_dev->dev) {
  518. class_name = make_class_name(class_dev);
  519. sysfs_remove_link(&class_dev->kobj, "device");
  520. sysfs_remove_link(&class_dev->dev->kobj, class_name);
  521. }
  522. if (class_dev->devt_attr)
  523. class_device_remove_file(class_dev, class_dev->devt_attr);
  524. class_device_remove_attrs(class_dev);
  525. kobject_hotplug(&class_dev->kobj, KOBJ_REMOVE);
  526. kobject_del(&class_dev->kobj);
  527. if (parent)
  528. class_put(parent);
  529. kfree(class_name);
  530. }
  531. void class_device_unregister(struct class_device *class_dev)
  532. {
  533. pr_debug("CLASS: Unregistering class device. ID = '%s'\n",
  534. class_dev->class_id);
  535. class_device_del(class_dev);
  536. class_device_put(class_dev);
  537. }
  538. /**
  539. * class_device_destroy - removes a class device that was created with class_device_create()
  540. * @cls: the pointer to the struct class that this device was registered * with.
  541. * @dev: the dev_t of the device that was previously registered.
  542. *
  543. * This call unregisters and cleans up a class device that was created with a
  544. * call to class_device_create()
  545. */
  546. void class_device_destroy(struct class *cls, dev_t devt)
  547. {
  548. struct class_device *class_dev = NULL;
  549. struct class_device *class_dev_tmp;
  550. down(&cls->sem);
  551. list_for_each_entry(class_dev_tmp, &cls->children, node) {
  552. if (class_dev_tmp->devt == devt) {
  553. class_dev = class_dev_tmp;
  554. break;
  555. }
  556. }
  557. up(&cls->sem);
  558. if (class_dev)
  559. class_device_unregister(class_dev);
  560. }
  561. int class_device_rename(struct class_device *class_dev, char *new_name)
  562. {
  563. int error = 0;
  564. class_dev = class_device_get(class_dev);
  565. if (!class_dev)
  566. return -EINVAL;
  567. pr_debug("CLASS: renaming '%s' to '%s'\n", class_dev->class_id,
  568. new_name);
  569. strlcpy(class_dev->class_id, new_name, KOBJ_NAME_LEN);
  570. error = kobject_rename(&class_dev->kobj, new_name);
  571. class_device_put(class_dev);
  572. return error;
  573. }
  574. struct class_device * class_device_get(struct class_device *class_dev)
  575. {
  576. if (class_dev)
  577. return to_class_dev(kobject_get(&class_dev->kobj));
  578. return NULL;
  579. }
  580. void class_device_put(struct class_device *class_dev)
  581. {
  582. kobject_put(&class_dev->kobj);
  583. }
  584. int class_interface_register(struct class_interface *class_intf)
  585. {
  586. struct class *parent;
  587. struct class_device *class_dev;
  588. if (!class_intf || !class_intf->class)
  589. return -ENODEV;
  590. parent = class_get(class_intf->class);
  591. if (!parent)
  592. return -EINVAL;
  593. down(&parent->sem);
  594. list_add_tail(&class_intf->node, &parent->interfaces);
  595. if (class_intf->add) {
  596. list_for_each_entry(class_dev, &parent->children, node)
  597. class_intf->add(class_dev);
  598. }
  599. up(&parent->sem);
  600. return 0;
  601. }
  602. void class_interface_unregister(struct class_interface *class_intf)
  603. {
  604. struct class * parent = class_intf->class;
  605. struct class_device *class_dev;
  606. if (!parent)
  607. return;
  608. down(&parent->sem);
  609. list_del_init(&class_intf->node);
  610. if (class_intf->remove) {
  611. list_for_each_entry(class_dev, &parent->children, node)
  612. class_intf->remove(class_dev);
  613. }
  614. up(&parent->sem);
  615. class_put(parent);
  616. }
  617. int __init classes_init(void)
  618. {
  619. int retval;
  620. retval = subsystem_register(&class_subsys);
  621. if (retval)
  622. return retval;
  623. /* ick, this is ugly, the things we go through to keep from showing up
  624. * in sysfs... */
  625. subsystem_init(&class_obj_subsys);
  626. if (!class_obj_subsys.kset.subsys)
  627. class_obj_subsys.kset.subsys = &class_obj_subsys;
  628. return 0;
  629. }
  630. EXPORT_SYMBOL_GPL(class_create_file);
  631. EXPORT_SYMBOL_GPL(class_remove_file);
  632. EXPORT_SYMBOL_GPL(class_register);
  633. EXPORT_SYMBOL_GPL(class_unregister);
  634. EXPORT_SYMBOL_GPL(class_get);
  635. EXPORT_SYMBOL_GPL(class_put);
  636. EXPORT_SYMBOL_GPL(class_create);
  637. EXPORT_SYMBOL_GPL(class_destroy);
  638. EXPORT_SYMBOL_GPL(class_device_register);
  639. EXPORT_SYMBOL_GPL(class_device_unregister);
  640. EXPORT_SYMBOL_GPL(class_device_initialize);
  641. EXPORT_SYMBOL_GPL(class_device_add);
  642. EXPORT_SYMBOL_GPL(class_device_del);
  643. EXPORT_SYMBOL_GPL(class_device_get);
  644. EXPORT_SYMBOL_GPL(class_device_put);
  645. EXPORT_SYMBOL_GPL(class_device_create);
  646. EXPORT_SYMBOL_GPL(class_device_destroy);
  647. EXPORT_SYMBOL_GPL(class_device_create_file);
  648. EXPORT_SYMBOL_GPL(class_device_remove_file);
  649. EXPORT_SYMBOL_GPL(class_device_create_bin_file);
  650. EXPORT_SYMBOL_GPL(class_device_remove_bin_file);
  651. EXPORT_SYMBOL_GPL(class_interface_register);
  652. EXPORT_SYMBOL_GPL(class_interface_unregister);