timer_compat.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * 32bit -> 64bit ioctl wrapper for timer API
  4. * Copyright (c) by Takashi Iwai <tiwai@suse.de>
  5. */
  6. /* This file included from timer.c */
  7. #include <linux/compat.h>
  8. /*
  9. * ILP32/LP64 has different size for 'long' type. Additionally, the size
  10. * of storage alignment differs depending on architectures. Here, '__packed'
  11. * qualifier is used so that the size of this structure is multiple of 4 and
  12. * it fits to any architectures with 32 bit storage alignment.
  13. */
  14. struct snd_timer_gparams32 {
  15. struct snd_timer_id tid;
  16. u32 period_num;
  17. u32 period_den;
  18. unsigned char reserved[32];
  19. } __packed;
  20. struct snd_timer_info32 {
  21. u32 flags;
  22. s32 card;
  23. unsigned char id[64];
  24. unsigned char name[80];
  25. u32 reserved0;
  26. u32 resolution;
  27. unsigned char reserved[64];
  28. };
  29. static int snd_timer_user_gparams_compat(struct file *file,
  30. struct snd_timer_gparams32 __user *user)
  31. {
  32. struct snd_timer_gparams gparams;
  33. if (copy_from_user(&gparams.tid, &user->tid, sizeof(gparams.tid)) ||
  34. get_user(gparams.period_num, &user->period_num) ||
  35. get_user(gparams.period_den, &user->period_den))
  36. return -EFAULT;
  37. return timer_set_gparams(&gparams);
  38. }
  39. static int snd_timer_user_info_compat(struct file *file,
  40. struct snd_timer_info32 __user *_info)
  41. {
  42. struct snd_timer_user *tu;
  43. struct snd_timer_info32 info;
  44. struct snd_timer *t;
  45. tu = file->private_data;
  46. if (!tu->timeri)
  47. return -EBADFD;
  48. t = tu->timeri->timer;
  49. if (!t)
  50. return -EBADFD;
  51. memset(&info, 0, sizeof(info));
  52. info.card = t->card ? t->card->number : -1;
  53. if (t->hw.flags & SNDRV_TIMER_HW_SLAVE)
  54. info.flags |= SNDRV_TIMER_FLG_SLAVE;
  55. strlcpy(info.id, t->id, sizeof(info.id));
  56. strlcpy(info.name, t->name, sizeof(info.name));
  57. info.resolution = t->hw.resolution;
  58. if (copy_to_user(_info, &info, sizeof(*_info)))
  59. return -EFAULT;
  60. return 0;
  61. }
  62. enum {
  63. SNDRV_TIMER_IOCTL_GPARAMS32 = _IOW('T', 0x04, struct snd_timer_gparams32),
  64. SNDRV_TIMER_IOCTL_INFO32 = _IOR('T', 0x11, struct snd_timer_info32),
  65. SNDRV_TIMER_IOCTL_STATUS_COMPAT32 = _IOW('T', 0x14, struct snd_timer_status32),
  66. SNDRV_TIMER_IOCTL_STATUS_COMPAT64 = _IOW('T', 0x14, struct snd_timer_status64),
  67. };
  68. static long __snd_timer_user_ioctl_compat(struct file *file, unsigned int cmd,
  69. unsigned long arg)
  70. {
  71. void __user *argp = compat_ptr(arg);
  72. switch (cmd) {
  73. case SNDRV_TIMER_IOCTL_PVERSION:
  74. case SNDRV_TIMER_IOCTL_TREAD_OLD:
  75. case SNDRV_TIMER_IOCTL_TREAD64:
  76. case SNDRV_TIMER_IOCTL_GINFO:
  77. case SNDRV_TIMER_IOCTL_GSTATUS:
  78. case SNDRV_TIMER_IOCTL_SELECT:
  79. case SNDRV_TIMER_IOCTL_PARAMS:
  80. case SNDRV_TIMER_IOCTL_START:
  81. case SNDRV_TIMER_IOCTL_START_OLD:
  82. case SNDRV_TIMER_IOCTL_STOP:
  83. case SNDRV_TIMER_IOCTL_STOP_OLD:
  84. case SNDRV_TIMER_IOCTL_CONTINUE:
  85. case SNDRV_TIMER_IOCTL_CONTINUE_OLD:
  86. case SNDRV_TIMER_IOCTL_PAUSE:
  87. case SNDRV_TIMER_IOCTL_PAUSE_OLD:
  88. case SNDRV_TIMER_IOCTL_NEXT_DEVICE:
  89. return __snd_timer_user_ioctl(file, cmd, (unsigned long)argp, true);
  90. case SNDRV_TIMER_IOCTL_GPARAMS32:
  91. return snd_timer_user_gparams_compat(file, argp);
  92. case SNDRV_TIMER_IOCTL_INFO32:
  93. return snd_timer_user_info_compat(file, argp);
  94. case SNDRV_TIMER_IOCTL_STATUS_COMPAT32:
  95. return snd_timer_user_status32(file, argp);
  96. case SNDRV_TIMER_IOCTL_STATUS_COMPAT64:
  97. return snd_timer_user_status64(file, argp);
  98. }
  99. return -ENOIOCTLCMD;
  100. }
  101. static long snd_timer_user_ioctl_compat(struct file *file, unsigned int cmd,
  102. unsigned long arg)
  103. {
  104. struct snd_timer_user *tu = file->private_data;
  105. long ret;
  106. mutex_lock(&tu->ioctl_lock);
  107. ret = __snd_timer_user_ioctl_compat(file, cmd, arg);
  108. mutex_unlock(&tu->ioctl_lock);
  109. return ret;
  110. }