firmware_class.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718
  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. switch (loading) {
  193. case 1:
  194. mutex_lock(&fw_lock);
  195. if (!fw_priv->fw) {
  196. mutex_unlock(&fw_lock);
  197. break;
  198. }
  199. firmware_free_data(fw_priv->fw);
  200. memset(fw_priv->fw, 0, sizeof(struct firmware));
  201. /* If the pages are not owned by 'struct firmware' */
  202. for (i = 0; i < fw_priv->nr_pages; i++)
  203. __free_page(fw_priv->pages[i]);
  204. kfree(fw_priv->pages);
  205. fw_priv->pages = NULL;
  206. fw_priv->page_array_size = 0;
  207. fw_priv->nr_pages = 0;
  208. set_bit(FW_STATUS_LOADING, &fw_priv->status);
  209. mutex_unlock(&fw_lock);
  210. break;
  211. case 0:
  212. if (test_bit(FW_STATUS_LOADING, &fw_priv->status)) {
  213. vunmap(fw_priv->fw->data);
  214. fw_priv->fw->data = vmap(fw_priv->pages,
  215. fw_priv->nr_pages,
  216. 0, PAGE_KERNEL_RO);
  217. if (!fw_priv->fw->data) {
  218. dev_err(dev, "%s: vmap() failed\n", __func__);
  219. goto err;
  220. }
  221. /* Pages are now owned by 'struct firmware' */
  222. fw_priv->fw->pages = fw_priv->pages;
  223. fw_priv->pages = NULL;
  224. fw_priv->page_array_size = 0;
  225. fw_priv->nr_pages = 0;
  226. complete(&fw_priv->completion);
  227. clear_bit(FW_STATUS_LOADING, &fw_priv->status);
  228. break;
  229. }
  230. /* fallthrough */
  231. default:
  232. dev_err(dev, "%s: unexpected value (%d)\n", __func__, loading);
  233. /* fallthrough */
  234. case -1:
  235. err:
  236. fw_load_abort(fw_priv);
  237. break;
  238. }
  239. return count;
  240. }
  241. static DEVICE_ATTR(loading, 0644, firmware_loading_show, firmware_loading_store);
  242. static ssize_t firmware_data_read(struct file *filp, struct kobject *kobj,
  243. struct bin_attribute *bin_attr,
  244. char *buffer, loff_t offset, size_t count)
  245. {
  246. struct device *dev = to_dev(kobj);
  247. struct firmware_priv *fw_priv = to_firmware_priv(dev);
  248. struct firmware *fw;
  249. ssize_t ret_count;
  250. mutex_lock(&fw_lock);
  251. fw = fw_priv->fw;
  252. if (!fw || test_bit(FW_STATUS_DONE, &fw_priv->status)) {
  253. ret_count = -ENODEV;
  254. goto out;
  255. }
  256. if (offset > fw->size) {
  257. ret_count = 0;
  258. goto out;
  259. }
  260. if (count > fw->size - offset)
  261. count = fw->size - offset;
  262. ret_count = count;
  263. while (count) {
  264. void *page_data;
  265. int page_nr = offset >> PAGE_SHIFT;
  266. int page_ofs = offset & (PAGE_SIZE-1);
  267. int page_cnt = min_t(size_t, PAGE_SIZE - page_ofs, count);
  268. page_data = kmap(fw_priv->pages[page_nr]);
  269. memcpy(buffer, page_data + page_ofs, page_cnt);
  270. kunmap(fw_priv->pages[page_nr]);
  271. buffer += page_cnt;
  272. offset += page_cnt;
  273. count -= page_cnt;
  274. }
  275. out:
  276. mutex_unlock(&fw_lock);
  277. return ret_count;
  278. }
  279. static int fw_realloc_buffer(struct firmware_priv *fw_priv, int min_size)
  280. {
  281. int pages_needed = ALIGN(min_size, PAGE_SIZE) >> PAGE_SHIFT;
  282. /* If the array of pages is too small, grow it... */
  283. if (fw_priv->page_array_size < pages_needed) {
  284. int new_array_size = max(pages_needed,
  285. fw_priv->page_array_size * 2);
  286. struct page **new_pages;
  287. new_pages = kmalloc(new_array_size * sizeof(void *),
  288. GFP_KERNEL);
  289. if (!new_pages) {
  290. fw_load_abort(fw_priv);
  291. return -ENOMEM;
  292. }
  293. memcpy(new_pages, fw_priv->pages,
  294. fw_priv->page_array_size * sizeof(void *));
  295. memset(&new_pages[fw_priv->page_array_size], 0, sizeof(void *) *
  296. (new_array_size - fw_priv->page_array_size));
  297. kfree(fw_priv->pages);
  298. fw_priv->pages = new_pages;
  299. fw_priv->page_array_size = new_array_size;
  300. }
  301. while (fw_priv->nr_pages < pages_needed) {
  302. fw_priv->pages[fw_priv->nr_pages] =
  303. alloc_page(GFP_KERNEL | __GFP_HIGHMEM);
  304. if (!fw_priv->pages[fw_priv->nr_pages]) {
  305. fw_load_abort(fw_priv);
  306. return -ENOMEM;
  307. }
  308. fw_priv->nr_pages++;
  309. }
  310. return 0;
  311. }
  312. /**
  313. * firmware_data_write - write method for firmware
  314. * @filp: open sysfs file
  315. * @kobj: kobject for the device
  316. * @bin_attr: bin_attr structure
  317. * @buffer: buffer being written
  318. * @offset: buffer offset for write in total data store area
  319. * @count: buffer size
  320. *
  321. * Data written to the 'data' attribute will be later handed to
  322. * the driver as a firmware image.
  323. **/
  324. static ssize_t firmware_data_write(struct file *filp, struct kobject *kobj,
  325. struct bin_attribute *bin_attr,
  326. char *buffer, loff_t offset, size_t count)
  327. {
  328. struct device *dev = to_dev(kobj);
  329. struct firmware_priv *fw_priv = to_firmware_priv(dev);
  330. struct firmware *fw;
  331. ssize_t retval;
  332. if (!capable(CAP_SYS_RAWIO))
  333. return -EPERM;
  334. mutex_lock(&fw_lock);
  335. fw = fw_priv->fw;
  336. if (!fw || test_bit(FW_STATUS_DONE, &fw_priv->status)) {
  337. retval = -ENODEV;
  338. goto out;
  339. }
  340. retval = fw_realloc_buffer(fw_priv, offset + count);
  341. if (retval)
  342. goto out;
  343. retval = count;
  344. while (count) {
  345. void *page_data;
  346. int page_nr = offset >> PAGE_SHIFT;
  347. int page_ofs = offset & (PAGE_SIZE - 1);
  348. int page_cnt = min_t(size_t, PAGE_SIZE - page_ofs, count);
  349. page_data = kmap(fw_priv->pages[page_nr]);
  350. memcpy(page_data + page_ofs, buffer, page_cnt);
  351. kunmap(fw_priv->pages[page_nr]);
  352. buffer += page_cnt;
  353. offset += page_cnt;
  354. count -= page_cnt;
  355. }
  356. fw->size = max_t(size_t, offset, fw->size);
  357. out:
  358. mutex_unlock(&fw_lock);
  359. return retval;
  360. }
  361. static struct bin_attribute firmware_attr_data = {
  362. .attr = { .name = "data", .mode = 0644 },
  363. .size = 0,
  364. .read = firmware_data_read,
  365. .write = firmware_data_write,
  366. };
  367. static void firmware_class_timeout(u_long data)
  368. {
  369. struct firmware_priv *fw_priv = (struct firmware_priv *) data;
  370. fw_load_abort(fw_priv);
  371. }
  372. static struct firmware_priv *
  373. fw_create_instance(struct firmware *firmware, const char *fw_name,
  374. struct device *device, bool uevent, bool nowait)
  375. {
  376. struct firmware_priv *fw_priv;
  377. struct device *f_dev;
  378. int error;
  379. fw_priv = kzalloc(sizeof(*fw_priv) + strlen(fw_name) + 1 , GFP_KERNEL);
  380. if (!fw_priv) {
  381. dev_err(device, "%s: kmalloc failed\n", __func__);
  382. error = -ENOMEM;
  383. goto err_out;
  384. }
  385. fw_priv->fw = firmware;
  386. fw_priv->nowait = nowait;
  387. strcpy(fw_priv->fw_id, fw_name);
  388. init_completion(&fw_priv->completion);
  389. setup_timer(&fw_priv->timeout,
  390. firmware_class_timeout, (u_long) fw_priv);
  391. f_dev = &fw_priv->dev;
  392. device_initialize(f_dev);
  393. dev_set_name(f_dev, "%s", dev_name(device));
  394. f_dev->parent = device;
  395. f_dev->class = &firmware_class;
  396. dev_set_uevent_suppress(f_dev, true);
  397. /* Need to pin this module until class device is destroyed */
  398. __module_get(THIS_MODULE);
  399. error = device_add(f_dev);
  400. if (error) {
  401. dev_err(device, "%s: device_register failed\n", __func__);
  402. goto err_put_dev;
  403. }
  404. error = device_create_bin_file(f_dev, &firmware_attr_data);
  405. if (error) {
  406. dev_err(device, "%s: sysfs_create_bin_file failed\n", __func__);
  407. goto err_del_dev;
  408. }
  409. error = device_create_file(f_dev, &dev_attr_loading);
  410. if (error) {
  411. dev_err(device, "%s: device_create_file failed\n", __func__);
  412. goto err_del_bin_attr;
  413. }
  414. if (uevent)
  415. dev_set_uevent_suppress(f_dev, false);
  416. return fw_priv;
  417. err_del_bin_attr:
  418. device_remove_bin_file(f_dev, &firmware_attr_data);
  419. err_del_dev:
  420. device_del(f_dev);
  421. err_put_dev:
  422. put_device(f_dev);
  423. err_out:
  424. return ERR_PTR(error);
  425. }
  426. static void fw_destroy_instance(struct firmware_priv *fw_priv)
  427. {
  428. struct device *f_dev = &fw_priv->dev;
  429. device_remove_file(f_dev, &dev_attr_loading);
  430. device_remove_bin_file(f_dev, &firmware_attr_data);
  431. device_unregister(f_dev);
  432. }
  433. static int _request_firmware(const struct firmware **firmware_p,
  434. const char *name, struct device *device,
  435. bool uevent, bool nowait)
  436. {
  437. struct firmware_priv *fw_priv;
  438. struct firmware *firmware;
  439. int retval = 0;
  440. if (!firmware_p)
  441. return -EINVAL;
  442. if (WARN_ON(usermodehelper_is_disabled())) {
  443. dev_err(device, "firmware: %s will not be loaded\n", name);
  444. return -EBUSY;
  445. }
  446. *firmware_p = firmware = kzalloc(sizeof(*firmware), GFP_KERNEL);
  447. if (!firmware) {
  448. dev_err(device, "%s: kmalloc(struct firmware) failed\n",
  449. __func__);
  450. retval = -ENOMEM;
  451. goto out;
  452. }
  453. if (fw_get_builtin_firmware(firmware, name)) {
  454. dev_dbg(device, "firmware: using built-in firmware %s\n", name);
  455. return 0;
  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. if (retval) {
  482. release_firmware(firmware);
  483. *firmware_p = NULL;
  484. }
  485. return retval;
  486. }
  487. /**
  488. * request_firmware: - send firmware request and wait for it
  489. * @firmware_p: pointer to firmware image
  490. * @name: name of firmware file
  491. * @device: device for which firmware is being loaded
  492. *
  493. * @firmware_p will be used to return a firmware image by the name
  494. * of @name for device @device.
  495. *
  496. * Should be called from user context where sleeping is allowed.
  497. *
  498. * @name will be used as $FIRMWARE in the uevent environment and
  499. * should be distinctive enough not to be confused with any other
  500. * firmware image for this or any other device.
  501. **/
  502. int
  503. request_firmware(const struct firmware **firmware_p, const char *name,
  504. struct device *device)
  505. {
  506. return _request_firmware(firmware_p, name, device, true, false);
  507. }
  508. /**
  509. * release_firmware: - release the resource associated with a firmware image
  510. * @fw: firmware resource to release
  511. **/
  512. void release_firmware(const struct firmware *fw)
  513. {
  514. if (fw) {
  515. if (!fw_is_builtin_firmware(fw))
  516. firmware_free_data(fw);
  517. kfree(fw);
  518. }
  519. }
  520. /* Async support */
  521. struct firmware_work {
  522. struct work_struct work;
  523. struct module *module;
  524. const char *name;
  525. struct device *device;
  526. void *context;
  527. void (*cont)(const struct firmware *fw, void *context);
  528. bool uevent;
  529. };
  530. static int request_firmware_work_func(void *arg)
  531. {
  532. struct firmware_work *fw_work = arg;
  533. const struct firmware *fw;
  534. int ret;
  535. if (!arg) {
  536. WARN_ON(1);
  537. return 0;
  538. }
  539. ret = _request_firmware(&fw, fw_work->name, fw_work->device,
  540. fw_work->uevent, true);
  541. fw_work->cont(fw, fw_work->context);
  542. module_put(fw_work->module);
  543. kfree(fw_work);
  544. return ret;
  545. }
  546. /**
  547. * request_firmware_nowait - asynchronous version of request_firmware
  548. * @module: module requesting the firmware
  549. * @uevent: sends uevent to copy the firmware image if this flag
  550. * is non-zero else the firmware copy must be done manually.
  551. * @name: name of firmware file
  552. * @device: device for which firmware is being loaded
  553. * @gfp: allocation flags
  554. * @context: will be passed over to @cont, and
  555. * @fw may be %NULL if firmware request fails.
  556. * @cont: function will be called asynchronously when the firmware
  557. * request is over.
  558. *
  559. * Asynchronous variant of request_firmware() for user contexts where
  560. * it is not possible to sleep for long time. It can't be called
  561. * in atomic contexts.
  562. **/
  563. int
  564. request_firmware_nowait(
  565. struct module *module, bool uevent,
  566. const char *name, struct device *device, gfp_t gfp, void *context,
  567. void (*cont)(const struct firmware *fw, void *context))
  568. {
  569. struct task_struct *task;
  570. struct firmware_work *fw_work;
  571. fw_work = kzalloc(sizeof (struct firmware_work), gfp);
  572. if (!fw_work)
  573. return -ENOMEM;
  574. fw_work->module = module;
  575. fw_work->name = name;
  576. fw_work->device = device;
  577. fw_work->context = context;
  578. fw_work->cont = cont;
  579. fw_work->uevent = uevent;
  580. if (!try_module_get(module)) {
  581. kfree(fw_work);
  582. return -EFAULT;
  583. }
  584. task = kthread_run(request_firmware_work_func, fw_work,
  585. "firmware/%s", name);
  586. if (IS_ERR(task)) {
  587. fw_work->cont(NULL, fw_work->context);
  588. module_put(fw_work->module);
  589. kfree(fw_work);
  590. return PTR_ERR(task);
  591. }
  592. return 0;
  593. }
  594. static int __init firmware_class_init(void)
  595. {
  596. return class_register(&firmware_class);
  597. }
  598. static void __exit firmware_class_exit(void)
  599. {
  600. class_unregister(&firmware_class);
  601. }
  602. fs_initcall(firmware_class_init);
  603. module_exit(firmware_class_exit);
  604. EXPORT_SYMBOL(release_firmware);
  605. EXPORT_SYMBOL(request_firmware);
  606. EXPORT_SYMBOL(request_firmware_nowait);