sound_firmware.c 1.6 KB

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