file.c 18 KB

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