hc
2024-10-22 8ac6c7a54ed1b98d142dce24b11c6de6a1e239a5
kernel/sound/core/rawmidi_compat.c
....@@ -1,21 +1,7 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /*
23 * 32bit -> 64bit ioctl wrapper for raw MIDI API
34 * Copyright (c) by Takashi Iwai <tiwai@suse.de>
4
- *
5
- * This program is free software; you can redistribute it and/or modify
6
- * it under the terms of the GNU General Public License as published by
7
- * the Free Software Foundation; either version 2 of the License, or
8
- * (at your option) any later version.
9
- *
10
- * This program is distributed in the hope that it will be useful,
11
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
- * GNU General Public License for more details.
14
- *
15
- * You should have received a copy of the GNU General Public License
16
- * along with this program; if not, write to the Free Software
17
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18
- *
195 */
206
217 /* This file included from rawmidi.c */
....@@ -55,19 +41,22 @@
5541 return -EINVAL;
5642 }
5743
58
-struct snd_rawmidi_status32 {
44
+struct compat_snd_rawmidi_status64 {
5945 s32 stream;
60
- struct compat_timespec tstamp;
46
+ u8 rsvd[4]; /* alignment */
47
+ s64 tstamp_sec;
48
+ s64 tstamp_nsec;
6149 u32 avail;
6250 u32 xruns;
6351 unsigned char reserved[16];
6452 } __attribute__((packed));
6553
66
-static int snd_rawmidi_ioctl_status_compat(struct snd_rawmidi_file *rfile,
67
- struct snd_rawmidi_status32 __user *src)
54
+static int snd_rawmidi_ioctl_status_compat64(struct snd_rawmidi_file *rfile,
55
+ struct compat_snd_rawmidi_status64 __user *src)
6856 {
6957 int err;
70
- struct snd_rawmidi_status status;
58
+ struct snd_rawmidi_status64 status;
59
+ struct compat_snd_rawmidi_status64 compat_status;
7160
7261 if (get_user(status.stream, &src->stream))
7362 return -EFAULT;
....@@ -89,68 +78,24 @@
8978 if (err < 0)
9079 return err;
9180
92
- if (compat_put_timespec(&status.tstamp, &src->tstamp) ||
93
- put_user(status.avail, &src->avail) ||
94
- put_user(status.xruns, &src->xruns))
81
+ compat_status = (struct compat_snd_rawmidi_status64) {
82
+ .stream = status.stream,
83
+ .tstamp_sec = status.tstamp_sec,
84
+ .tstamp_nsec = status.tstamp_nsec,
85
+ .avail = status.avail,
86
+ .xruns = status.xruns,
87
+ };
88
+
89
+ if (copy_to_user(src, &compat_status, sizeof(*src)))
9590 return -EFAULT;
9691
9792 return 0;
9893 }
99
-
100
-#ifdef CONFIG_X86_X32
101
-/* X32 ABI has 64bit timespec and 64bit alignment */
102
-struct snd_rawmidi_status_x32 {
103
- s32 stream;
104
- u32 rsvd; /* alignment */
105
- struct timespec tstamp;
106
- u32 avail;
107
- u32 xruns;
108
- unsigned char reserved[16];
109
-} __attribute__((packed));
110
-
111
-#define put_timespec(src, dst) copy_to_user(dst, src, sizeof(*dst))
112
-
113
-static int snd_rawmidi_ioctl_status_x32(struct snd_rawmidi_file *rfile,
114
- struct snd_rawmidi_status_x32 __user *src)
115
-{
116
- int err;
117
- struct snd_rawmidi_status status;
118
-
119
- if (get_user(status.stream, &src->stream))
120
- return -EFAULT;
121
-
122
- switch (status.stream) {
123
- case SNDRV_RAWMIDI_STREAM_OUTPUT:
124
- if (!rfile->output)
125
- return -EINVAL;
126
- err = snd_rawmidi_output_status(rfile->output, &status);
127
- break;
128
- case SNDRV_RAWMIDI_STREAM_INPUT:
129
- if (!rfile->input)
130
- return -EINVAL;
131
- err = snd_rawmidi_input_status(rfile->input, &status);
132
- break;
133
- default:
134
- return -EINVAL;
135
- }
136
- if (err < 0)
137
- return err;
138
-
139
- if (put_timespec(&status.tstamp, &src->tstamp) ||
140
- put_user(status.avail, &src->avail) ||
141
- put_user(status.xruns, &src->xruns))
142
- return -EFAULT;
143
-
144
- return 0;
145
-}
146
-#endif /* CONFIG_X86_X32 */
14794
14895 enum {
14996 SNDRV_RAWMIDI_IOCTL_PARAMS32 = _IOWR('W', 0x10, struct snd_rawmidi_params32),
150
- SNDRV_RAWMIDI_IOCTL_STATUS32 = _IOWR('W', 0x20, struct snd_rawmidi_status32),
151
-#ifdef CONFIG_X86_X32
152
- SNDRV_RAWMIDI_IOCTL_STATUS_X32 = _IOWR('W', 0x20, struct snd_rawmidi_status_x32),
153
-#endif /* CONFIG_X86_X32 */
97
+ SNDRV_RAWMIDI_IOCTL_STATUS_COMPAT32 = _IOWR('W', 0x20, struct snd_rawmidi_status32),
98
+ SNDRV_RAWMIDI_IOCTL_STATUS_COMPAT64 = _IOWR('W', 0x20, struct compat_snd_rawmidi_status64),
15499 };
155100
156101 static long snd_rawmidi_ioctl_compat(struct file *file, unsigned int cmd, unsigned long arg)
....@@ -167,12 +112,10 @@
167112 return snd_rawmidi_ioctl(file, cmd, (unsigned long)argp);
168113 case SNDRV_RAWMIDI_IOCTL_PARAMS32:
169114 return snd_rawmidi_ioctl_params_compat(rfile, argp);
170
- case SNDRV_RAWMIDI_IOCTL_STATUS32:
171
- return snd_rawmidi_ioctl_status_compat(rfile, argp);
172
-#ifdef CONFIG_X86_X32
173
- case SNDRV_RAWMIDI_IOCTL_STATUS_X32:
174
- return snd_rawmidi_ioctl_status_x32(rfile, argp);
175
-#endif /* CONFIG_X86_X32 */
115
+ case SNDRV_RAWMIDI_IOCTL_STATUS_COMPAT32:
116
+ return snd_rawmidi_ioctl_status32(rfile, argp);
117
+ case SNDRV_RAWMIDI_IOCTL_STATUS_COMPAT64:
118
+ return snd_rawmidi_ioctl_status_compat64(rfile, argp);
176119 }
177120 return -ENOIOCTLCMD;
178121 }