firmware_class.c 17 KB

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