firmware_class.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722
  1. /*
  2. * firmware_class.c - Multi purpose firmware loading support
  3. *
  4. * Copyright (c) 2003 Manuel Estrada Sainz
  5. *
  6. * Please see Documentation/firmware_class/ for more information.
  7. *
  8. */
  9. #include <linux/capability.h>
  10. #include <linux/device.h>
  11. #include <linux/module.h>
  12. #include <linux/init.h>
  13. #include <linux/timer.h>
  14. #include <linux/vmalloc.h>
  15. #include <linux/interrupt.h>
  16. #include <linux/bitops.h>
  17. #include <linux/mutex.h>
  18. #include <linux/kthread.h>
  19. #include <linux/highmem.h>
  20. #include <linux/firmware.h>
  21. #include <linux/slab.h>
  22. #define to_dev(obj) container_of(obj, struct device, kobj)
  23. MODULE_AUTHOR("Manuel Estrada Sainz");
  24. MODULE_DESCRIPTION("Multi purpose firmware loading support");
  25. MODULE_LICENSE("GPL");
  26. /* Builtin firmware support */
  27. #ifdef CONFIG_FW_LOADER
  28. extern struct builtin_fw __start_builtin_fw[];
  29. extern struct builtin_fw __end_builtin_fw[];
  30. static bool fw_get_builtin_firmware(struct firmware *fw, const char *name)
  31. {
  32. struct builtin_fw *b_fw;
  33. for (b_fw = __start_builtin_fw; b_fw != __end_builtin_fw; b_fw++) {
  34. if (strcmp(name, b_fw->name) == 0) {
  35. fw->size = b_fw->size;
  36. fw->data = b_fw->data;
  37. return true;
  38. }
  39. }
  40. return false;
  41. }
  42. static bool fw_is_builtin_firmware(const struct firmware *fw)
  43. {
  44. struct builtin_fw *b_fw;
  45. for (b_fw = __start_builtin_fw; b_fw != __end_builtin_fw; b_fw++)
  46. if (fw->data == b_fw->data)
  47. return true;
  48. return false;
  49. }
  50. #else /* Module case - no builtin firmware support */
  51. static inline bool fw_get_builtin_firmware(struct firmware *fw, const char *name)
  52. {
  53. return false;
  54. }
  55. static inline bool fw_is_builtin_firmware(const struct firmware *fw)
  56. {
  57. return false;
  58. }
  59. #endif
  60. enum {
  61. FW_STATUS_LOADING,
  62. FW_STATUS_DONE,
  63. FW_STATUS_ABORT,
  64. };
  65. static int loading_timeout = 60; /* In seconds */
  66. /* fw_lock could be moved to 'struct firmware_priv' but since it is just
  67. * guarding for corner cases a global lock should be OK */
  68. static DEFINE_MUTEX(fw_lock);
  69. struct firmware_priv {
  70. struct completion completion;
  71. struct firmware *fw;
  72. unsigned long status;
  73. struct page **pages;
  74. int nr_pages;
  75. int page_array_size;
  76. struct timer_list timeout;
  77. struct device dev;
  78. bool nowait;
  79. char fw_id[];
  80. };
  81. static struct firmware_priv *to_firmware_priv(struct device *dev)
  82. {
  83. return container_of(dev, struct firmware_priv, dev);
  84. }
  85. static void fw_load_abort(struct firmware_priv *fw_priv)
  86. {
  87. set_bit(FW_STATUS_ABORT, &fw_priv->status);
  88. wmb();
  89. complete(&fw_priv->completion);
  90. }
  91. static ssize_t firmware_timeout_show(struct class *class,
  92. struct class_attribute *attr,
  93. char *buf)
  94. {
  95. return sprintf(buf, "%d\n", loading_timeout);
  96. }
  97. /**
  98. * firmware_timeout_store - set number of seconds to wait for firmware
  99. * @class: device class pointer
  100. * @attr: device attribute pointer
  101. * @buf: buffer to scan for timeout value
  102. * @count: number of bytes in @buf
  103. *
  104. * Sets the number of seconds to wait for the firmware. Once
  105. * this expires an error will be returned to the driver and no
  106. * firmware will be provided.
  107. *
  108. * Note: zero means 'wait forever'.
  109. **/
  110. static ssize_t firmware_timeout_store(struct class *class,
  111. struct class_attribute *attr,
  112. const char *buf, size_t count)
  113. {
  114. loading_timeout = simple_strtol(buf, NULL, 10);
  115. if (loading_timeout < 0)
  116. loading_timeout = 0;
  117. return count;
  118. }
  119. static struct class_attribute firmware_class_attrs[] = {
  120. __ATTR(timeout, S_IWUSR | S_IRUGO,
  121. firmware_timeout_show, firmware_timeout_store),
  122. __ATTR_NULL
  123. };
  124. static void fw_dev_release(struct device *dev)
  125. {
  126. struct firmware_priv *fw_priv = to_firmware_priv(dev);
  127. int i;
  128. for (i = 0; i < fw_priv->nr_pages; i++)
  129. __free_page(fw_priv->pages[i]);
  130. kfree(fw_priv->pages);
  131. kfree(fw_priv);
  132. module_put(THIS_MODULE);
  133. }
  134. static int firmware_uevent(struct device *dev, struct kobj_uevent_env *env)
  135. {
  136. struct firmware_priv *fw_priv = to_firmware_priv(dev);
  137. if (add_uevent_var(env, "FIRMWARE=%s", fw_priv->fw_id))
  138. return -ENOMEM;
  139. if (add_uevent_var(env, "TIMEOUT=%i", loading_timeout))
  140. return -ENOMEM;
  141. if (add_uevent_var(env, "ASYNC=%d", fw_priv->nowait))
  142. return -ENOMEM;
  143. return 0;
  144. }
  145. static struct class firmware_class = {
  146. .name = "firmware",
  147. .class_attrs = firmware_class_attrs,
  148. .dev_uevent = firmware_uevent,
  149. .dev_release = fw_dev_release,
  150. };
  151. static ssize_t firmware_loading_show(struct device *dev,
  152. struct device_attribute *attr, char *buf)
  153. {
  154. struct firmware_priv *fw_priv = to_firmware_priv(dev);
  155. int loading = test_bit(FW_STATUS_LOADING, &fw_priv->status);
  156. return sprintf(buf, "%d\n", loading);
  157. }
  158. static void firmware_free_data(const struct firmware *fw)
  159. {
  160. int i;
  161. vunmap(fw->data);
  162. if (fw->pages) {
  163. for (i = 0; i < PFN_UP(fw->size); i++)
  164. __free_page(fw->pages[i]);
  165. kfree(fw->pages);
  166. }
  167. }
  168. /* Some architectures don't have PAGE_KERNEL_RO */
  169. #ifndef PAGE_KERNEL_RO
  170. #define PAGE_KERNEL_RO PAGE_KERNEL
  171. #endif
  172. /**
  173. * firmware_loading_store - set value in the 'loading' control file
  174. * @dev: device pointer
  175. * @attr: device attribute pointer
  176. * @buf: buffer to scan for loading control value
  177. * @count: number of bytes in @buf
  178. *
  179. * The relevant values are:
  180. *
  181. * 1: Start a load, discarding any previous partial load.
  182. * 0: Conclude the load and hand the data to the driver code.
  183. * -1: Conclude the load with an error and discard any written data.
  184. **/
  185. static ssize_t firmware_loading_store(struct device *dev,
  186. struct device_attribute *attr,
  187. const char *buf, size_t count)
  188. {
  189. struct firmware_priv *fw_priv = to_firmware_priv(dev);
  190. int loading = simple_strtol(buf, NULL, 10);
  191. int i;
  192. mutex_lock(&fw_lock);
  193. if (!fw_priv->fw)
  194. goto out;
  195. switch (loading) {
  196. case 1:
  197. firmware_free_data(fw_priv->fw);
  198. memset(fw_priv->fw, 0, sizeof(struct firmware));
  199. /* If the pages are not owned by 'struct firmware' */
  200. for (i = 0; i < fw_priv->nr_pages; i++)
  201. __free_page(fw_priv->pages[i]);
  202. kfree(fw_priv->pages);
  203. fw_priv->pages = NULL;
  204. fw_priv->page_array_size = 0;
  205. fw_priv->nr_pages = 0;
  206. set_bit(FW_STATUS_LOADING, &fw_priv->status);
  207. break;
  208. case 0:
  209. if (test_bit(FW_STATUS_LOADING, &fw_priv->status)) {
  210. vunmap(fw_priv->fw->data);
  211. fw_priv->fw->data = vmap(fw_priv->pages,
  212. fw_priv->nr_pages,
  213. 0, PAGE_KERNEL_RO);
  214. if (!fw_priv->fw->data) {
  215. dev_err(dev, "%s: vmap() failed\n", __func__);
  216. goto err;
  217. }
  218. /* Pages are now owned by 'struct firmware' */
  219. fw_priv->fw->pages = fw_priv->pages;
  220. fw_priv->pages = NULL;
  221. fw_priv->page_array_size = 0;
  222. fw_priv->nr_pages = 0;
  223. complete(&fw_priv->completion);
  224. clear_bit(FW_STATUS_LOADING, &fw_priv->status);
  225. break;
  226. }
  227. /* fallthrough */
  228. default:
  229. dev_err(dev, "%s: unexpected value (%d)\n", __func__, loading);
  230. /* fallthrough */
  231. case -1:
  232. err:
  233. fw_load_abort(fw_priv);
  234. break;
  235. }
  236. out:
  237. mutex_unlock(&fw_lock);
  238. return count;
  239. }
  240. static DEVICE_ATTR(loading, 0644, firmware_loading_show, firmware_loading_store);
  241. static ssize_t firmware_data_read(struct file *filp, struct kobject *kobj,
  242. struct bin_attribute *bin_attr,
  243. char *buffer, loff_t offset, size_t count)
  244. {
  245. struct device *dev = to_dev(kobj);
  246. struct firmware_priv *fw_priv = to_firmware_priv(dev);
  247. struct firmware *fw;
  248. ssize_t ret_count;
  249. mutex_lock(&fw_lock);
  250. fw = fw_priv->fw;
  251. if (!fw || test_bit(FW_STATUS_DONE, &fw_priv->status)) {
  252. ret_count = -ENODEV;
  253. goto out;
  254. }
  255. if (offset > fw->size) {
  256. ret_count = 0;
  257. goto out;
  258. }
  259. if (count > fw->size - offset)
  260. count = fw->size - offset;
  261. ret_count = count;
  262. while (count) {
  263. void *page_data;
  264. int page_nr = offset >> PAGE_SHIFT;
  265. int page_ofs = offset & (PAGE_SIZE-1);
  266. int page_cnt = min_t(size_t, PAGE_SIZE - page_ofs, count);
  267. page_data = kmap(fw_priv->pages[page_nr]);
  268. memcpy(buffer, page_data + page_ofs, page_cnt);
  269. kunmap(fw_priv->pages[page_nr]);
  270. buffer += page_cnt;
  271. offset += page_cnt;
  272. count -= page_cnt;
  273. }
  274. out:
  275. mutex_unlock(&fw_lock);
  276. return ret_count;
  277. }
  278. static int fw_realloc_buffer(struct firmware_priv *fw_priv, int min_size)
  279. {
  280. int pages_needed = ALIGN(min_size, PAGE_SIZE) >> PAGE_SHIFT;
  281. /* If the array of pages is too small, grow it... */
  282. if (fw_priv->page_array_size < pages_needed) {
  283. int new_array_size = max(pages_needed,
  284. fw_priv->page_array_size * 2);
  285. struct page **new_pages;
  286. new_pages = kmalloc(new_array_size * sizeof(void *),
  287. GFP_KERNEL);
  288. if (!new_pages) {
  289. fw_load_abort(fw_priv);
  290. return -ENOMEM;
  291. }
  292. memcpy(new_pages, fw_priv->pages,
  293. fw_priv->page_array_size * sizeof(void *));
  294. memset(&new_pages[fw_priv->page_array_size], 0, sizeof(void *) *
  295. (new_array_size - fw_priv->page_array_size));
  296. kfree(fw_priv->pages);
  297. fw_priv->pages = new_pages;
  298. fw_priv->page_array_size = new_array_size;
  299. }
  300. while (fw_priv->nr_pages < pages_needed) {
  301. fw_priv->pages[fw_priv->nr_pages] =
  302. alloc_page(GFP_KERNEL | __GFP_HIGHMEM);
  303. if (!fw_priv->pages[fw_priv->nr_pages]) {
  304. fw_load_abort(fw_priv);
  305. return -ENOMEM;
  306. }
  307. fw_priv->nr_pages++;
  308. }
  309. return 0;
  310. }
  311. /**
  312. * firmware_data_write - write method for firmware
  313. * @filp: open sysfs file
  314. * @kobj: kobject for the device
  315. * @bin_attr: bin_attr structure
  316. * @buffer: buffer being written
  317. * @offset: buffer offset for write in total data store area
  318. * @count: buffer size
  319. *
  320. * Data written to the 'data' attribute will be later handed to
  321. * the driver as a firmware image.
  322. **/
  323. static ssize_t firmware_data_write(struct file *filp, struct kobject *kobj,
  324. struct bin_attribute *bin_attr,
  325. char *buffer, loff_t offset, size_t count)
  326. {
  327. struct device *dev = to_dev(kobj);
  328. struct firmware_priv *fw_priv = to_firmware_priv(dev);
  329. struct firmware *fw;
  330. ssize_t retval;
  331. if (!capable(CAP_SYS_RAWIO))
  332. return -EPERM;
  333. mutex_lock(&fw_lock);
  334. fw = fw_priv->fw;
  335. if (!fw || test_bit(FW_STATUS_DONE, &fw_priv->status)) {
  336. retval = -ENODEV;
  337. goto out;
  338. }
  339. retval = fw_realloc_buffer(fw_priv, offset + count);
  340. if (retval)
  341. goto out;
  342. retval = count;
  343. while (count) {
  344. void *page_data;
  345. int page_nr = offset >> PAGE_SHIFT;
  346. int page_ofs = offset & (PAGE_SIZE - 1);
  347. int page_cnt = min_t(size_t, PAGE_SIZE - page_ofs, count);
  348. page_data = kmap(fw_priv->pages[page_nr]);
  349. memcpy(page_data + page_ofs, buffer, page_cnt);
  350. kunmap(fw_priv->pages[page_nr]);
  351. buffer += page_cnt;
  352. offset += page_cnt;
  353. count -= page_cnt;
  354. }
  355. fw->size = max_t(size_t, offset, fw->size);
  356. out:
  357. mutex_unlock(&fw_lock);
  358. return retval;
  359. }
  360. static struct bin_attribute firmware_attr_data = {
  361. .attr = { .name = "data", .mode = 0644 },
  362. .size = 0,
  363. .read = firmware_data_read,
  364. .write = firmware_data_write,
  365. };
  366. static void firmware_class_timeout(u_long data)
  367. {
  368. struct firmware_priv *fw_priv = (struct firmware_priv *) data;
  369. fw_load_abort(fw_priv);
  370. }
  371. static struct firmware_priv *
  372. fw_create_instance(struct firmware *firmware, const char *fw_name,
  373. struct device *device, bool uevent, bool nowait)
  374. {
  375. struct firmware_priv *fw_priv;
  376. struct device *f_dev;
  377. int error;
  378. fw_priv = kzalloc(sizeof(*fw_priv) + strlen(fw_name) + 1 , GFP_KERNEL);
  379. if (!fw_priv) {
  380. dev_err(device, "%s: kmalloc failed\n", __func__);
  381. error = -ENOMEM;
  382. goto err_out;
  383. }
  384. fw_priv->fw = firmware;
  385. fw_priv->nowait = nowait;
  386. strcpy(fw_priv->fw_id, fw_name);
  387. init_completion(&fw_priv->completion);
  388. setup_timer(&fw_priv->timeout,
  389. firmware_class_timeout, (u_long) fw_priv);
  390. f_dev = &fw_priv->dev;
  391. device_initialize(f_dev);
  392. dev_set_name(f_dev, "%s", dev_name(device));
  393. f_dev->parent = device;
  394. f_dev->class = &firmware_class;
  395. dev_set_uevent_suppress(f_dev, true);
  396. /* Need to pin this module until class device is destroyed */
  397. __module_get(THIS_MODULE);
  398. error = device_add(f_dev);
  399. if (error) {
  400. dev_err(device, "%s: device_register failed\n", __func__);
  401. goto err_put_dev;
  402. }
  403. error = device_create_bin_file(f_dev, &firmware_attr_data);
  404. if (error) {
  405. dev_err(device, "%s: sysfs_create_bin_file failed\n", __func__);
  406. goto err_del_dev;
  407. }
  408. error = device_create_file(f_dev, &dev_attr_loading);
  409. if (error) {
  410. dev_err(device, "%s: device_create_file failed\n", __func__);
  411. goto err_del_bin_attr;
  412. }
  413. if (uevent)
  414. dev_set_uevent_suppress(f_dev, false);
  415. return fw_priv;
  416. err_del_bin_attr:
  417. device_remove_bin_file(f_dev, &firmware_attr_data);
  418. err_del_dev:
  419. device_del(f_dev);
  420. err_put_dev:
  421. put_device(f_dev);
  422. err_out:
  423. return ERR_PTR(error);
  424. }
  425. static void fw_destroy_instance(struct firmware_priv *fw_priv)
  426. {
  427. struct device *f_dev = &fw_priv->dev;
  428. device_remove_file(f_dev, &dev_attr_loading);
  429. device_remove_bin_file(f_dev, &firmware_attr_data);
  430. device_unregister(f_dev);
  431. }
  432. static int _request_firmware(const struct firmware **firmware_p,
  433. const char *name, struct device *device,
  434. bool uevent, bool nowait)
  435. {
  436. struct firmware_priv *fw_priv;
  437. struct firmware *firmware;
  438. int retval = 0;
  439. if (!firmware_p)
  440. return -EINVAL;
  441. *firmware_p = firmware = kzalloc(sizeof(*firmware), GFP_KERNEL);
  442. if (!firmware) {
  443. dev_err(device, "%s: kmalloc(struct firmware) failed\n",
  444. __func__);
  445. return -ENOMEM;
  446. }
  447. if (fw_get_builtin_firmware(firmware, name)) {
  448. dev_dbg(device, "firmware: using built-in firmware %s\n", name);
  449. return 0;
  450. }
  451. read_lock_usermodehelper();
  452. if (WARN_ON(usermodehelper_is_disabled())) {
  453. dev_err(device, "firmware: %s will not be loaded\n", name);
  454. retval = -EBUSY;
  455. goto out;
  456. }
  457. if (uevent)
  458. dev_dbg(device, "firmware: requesting %s\n", name);
  459. fw_priv = fw_create_instance(firmware, name, device, uevent, nowait);
  460. if (IS_ERR(fw_priv)) {
  461. retval = PTR_ERR(fw_priv);
  462. goto out;
  463. }
  464. if (uevent) {
  465. if (loading_timeout > 0)
  466. mod_timer(&fw_priv->timeout,
  467. round_jiffies_up(jiffies +
  468. loading_timeout * HZ));
  469. kobject_uevent(&fw_priv->dev.kobj, KOBJ_ADD);
  470. }
  471. wait_for_completion(&fw_priv->completion);
  472. set_bit(FW_STATUS_DONE, &fw_priv->status);
  473. del_timer_sync(&fw_priv->timeout);
  474. mutex_lock(&fw_lock);
  475. if (!fw_priv->fw->size || test_bit(FW_STATUS_ABORT, &fw_priv->status))
  476. retval = -ENOENT;
  477. fw_priv->fw = NULL;
  478. mutex_unlock(&fw_lock);
  479. fw_destroy_instance(fw_priv);
  480. out:
  481. read_unlock_usermodehelper();
  482. if (retval) {
  483. release_firmware(firmware);
  484. *firmware_p = NULL;
  485. }
  486. return retval;
  487. }
  488. /**
  489. * request_firmware: - send firmware request and wait for it
  490. * @firmware_p: pointer to firmware image
  491. * @name: name of firmware file
  492. * @device: device for which firmware is being loaded
  493. *
  494. * @firmware_p will be used to return a firmware image by the name
  495. * of @name for device @device.
  496. *
  497. * Should be called from user context where sleeping is allowed.
  498. *
  499. * @name will be used as $FIRMWARE in the uevent environment and
  500. * should be distinctive enough not to be confused with any other
  501. * firmware image for this or any other device.
  502. **/
  503. int
  504. request_firmware(const struct firmware **firmware_p, const char *name,
  505. struct device *device)
  506. {
  507. return _request_firmware(firmware_p, name, device, true, false);
  508. }
  509. /**
  510. * release_firmware: - release the resource associated with a firmware image
  511. * @fw: firmware resource to release
  512. **/
  513. void release_firmware(const struct firmware *fw)
  514. {
  515. if (fw) {
  516. if (!fw_is_builtin_firmware(fw))
  517. firmware_free_data(fw);
  518. kfree(fw);
  519. }
  520. }
  521. /* Async support */
  522. struct firmware_work {
  523. struct work_struct work;
  524. struct module *module;
  525. const char *name;
  526. struct device *device;
  527. void *context;
  528. void (*cont)(const struct firmware *fw, void *context);
  529. bool uevent;
  530. };
  531. static int request_firmware_work_func(void *arg)
  532. {
  533. struct firmware_work *fw_work = arg;
  534. const struct firmware *fw;
  535. int ret;
  536. if (!arg) {
  537. WARN_ON(1);
  538. return 0;
  539. }
  540. ret = _request_firmware(&fw, fw_work->name, fw_work->device,
  541. fw_work->uevent, true);
  542. fw_work->cont(fw, fw_work->context);
  543. module_put(fw_work->module);
  544. kfree(fw_work);
  545. return ret;
  546. }
  547. /**
  548. * request_firmware_nowait - asynchronous version of request_firmware
  549. * @module: module requesting the firmware
  550. * @uevent: sends uevent to copy the firmware image if this flag
  551. * is non-zero else the firmware copy must be done manually.
  552. * @name: name of firmware file
  553. * @device: device for which firmware is being loaded
  554. * @gfp: allocation flags
  555. * @context: will be passed over to @cont, and
  556. * @fw may be %NULL if firmware request fails.
  557. * @cont: function will be called asynchronously when the firmware
  558. * request is over.
  559. *
  560. * Asynchronous variant of request_firmware() for user contexts where
  561. * it is not possible to sleep for long time. It can't be called
  562. * in atomic contexts.
  563. **/
  564. int
  565. request_firmware_nowait(
  566. struct module *module, bool uevent,
  567. const char *name, struct device *device, gfp_t gfp, void *context,
  568. void (*cont)(const struct firmware *fw, void *context))
  569. {
  570. struct task_struct *task;
  571. struct firmware_work *fw_work;
  572. fw_work = kzalloc(sizeof (struct firmware_work), gfp);
  573. if (!fw_work)
  574. return -ENOMEM;
  575. fw_work->module = module;
  576. fw_work->name = name;
  577. fw_work->device = device;
  578. fw_work->context = context;
  579. fw_work->cont = cont;
  580. fw_work->uevent = uevent;
  581. if (!try_module_get(module)) {
  582. kfree(fw_work);
  583. return -EFAULT;
  584. }
  585. task = kthread_run(request_firmware_work_func, fw_work,
  586. "firmware/%s", name);
  587. if (IS_ERR(task)) {
  588. fw_work->cont(NULL, fw_work->context);
  589. module_put(fw_work->module);
  590. kfree(fw_work);
  591. return PTR_ERR(task);
  592. }
  593. return 0;
  594. }
  595. static int __init firmware_class_init(void)
  596. {
  597. return class_register(&firmware_class);
  598. }
  599. static void __exit firmware_class_exit(void)
  600. {
  601. class_unregister(&firmware_class);
  602. }
  603. fs_initcall(firmware_class_init);
  604. module_exit(firmware_class_exit);
  605. EXPORT_SYMBOL(release_firmware);
  606. EXPORT_SYMBOL(request_firmware);
  607. EXPORT_SYMBOL(request_firmware_nowait);