sound_firmware.c 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. #include <linux/vmalloc.h>
  2. #include <linux/module.h>
  3. #include <linux/fs.h>
  4. #include <linux/mm.h>
  5. #include <linux/sched.h>
  6. #include <asm/uaccess.h>
  7. #include "oss/sound_firmware.h"
  8. static int do_mod_firmware_load(const char *fn, char **fp)
  9. {
  10. struct file* filp;
  11. long l;
  12. char *dp;
  13. loff_t pos;
  14. filp = filp_open(fn, 0, 0);
  15. if (IS_ERR(filp))
  16. {
  17. printk(KERN_INFO "Unable to load '%s'.\n", fn);
  18. return 0;
  19. }
  20. l = i_size_read(filp->f_path.dentry->d_inode);
  21. if (l <= 0 || l > 131072)
  22. {
  23. printk(KERN_INFO "Invalid firmware '%s'\n", fn);
  24. filp_close(filp, current->files);
  25. return 0;
  26. }
  27. dp = vmalloc(l);
  28. if (dp == NULL)
  29. {
  30. printk(KERN_INFO "Out of memory loading '%s'.\n", fn);
  31. filp_close(filp, current->files);
  32. return 0;
  33. }
  34. pos = 0;
  35. if (vfs_read(filp, dp, l, &pos) != l)
  36. {
  37. printk(KERN_INFO "Failed to read '%s'.\n", fn);
  38. vfree(dp);
  39. filp_close(filp, current->files);
  40. return 0;
  41. }
  42. filp_close(filp, current->files);
  43. *fp = dp;
  44. return (int) l;
  45. }
  46. /**
  47. * mod_firmware_load - load sound driver firmware
  48. * @fn: filename
  49. * @fp: return for the buffer.
  50. *
  51. * Load the firmware for a sound module (up to 128K) into a buffer.
  52. * The buffer is returned in *fp. It is allocated with vmalloc so is
  53. * virtually linear and not DMAable. The caller should free it with
  54. * vfree when finished.
  55. *
  56. * The length of the buffer is returned on a successful load, the
  57. * value zero on a failure.
  58. *
  59. * Caution: This API is not recommended. Firmware should be loaded via
  60. * request_firmware.
  61. */
  62. int mod_firmware_load(const char *fn, char **fp)
  63. {
  64. int r;
  65. mm_segment_t fs = get_fs();
  66. set_fs(get_ds());
  67. r = do_mod_firmware_load(fn, fp);
  68. set_fs(fs);
  69. return r;
  70. }
  71. EXPORT_SYMBOL(mod_firmware_load);
  72. MODULE_LICENSE("GPL");