seq_compat.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * 32bit -> 64bit ioctl wrapper for sequencer API
  4. * Copyright (c) by Takashi Iwai <tiwai@suse.de>
  5. */
  6. /* This file included from seq.c */
  7. #include <linux/compat.h>
  8. #include <linux/slab.h>
  9. struct snd_seq_port_info32 {
  10. struct snd_seq_addr addr; /* client/port numbers */
  11. char name[64]; /* port name */
  12. u32 capability; /* port capability bits */
  13. u32 type; /* port type bits */
  14. s32 midi_channels; /* channels per MIDI port */
  15. s32 midi_voices; /* voices per MIDI port */
  16. s32 synth_voices; /* voices per SYNTH port */
  17. s32 read_use; /* R/O: subscribers for output (from this port) */
  18. s32 write_use; /* R/O: subscribers for input (to this port) */
  19. u32 kernel; /* reserved for kernel use (must be NULL) */
  20. u32 flags; /* misc. conditioning */
  21. unsigned char time_queue; /* queue # for timestamping */
  22. char reserved[59]; /* for future use */
  23. };
  24. static int snd_seq_call_port_info_ioctl(struct snd_seq_client *client, unsigned int cmd,
  25. struct snd_seq_port_info32 __user *data32)
  26. {
  27. struct snd_seq_port_info *data __free(kfree) = NULL;
  28. int err;
  29. data = kmalloc(sizeof(*data), GFP_KERNEL);
  30. if (!data)
  31. return -ENOMEM;
  32. if (copy_from_user(data, data32, sizeof(*data32)) ||
  33. get_user(data->flags, &data32->flags) ||
  34. get_user(data->time_queue, &data32->time_queue))
  35. return -EFAULT;
  36. data->kernel = NULL;
  37. err = snd_seq_kernel_client_ctl(client->number, cmd, data);
  38. if (err < 0)
  39. return err;
  40. if (copy_to_user(data32, data, sizeof(*data32)) ||
  41. put_user(data->flags, &data32->flags) ||
  42. put_user(data->time_queue, &data32->time_queue))
  43. return -EFAULT;
  44. return err;
  45. }
  46. /*
  47. */
  48. enum {
  49. SNDRV_SEQ_IOCTL_CREATE_PORT32 = _IOWR('S', 0x20, struct snd_seq_port_info32),
  50. SNDRV_SEQ_IOCTL_DELETE_PORT32 = _IOW ('S', 0x21, struct snd_seq_port_info32),
  51. SNDRV_SEQ_IOCTL_GET_PORT_INFO32 = _IOWR('S', 0x22, struct snd_seq_port_info32),
  52. SNDRV_SEQ_IOCTL_SET_PORT_INFO32 = _IOW ('S', 0x23, struct snd_seq_port_info32),
  53. SNDRV_SEQ_IOCTL_QUERY_NEXT_PORT32 = _IOWR('S', 0x52, struct snd_seq_port_info32),
  54. };
  55. static long snd_seq_ioctl_compat(struct file *file, unsigned int cmd, unsigned long arg)
  56. {
  57. struct snd_seq_client *client = file->private_data;
  58. void __user *argp = compat_ptr(arg);
  59. if (snd_BUG_ON(!client))
  60. return -ENXIO;
  61. switch (cmd) {
  62. case SNDRV_SEQ_IOCTL_PVERSION:
  63. case SNDRV_SEQ_IOCTL_USER_PVERSION:
  64. case SNDRV_SEQ_IOCTL_CLIENT_ID:
  65. case SNDRV_SEQ_IOCTL_SYSTEM_INFO:
  66. case SNDRV_SEQ_IOCTL_GET_CLIENT_INFO:
  67. case SNDRV_SEQ_IOCTL_SET_CLIENT_INFO:
  68. case SNDRV_SEQ_IOCTL_GET_CLIENT_UMP_INFO:
  69. case SNDRV_SEQ_IOCTL_SET_CLIENT_UMP_INFO:
  70. case SNDRV_SEQ_IOCTL_SUBSCRIBE_PORT:
  71. case SNDRV_SEQ_IOCTL_UNSUBSCRIBE_PORT:
  72. case SNDRV_SEQ_IOCTL_CREATE_QUEUE:
  73. case SNDRV_SEQ_IOCTL_DELETE_QUEUE:
  74. case SNDRV_SEQ_IOCTL_GET_QUEUE_INFO:
  75. case SNDRV_SEQ_IOCTL_SET_QUEUE_INFO:
  76. case SNDRV_SEQ_IOCTL_GET_NAMED_QUEUE:
  77. case SNDRV_SEQ_IOCTL_GET_QUEUE_STATUS:
  78. case SNDRV_SEQ_IOCTL_GET_QUEUE_TEMPO:
  79. case SNDRV_SEQ_IOCTL_SET_QUEUE_TEMPO:
  80. case SNDRV_SEQ_IOCTL_GET_QUEUE_TIMER:
  81. case SNDRV_SEQ_IOCTL_SET_QUEUE_TIMER:
  82. case SNDRV_SEQ_IOCTL_GET_QUEUE_CLIENT:
  83. case SNDRV_SEQ_IOCTL_SET_QUEUE_CLIENT:
  84. case SNDRV_SEQ_IOCTL_GET_CLIENT_POOL:
  85. case SNDRV_SEQ_IOCTL_SET_CLIENT_POOL:
  86. case SNDRV_SEQ_IOCTL_REMOVE_EVENTS:
  87. case SNDRV_SEQ_IOCTL_QUERY_SUBS:
  88. case SNDRV_SEQ_IOCTL_GET_SUBSCRIPTION:
  89. case SNDRV_SEQ_IOCTL_QUERY_NEXT_CLIENT:
  90. case SNDRV_SEQ_IOCTL_RUNNING_MODE:
  91. return snd_seq_ioctl(file, cmd, arg);
  92. case SNDRV_SEQ_IOCTL_CREATE_PORT32:
  93. return snd_seq_call_port_info_ioctl(client, SNDRV_SEQ_IOCTL_CREATE_PORT, argp);
  94. case SNDRV_SEQ_IOCTL_DELETE_PORT32:
  95. return snd_seq_call_port_info_ioctl(client, SNDRV_SEQ_IOCTL_DELETE_PORT, argp);
  96. case SNDRV_SEQ_IOCTL_GET_PORT_INFO32:
  97. return snd_seq_call_port_info_ioctl(client, SNDRV_SEQ_IOCTL_GET_PORT_INFO, argp);
  98. case SNDRV_SEQ_IOCTL_SET_PORT_INFO32:
  99. return snd_seq_call_port_info_ioctl(client, SNDRV_SEQ_IOCTL_SET_PORT_INFO, argp);
  100. case SNDRV_SEQ_IOCTL_QUERY_NEXT_PORT32:
  101. return snd_seq_call_port_info_ioctl(client, SNDRV_SEQ_IOCTL_QUERY_NEXT_PORT, argp);
  102. }
  103. return -ENOIOCTLCMD;
  104. }