file.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693
  1. /*
  2. * fs/sysfs/file.c - sysfs regular (text) file implementation
  3. *
  4. * Copyright (c) 2001-3 Patrick Mochel
  5. * Copyright (c) 2007 SUSE Linux Products GmbH
  6. * Copyright (c) 2007 Tejun Heo <teheo@suse.de>
  7. *
  8. * This file is released under the GPLv2.
  9. *
  10. * Please see Documentation/filesystems/sysfs.txt for more information.
  11. */
  12. #include <linux/module.h>
  13. #include <linux/kobject.h>
  14. #include <linux/namei.h>
  15. #include <linux/poll.h>
  16. #include <linux/list.h>
  17. #include <linux/mutex.h>
  18. #include <asm/uaccess.h>
  19. #include "sysfs.h"
  20. /*
  21. * There's one sysfs_buffer for each open file and one
  22. * sysfs_open_dirent for each sysfs_dirent with one or more open
  23. * files.
  24. *
  25. * filp->private_data points to sysfs_buffer and
  26. * sysfs_dirent->s_attr.open points to sysfs_open_dirent. s_attr.open
  27. * is protected by sysfs_open_dirent_lock.
  28. */
  29. static DEFINE_SPINLOCK(sysfs_open_dirent_lock);
  30. struct sysfs_open_dirent {
  31. atomic_t refcnt;
  32. atomic_t event;
  33. wait_queue_head_t poll;
  34. struct list_head buffers; /* goes through sysfs_buffer.list */
  35. };
  36. struct sysfs_buffer {
  37. size_t count;
  38. loff_t pos;
  39. char * page;
  40. struct sysfs_ops * ops;
  41. struct mutex mutex;
  42. int needs_read_fill;
  43. int event;
  44. struct list_head list;
  45. };
  46. /**
  47. * fill_read_buffer - allocate and fill buffer from object.
  48. * @dentry: dentry pointer.
  49. * @buffer: data buffer for file.
  50. *
  51. * Allocate @buffer->page, if it hasn't been already, then call the
  52. * kobject's show() method to fill the buffer with this attribute's
  53. * data.
  54. * This is called only once, on the file's first read unless an error
  55. * is returned.
  56. */
  57. static int fill_read_buffer(struct dentry * dentry, struct sysfs_buffer * buffer)
  58. {
  59. struct sysfs_dirent *attr_sd = dentry->d_fsdata;
  60. struct kobject *kobj = attr_sd->s_parent->s_dir.kobj;
  61. struct sysfs_ops * ops = buffer->ops;
  62. int ret = 0;
  63. ssize_t count;
  64. if (!buffer->page)
  65. buffer->page = (char *) get_zeroed_page(GFP_KERNEL);
  66. if (!buffer->page)
  67. return -ENOMEM;
  68. /* need attr_sd for attr and ops, its parent for kobj */
  69. if (!sysfs_get_active_two(attr_sd))
  70. return -ENODEV;
  71. buffer->event = atomic_read(&attr_sd->s_attr.open->event);
  72. count = ops->show(kobj, attr_sd->s_attr.attr, buffer->page);
  73. sysfs_put_active_two(attr_sd);
  74. /*
  75. * The code works fine with PAGE_SIZE return but it's likely to
  76. * indicate truncated result or overflow in normal use cases.
  77. */
  78. BUG_ON(count >= (ssize_t)PAGE_SIZE);
  79. if (count >= 0) {
  80. buffer->needs_read_fill = 0;
  81. buffer->count = count;
  82. } else {
  83. ret = count;
  84. }
  85. return ret;
  86. }
  87. /**
  88. * sysfs_read_file - read an attribute.
  89. * @file: file pointer.
  90. * @buf: buffer to fill.
  91. * @count: number of bytes to read.
  92. * @ppos: starting offset in file.
  93. *
  94. * Userspace wants to read an attribute file. The attribute descriptor
  95. * is in the file's ->d_fsdata. The target object is in the directory's
  96. * ->d_fsdata.
  97. *
  98. * We call fill_read_buffer() to allocate and fill the buffer from the
  99. * object's show() method exactly once (if the read is happening from
  100. * the beginning of the file). That should fill the entire buffer with
  101. * all the data the object has to offer for that attribute.
  102. * We then call flush_read_buffer() to copy the buffer to userspace
  103. * in the increments specified.
  104. */
  105. static ssize_t
  106. sysfs_read_file(struct file *file, char __user *buf, size_t count, loff_t *ppos)
  107. {
  108. struct sysfs_buffer * buffer = file->private_data;
  109. ssize_t retval = 0;
  110. mutex_lock(&buffer->mutex);
  111. if (buffer->needs_read_fill) {
  112. retval = fill_read_buffer(file->f_path.dentry,buffer);
  113. if (retval)
  114. goto out;
  115. }
  116. pr_debug("%s: count = %zd, ppos = %lld, buf = %s\n",
  117. __FUNCTION__, count, *ppos, buffer->page);
  118. retval = simple_read_from_buffer(buf, count, ppos, buffer->page,
  119. buffer->count);
  120. out:
  121. mutex_unlock(&buffer->mutex);
  122. return retval;
  123. }
  124. /**
  125. * fill_write_buffer - copy buffer from userspace.
  126. * @buffer: data buffer for file.
  127. * @buf: data from user.
  128. * @count: number of bytes in @userbuf.
  129. *
  130. * Allocate @buffer->page if it hasn't been already, then
  131. * copy the user-supplied buffer into it.
  132. */
  133. static int
  134. fill_write_buffer(struct sysfs_buffer * buffer, const char __user * buf, size_t count)
  135. {
  136. int error;
  137. if (!buffer->page)
  138. buffer->page = (char *)get_zeroed_page(GFP_KERNEL);
  139. if (!buffer->page)
  140. return -ENOMEM;
  141. if (count >= PAGE_SIZE)
  142. count = PAGE_SIZE - 1;
  143. error = copy_from_user(buffer->page,buf,count);
  144. buffer->needs_read_fill = 1;
  145. /* if buf is assumed to contain a string, terminate it by \0,
  146. so e.g. sscanf() can scan the string easily */
  147. buffer->page[count] = 0;
  148. return error ? -EFAULT : count;
  149. }
  150. /**
  151. * flush_write_buffer - push buffer to kobject.
  152. * @dentry: dentry to the attribute
  153. * @buffer: data buffer for file.
  154. * @count: number of bytes
  155. *
  156. * Get the correct pointers for the kobject and the attribute we're
  157. * dealing with, then call the store() method for the attribute,
  158. * passing the buffer that we acquired in fill_write_buffer().
  159. */
  160. static int
  161. flush_write_buffer(struct dentry * dentry, struct sysfs_buffer * buffer, size_t count)
  162. {
  163. struct sysfs_dirent *attr_sd = dentry->d_fsdata;
  164. struct kobject *kobj = attr_sd->s_parent->s_dir.kobj;
  165. struct sysfs_ops * ops = buffer->ops;
  166. int rc;
  167. /* need attr_sd for attr and ops, its parent for kobj */
  168. if (!sysfs_get_active_two(attr_sd))
  169. return -ENODEV;
  170. rc = ops->store(kobj, attr_sd->s_attr.attr, buffer->page, count);
  171. sysfs_put_active_two(attr_sd);
  172. return rc;
  173. }
  174. /**
  175. * sysfs_write_file - write an attribute.
  176. * @file: file pointer
  177. * @buf: data to write
  178. * @count: number of bytes
  179. * @ppos: starting offset
  180. *
  181. * Similar to sysfs_read_file(), though working in the opposite direction.
  182. * We allocate and fill the data from the user in fill_write_buffer(),
  183. * then push it to the kobject in flush_write_buffer().
  184. * There is no easy way for us to know if userspace is only doing a partial
  185. * write, so we don't support them. We expect the entire buffer to come
  186. * on the first write.
  187. * Hint: if you're writing a value, first read the file, modify only the
  188. * the value you're changing, then write entire buffer back.
  189. */
  190. static ssize_t
  191. sysfs_write_file(struct file *file, const char __user *buf, size_t count, loff_t *ppos)
  192. {
  193. struct sysfs_buffer * buffer = file->private_data;
  194. ssize_t len;
  195. mutex_lock(&buffer->mutex);
  196. len = fill_write_buffer(buffer, buf, count);
  197. if (len > 0)
  198. len = flush_write_buffer(file->f_path.dentry, buffer, len);
  199. if (len > 0)
  200. *ppos += len;
  201. mutex_unlock(&buffer->mutex);
  202. return len;
  203. }
  204. /**
  205. * sysfs_get_open_dirent - get or create sysfs_open_dirent
  206. * @sd: target sysfs_dirent
  207. * @buffer: sysfs_buffer for this instance of open
  208. *
  209. * If @sd->s_attr.open exists, increment its reference count;
  210. * otherwise, create one. @buffer is chained to the buffers
  211. * list.
  212. *
  213. * LOCKING:
  214. * Kernel thread context (may sleep).
  215. *
  216. * RETURNS:
  217. * 0 on success, -errno on failure.
  218. */
  219. static int sysfs_get_open_dirent(struct sysfs_dirent *sd,
  220. struct sysfs_buffer *buffer)
  221. {
  222. struct sysfs_open_dirent *od, *new_od = NULL;
  223. retry:
  224. spin_lock(&sysfs_open_dirent_lock);
  225. if (!sd->s_attr.open && new_od) {
  226. sd->s_attr.open = new_od;
  227. new_od = NULL;
  228. }
  229. od = sd->s_attr.open;
  230. if (od) {
  231. atomic_inc(&od->refcnt);
  232. list_add_tail(&buffer->list, &od->buffers);
  233. }
  234. spin_unlock(&sysfs_open_dirent_lock);
  235. if (od) {
  236. kfree(new_od);
  237. return 0;
  238. }
  239. /* not there, initialize a new one and retry */
  240. new_od = kmalloc(sizeof(*new_od), GFP_KERNEL);
  241. if (!new_od)
  242. return -ENOMEM;
  243. atomic_set(&new_od->refcnt, 0);
  244. atomic_set(&new_od->event, 1);
  245. init_waitqueue_head(&new_od->poll);
  246. INIT_LIST_HEAD(&new_od->buffers);
  247. goto retry;
  248. }
  249. /**
  250. * sysfs_put_open_dirent - put sysfs_open_dirent
  251. * @sd: target sysfs_dirent
  252. * @buffer: associated sysfs_buffer
  253. *
  254. * Put @sd->s_attr.open and unlink @buffer from the buffers list.
  255. * If reference count reaches zero, disassociate and free it.
  256. *
  257. * LOCKING:
  258. * None.
  259. */
  260. static void sysfs_put_open_dirent(struct sysfs_dirent *sd,
  261. struct sysfs_buffer *buffer)
  262. {
  263. struct sysfs_open_dirent *od = sd->s_attr.open;
  264. spin_lock(&sysfs_open_dirent_lock);
  265. list_del(&buffer->list);
  266. if (atomic_dec_and_test(&od->refcnt))
  267. sd->s_attr.open = NULL;
  268. else
  269. od = NULL;
  270. spin_unlock(&sysfs_open_dirent_lock);
  271. kfree(od);
  272. }
  273. static int sysfs_open_file(struct inode *inode, struct file *file)
  274. {
  275. struct sysfs_dirent *attr_sd = file->f_path.dentry->d_fsdata;
  276. struct kobject *kobj = attr_sd->s_parent->s_dir.kobj;
  277. struct sysfs_buffer *buffer;
  278. struct sysfs_ops *ops;
  279. int error = -EACCES;
  280. /* need attr_sd for attr and ops, its parent for kobj */
  281. if (!sysfs_get_active_two(attr_sd))
  282. return -ENODEV;
  283. /* every kobject with an attribute needs a ktype assigned */
  284. if (kobj->ktype && kobj->ktype->sysfs_ops)
  285. ops = kobj->ktype->sysfs_ops;
  286. else {
  287. printk(KERN_ERR "missing sysfs attribute operations for "
  288. "kobject: %s\n", kobject_name(kobj));
  289. WARN_ON(1);
  290. goto err_out;
  291. }
  292. /* File needs write support.
  293. * The inode's perms must say it's ok,
  294. * and we must have a store method.
  295. */
  296. if (file->f_mode & FMODE_WRITE) {
  297. if (!(inode->i_mode & S_IWUGO) || !ops->store)
  298. goto err_out;
  299. }
  300. /* File needs read support.
  301. * The inode's perms must say it's ok, and we there
  302. * must be a show method for it.
  303. */
  304. if (file->f_mode & FMODE_READ) {
  305. if (!(inode->i_mode & S_IRUGO) || !ops->show)
  306. goto err_out;
  307. }
  308. /* No error? Great, allocate a buffer for the file, and store it
  309. * it in file->private_data for easy access.
  310. */
  311. error = -ENOMEM;
  312. buffer = kzalloc(sizeof(struct sysfs_buffer), GFP_KERNEL);
  313. if (!buffer)
  314. goto err_out;
  315. mutex_init(&buffer->mutex);
  316. buffer->needs_read_fill = 1;
  317. buffer->ops = ops;
  318. file->private_data = buffer;
  319. /* make sure we have open dirent struct */
  320. error = sysfs_get_open_dirent(attr_sd, buffer);
  321. if (error)
  322. goto err_free;
  323. /* open succeeded, put active references */
  324. sysfs_put_active_two(attr_sd);
  325. return 0;
  326. err_free:
  327. kfree(buffer);
  328. err_out:
  329. sysfs_put_active_two(attr_sd);
  330. return error;
  331. }
  332. static int sysfs_release(struct inode *inode, struct file *filp)
  333. {
  334. struct sysfs_dirent *sd = filp->f_path.dentry->d_fsdata;
  335. struct sysfs_buffer *buffer = filp->private_data;
  336. sysfs_put_open_dirent(sd, buffer);
  337. if (buffer->page)
  338. free_page((unsigned long)buffer->page);
  339. kfree(buffer);
  340. return 0;
  341. }
  342. /* Sysfs attribute files are pollable. The idea is that you read
  343. * the content and then you use 'poll' or 'select' to wait for
  344. * the content to change. When the content changes (assuming the
  345. * manager for the kobject supports notification), poll will
  346. * return POLLERR|POLLPRI, and select will return the fd whether
  347. * it is waiting for read, write, or exceptions.
  348. * Once poll/select indicates that the value has changed, you
  349. * need to close and re-open the file, as simply seeking and reading
  350. * again will not get new data, or reset the state of 'poll'.
  351. * Reminder: this only works for attributes which actively support
  352. * it, and it is not possible to test an attribute from userspace
  353. * to see if it supports poll (Neither 'poll' nor 'select' return
  354. * an appropriate error code). When in doubt, set a suitable timeout value.
  355. */
  356. static unsigned int sysfs_poll(struct file *filp, poll_table *wait)
  357. {
  358. struct sysfs_buffer * buffer = filp->private_data;
  359. struct sysfs_dirent *attr_sd = filp->f_path.dentry->d_fsdata;
  360. struct sysfs_open_dirent *od = attr_sd->s_attr.open;
  361. /* need parent for the kobj, grab both */
  362. if (!sysfs_get_active_two(attr_sd))
  363. goto trigger;
  364. poll_wait(filp, &od->poll, wait);
  365. sysfs_put_active_two(attr_sd);
  366. if (buffer->event != atomic_read(&od->event))
  367. goto trigger;
  368. return 0;
  369. trigger:
  370. buffer->needs_read_fill = 1;
  371. return POLLERR|POLLPRI;
  372. }
  373. void sysfs_notify(struct kobject *k, char *dir, char *attr)
  374. {
  375. struct sysfs_dirent *sd = k->sd;
  376. mutex_lock(&sysfs_mutex);
  377. if (sd && dir)
  378. sd = sysfs_find_dirent(sd, dir);
  379. if (sd && attr)
  380. sd = sysfs_find_dirent(sd, attr);
  381. if (sd) {
  382. struct sysfs_open_dirent *od;
  383. spin_lock(&sysfs_open_dirent_lock);
  384. od = sd->s_attr.open;
  385. if (od) {
  386. atomic_inc(&od->event);
  387. wake_up_interruptible(&od->poll);
  388. }
  389. spin_unlock(&sysfs_open_dirent_lock);
  390. }
  391. mutex_unlock(&sysfs_mutex);
  392. }
  393. EXPORT_SYMBOL_GPL(sysfs_notify);
  394. const struct file_operations sysfs_file_operations = {
  395. .read = sysfs_read_file,
  396. .write = sysfs_write_file,
  397. .llseek = generic_file_llseek,
  398. .open = sysfs_open_file,
  399. .release = sysfs_release,
  400. .poll = sysfs_poll,
  401. };
  402. int sysfs_add_file(struct sysfs_dirent *dir_sd, const struct attribute *attr,
  403. int type)
  404. {
  405. umode_t mode = (attr->mode & S_IALLUGO) | S_IFREG;
  406. struct sysfs_addrm_cxt acxt;
  407. struct sysfs_dirent *sd;
  408. int rc;
  409. sd = sysfs_new_dirent(attr->name, mode, type);
  410. if (!sd)
  411. return -ENOMEM;
  412. sd->s_attr.attr = (void *)attr;
  413. sysfs_addrm_start(&acxt, dir_sd);
  414. rc = sysfs_add_one(&acxt, sd);
  415. sysfs_addrm_finish(&acxt);
  416. if (rc)
  417. sysfs_put(sd);
  418. return rc;
  419. }
  420. /**
  421. * sysfs_create_file - create an attribute file for an object.
  422. * @kobj: object we're creating for.
  423. * @attr: attribute descriptor.
  424. */
  425. int sysfs_create_file(struct kobject * kobj, const struct attribute * attr)
  426. {
  427. BUG_ON(!kobj || !kobj->sd || !attr);
  428. return sysfs_add_file(kobj->sd, attr, SYSFS_KOBJ_ATTR);
  429. }
  430. /**
  431. * sysfs_add_file_to_group - add an attribute file to a pre-existing group.
  432. * @kobj: object we're acting for.
  433. * @attr: attribute descriptor.
  434. * @group: group name.
  435. */
  436. int sysfs_add_file_to_group(struct kobject *kobj,
  437. const struct attribute *attr, const char *group)
  438. {
  439. struct sysfs_dirent *dir_sd;
  440. int error;
  441. if (group)
  442. dir_sd = sysfs_get_dirent(kobj->sd, group);
  443. else
  444. dir_sd = sysfs_get(kobj->sd);
  445. if (!dir_sd)
  446. return -ENOENT;
  447. error = sysfs_add_file(dir_sd, attr, SYSFS_KOBJ_ATTR);
  448. sysfs_put(dir_sd);
  449. return error;
  450. }
  451. EXPORT_SYMBOL_GPL(sysfs_add_file_to_group);
  452. /**
  453. * sysfs_chmod_file - update the modified mode value on an object attribute.
  454. * @kobj: object we're acting for.
  455. * @attr: attribute descriptor.
  456. * @mode: file permissions.
  457. *
  458. */
  459. int sysfs_chmod_file(struct kobject *kobj, struct attribute *attr, mode_t mode)
  460. {
  461. struct sysfs_dirent *victim_sd = NULL;
  462. struct dentry *victim = NULL;
  463. struct inode * inode;
  464. struct iattr newattrs;
  465. int rc;
  466. rc = -ENOENT;
  467. victim_sd = sysfs_get_dirent(kobj->sd, attr->name);
  468. if (!victim_sd)
  469. goto out;
  470. mutex_lock(&sysfs_rename_mutex);
  471. victim = sysfs_get_dentry(victim_sd);
  472. mutex_unlock(&sysfs_rename_mutex);
  473. if (IS_ERR(victim)) {
  474. rc = PTR_ERR(victim);
  475. victim = NULL;
  476. goto out;
  477. }
  478. inode = victim->d_inode;
  479. mutex_lock(&inode->i_mutex);
  480. newattrs.ia_mode = (mode & S_IALLUGO) | (inode->i_mode & ~S_IALLUGO);
  481. newattrs.ia_valid = ATTR_MODE | ATTR_CTIME;
  482. rc = notify_change(victim, &newattrs);
  483. if (rc == 0) {
  484. mutex_lock(&sysfs_mutex);
  485. victim_sd->s_mode = newattrs.ia_mode;
  486. mutex_unlock(&sysfs_mutex);
  487. }
  488. mutex_unlock(&inode->i_mutex);
  489. out:
  490. dput(victim);
  491. sysfs_put(victim_sd);
  492. return rc;
  493. }
  494. EXPORT_SYMBOL_GPL(sysfs_chmod_file);
  495. /**
  496. * sysfs_remove_file - remove an object attribute.
  497. * @kobj: object we're acting for.
  498. * @attr: attribute descriptor.
  499. *
  500. * Hash the attribute name and kill the victim.
  501. */
  502. void sysfs_remove_file(struct kobject * kobj, const struct attribute * attr)
  503. {
  504. sysfs_hash_and_remove(kobj->sd, attr->name);
  505. }
  506. /**
  507. * sysfs_remove_file_from_group - remove an attribute file from a group.
  508. * @kobj: object we're acting for.
  509. * @attr: attribute descriptor.
  510. * @group: group name.
  511. */
  512. void sysfs_remove_file_from_group(struct kobject *kobj,
  513. const struct attribute *attr, const char *group)
  514. {
  515. struct sysfs_dirent *dir_sd;
  516. if (group)
  517. dir_sd = sysfs_get_dirent(kobj->sd, group);
  518. else
  519. dir_sd = sysfs_get(kobj->sd);
  520. if (dir_sd) {
  521. sysfs_hash_and_remove(dir_sd, attr->name);
  522. sysfs_put(dir_sd);
  523. }
  524. }
  525. EXPORT_SYMBOL_GPL(sysfs_remove_file_from_group);
  526. struct sysfs_schedule_callback_struct {
  527. struct kobject *kobj;
  528. void (*func)(void *);
  529. void *data;
  530. struct module *owner;
  531. struct work_struct work;
  532. };
  533. static void sysfs_schedule_callback_work(struct work_struct *work)
  534. {
  535. struct sysfs_schedule_callback_struct *ss = container_of(work,
  536. struct sysfs_schedule_callback_struct, work);
  537. (ss->func)(ss->data);
  538. kobject_put(ss->kobj);
  539. module_put(ss->owner);
  540. kfree(ss);
  541. }
  542. /**
  543. * sysfs_schedule_callback - helper to schedule a callback for a kobject
  544. * @kobj: object we're acting for.
  545. * @func: callback function to invoke later.
  546. * @data: argument to pass to @func.
  547. * @owner: module owning the callback code
  548. *
  549. * sysfs attribute methods must not unregister themselves or their parent
  550. * kobject (which would amount to the same thing). Attempts to do so will
  551. * deadlock, since unregistration is mutually exclusive with driver
  552. * callbacks.
  553. *
  554. * Instead methods can call this routine, which will attempt to allocate
  555. * and schedule a workqueue request to call back @func with @data as its
  556. * argument in the workqueue's process context. @kobj will be pinned
  557. * until @func returns.
  558. *
  559. * Returns 0 if the request was submitted, -ENOMEM if storage could not
  560. * be allocated, -ENODEV if a reference to @owner isn't available.
  561. */
  562. int sysfs_schedule_callback(struct kobject *kobj, void (*func)(void *),
  563. void *data, struct module *owner)
  564. {
  565. struct sysfs_schedule_callback_struct *ss;
  566. if (!try_module_get(owner))
  567. return -ENODEV;
  568. ss = kmalloc(sizeof(*ss), GFP_KERNEL);
  569. if (!ss) {
  570. module_put(owner);
  571. return -ENOMEM;
  572. }
  573. kobject_get(kobj);
  574. ss->kobj = kobj;
  575. ss->func = func;
  576. ss->data = data;
  577. ss->owner = owner;
  578. INIT_WORK(&ss->work, sysfs_schedule_callback_work);
  579. schedule_work(&ss->work);
  580. return 0;
  581. }
  582. EXPORT_SYMBOL_GPL(sysfs_schedule_callback);
  583. EXPORT_SYMBOL_GPL(sysfs_create_file);
  584. EXPORT_SYMBOL_GPL(sysfs_remove_file);