hwdep_compat.c 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * 32bit -> 64bit ioctl wrapper for hwdep API
  4. * Copyright (c) by Takashi Iwai <tiwai@suse.de>
  5. */
  6. /* This file is included from hwdep.c */
  7. #include <linux/compat.h>
  8. struct snd_hwdep_dsp_image32 {
  9. u32 index;
  10. unsigned char name[64];
  11. u32 image; /* pointer */
  12. u32 length;
  13. u32 driver_data;
  14. } /* don't set packed attribute here */;
  15. static int snd_hwdep_dsp_load_compat(struct snd_hwdep *hw,
  16. struct snd_hwdep_dsp_image32 __user *src)
  17. {
  18. struct snd_hwdep_dsp_image info = {};
  19. compat_caddr_t ptr;
  20. if (copy_from_user(&info, src, 4 + 64) ||
  21. get_user(ptr, &src->image) ||
  22. get_user(info.length, &src->length) ||
  23. get_user(info.driver_data, &src->driver_data))
  24. return -EFAULT;
  25. info.image = compat_ptr(ptr);
  26. return snd_hwdep_dsp_load(hw, &info);
  27. }
  28. enum {
  29. SNDRV_HWDEP_IOCTL_DSP_LOAD32 = _IOW('H', 0x03, struct snd_hwdep_dsp_image32)
  30. };
  31. static long snd_hwdep_ioctl_compat(struct file * file, unsigned int cmd,
  32. unsigned long arg)
  33. {
  34. struct snd_hwdep *hw = file->private_data;
  35. void __user *argp = compat_ptr(arg);
  36. switch (cmd) {
  37. case SNDRV_HWDEP_IOCTL_PVERSION:
  38. case SNDRV_HWDEP_IOCTL_INFO:
  39. case SNDRV_HWDEP_IOCTL_DSP_STATUS:
  40. return snd_hwdep_ioctl(file, cmd, (unsigned long)argp);
  41. case SNDRV_HWDEP_IOCTL_DSP_LOAD32:
  42. return snd_hwdep_dsp_load_compat(hw, argp);
  43. }
  44. if (hw->ops.ioctl_compat)
  45. return hw->ops.ioctl_compat(hw, file, cmd, arg);
  46. return -ENOIOCTLCMD;
  47. }