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 7 /* This file included from seq.c */ 8 9 #include <linux/compat.h> 10 #include <linux/slab.h> 11 12 struct snd_seq_port_info32 { 13 struct snd_seq_addr addr; /* client/port numbers */ 14 char name[64]; /* port name */ 15 16 u32 capability; /* port capability bits */ 17 u32 type; /* port type bits */ 18 s32 midi_channels; /* channels per MIDI port */ 19 s32 midi_voices; /* voices per MIDI port */ 20 s32 synth_voices; /* voices per SYNTH port */ 21 22 s32 read_use; /* R/O: subscribers for output (from this port) */ 23 s32 write_use; /* R/O: subscribers for input (to this port) */ 24 25 u32 kernel; /* reserved for kernel use (must be NULL) */ 26 u32 flags; /* misc. conditioning */ 27 unsigned char time_queue; /* queue # for timestamping */ 28 unsigned char direction; /* port usage direction (r/w/bidir) */ 29 unsigned char ump_group; /* 0 = UMP EP (no conversion), 1-16 = UMP group number */ 30 char reserved[57]; /* for future use */ 31 }; 32 33 static int snd_seq_call_port_info_ioctl(struct snd_seq_client *client, unsigned int cmd, 34 struct snd_seq_port_info32 __user *data32) 35 { 36 int err; 37 struct snd_seq_port_info *data __free(kfree) = 38 kmalloc_obj(*data); 39 40 if (!data) 41 return -ENOMEM; 42 43 if (copy_from_user(data, data32, sizeof(*data32)) || 44 get_user(data->flags, &data32->flags) || 45 get_user(data->time_queue, &data32->time_queue) || 46 get_user(data->direction, &data32->direction) || 47 get_user(data->ump_group, &data32->ump_group)) 48 return -EFAULT; 49 data->kernel = NULL; 50 51 scoped_guard(mutex, &client->ioctl_mutex) { 52 err = snd_seq_kernel_client_ctl(client->number, cmd, data); 53 } 54 if (err < 0) 55 return err; 56 57 if (copy_to_user(data32, data, 58 offsetof(struct snd_seq_port_info32, kernel)) || 59 put_user(data->flags, &data32->flags) || 60 put_user(data->time_queue, &data32->time_queue) || 61 put_user(data->direction, &data32->direction) || 62 put_user(data->ump_group, &data32->ump_group)) 63 return -EFAULT; 64 65 return err; 66 } 67 68 69 70 /* 71 */ 72 73 enum { 74 SNDRV_SEQ_IOCTL_CREATE_PORT32 = _IOWR('S', 0x20, struct snd_seq_port_info32), 75 SNDRV_SEQ_IOCTL_DELETE_PORT32 = _IOW ('S', 0x21, struct snd_seq_port_info32), 76 SNDRV_SEQ_IOCTL_GET_PORT_INFO32 = _IOWR('S', 0x22, struct snd_seq_port_info32), 77 SNDRV_SEQ_IOCTL_SET_PORT_INFO32 = _IOW ('S', 0x23, struct snd_seq_port_info32), 78 SNDRV_SEQ_IOCTL_QUERY_NEXT_PORT32 = _IOWR('S', 0x52, struct snd_seq_port_info32), 79 }; 80 81 static long snd_seq_ioctl_compat(struct file *file, unsigned int cmd, unsigned long arg) 82 { 83 struct snd_seq_client *client = file->private_data; 84 void __user *argp = compat_ptr(arg); 85 86 if (snd_BUG_ON(!client)) 87 return -ENXIO; 88 89 switch (cmd) { 90 case SNDRV_SEQ_IOCTL_PVERSION: 91 case SNDRV_SEQ_IOCTL_USER_PVERSION: 92 case SNDRV_SEQ_IOCTL_CLIENT_ID: 93 case SNDRV_SEQ_IOCTL_SYSTEM_INFO: 94 case SNDRV_SEQ_IOCTL_GET_CLIENT_INFO: 95 case SNDRV_SEQ_IOCTL_SET_CLIENT_INFO: 96 case SNDRV_SEQ_IOCTL_GET_CLIENT_UMP_INFO: 97 case SNDRV_SEQ_IOCTL_SET_CLIENT_UMP_INFO: 98 case SNDRV_SEQ_IOCTL_SUBSCRIBE_PORT: 99 case SNDRV_SEQ_IOCTL_UNSUBSCRIBE_PORT: 100 case SNDRV_SEQ_IOCTL_CREATE_QUEUE: 101 case SNDRV_SEQ_IOCTL_DELETE_QUEUE: 102 case SNDRV_SEQ_IOCTL_GET_QUEUE_INFO: 103 case SNDRV_SEQ_IOCTL_SET_QUEUE_INFO: 104 case SNDRV_SEQ_IOCTL_GET_NAMED_QUEUE: 105 case SNDRV_SEQ_IOCTL_GET_QUEUE_STATUS: 106 case SNDRV_SEQ_IOCTL_GET_QUEUE_TEMPO: 107 case SNDRV_SEQ_IOCTL_SET_QUEUE_TEMPO: 108 case SNDRV_SEQ_IOCTL_GET_QUEUE_TIMER: 109 case SNDRV_SEQ_IOCTL_SET_QUEUE_TIMER: 110 case SNDRV_SEQ_IOCTL_GET_QUEUE_CLIENT: 111 case SNDRV_SEQ_IOCTL_SET_QUEUE_CLIENT: 112 case SNDRV_SEQ_IOCTL_GET_CLIENT_POOL: 113 case SNDRV_SEQ_IOCTL_SET_CLIENT_POOL: 114 case SNDRV_SEQ_IOCTL_REMOVE_EVENTS: 115 case SNDRV_SEQ_IOCTL_QUERY_SUBS: 116 case SNDRV_SEQ_IOCTL_GET_SUBSCRIPTION: 117 case SNDRV_SEQ_IOCTL_QUERY_NEXT_CLIENT: 118 case SNDRV_SEQ_IOCTL_RUNNING_MODE: 119 return snd_seq_ioctl(file, cmd, arg); 120 case SNDRV_SEQ_IOCTL_CREATE_PORT32: 121 return snd_seq_call_port_info_ioctl(client, SNDRV_SEQ_IOCTL_CREATE_PORT, argp); 122 case SNDRV_SEQ_IOCTL_DELETE_PORT32: 123 return snd_seq_call_port_info_ioctl(client, SNDRV_SEQ_IOCTL_DELETE_PORT, argp); 124 case SNDRV_SEQ_IOCTL_GET_PORT_INFO32: 125 return snd_seq_call_port_info_ioctl(client, SNDRV_SEQ_IOCTL_GET_PORT_INFO, argp); 126 case SNDRV_SEQ_IOCTL_SET_PORT_INFO32: 127 return snd_seq_call_port_info_ioctl(client, SNDRV_SEQ_IOCTL_SET_PORT_INFO, argp); 128 case SNDRV_SEQ_IOCTL_QUERY_NEXT_PORT32: 129 return snd_seq_call_port_info_ioctl(client, SNDRV_SEQ_IOCTL_QUERY_NEXT_PORT, argp); 130 } 131 return -ENOIOCTLCMD; 132 } 133