file.c 18 KB

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