1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23#include <linux/compat.h>
24
25
26
27
28
29
30
31struct snd_timer_gparams32 {
32 struct snd_timer_id tid;
33 u32 period_num;
34 u32 period_den;
35 unsigned char reserved[32];
36} __packed;
37
38struct snd_timer_info32 {
39 u32 flags;
40 s32 card;
41 unsigned char id[64];
42 unsigned char name[80];
43 u32 reserved0;
44 u32 resolution;
45 unsigned char reserved[64];
46};
47
48static int snd_timer_user_gparams_compat(struct file *file,
49 struct snd_timer_gparams32 __user *user)
50{
51 struct snd_timer_gparams gparams;
52
53 if (copy_from_user(&gparams.tid, &user->tid, sizeof(gparams.tid)) ||
54 get_user(gparams.period_num, &user->period_num) ||
55 get_user(gparams.period_den, &user->period_den))
56 return -EFAULT;
57
58 return timer_set_gparams(&gparams);
59}
60
61static int snd_timer_user_info_compat(struct file *file,
62 struct snd_timer_info32 __user *_info)
63{
64 struct snd_timer_user *tu;
65 struct snd_timer_info32 info;
66 struct snd_timer *t;
67
68 tu = file->private_data;
69 if (!tu->timeri)
70 return -EBADFD;
71 t = tu->timeri->timer;
72 if (!t)
73 return -EBADFD;
74 memset(&info, 0, sizeof(info));
75 info.card = t->card ? t->card->number : -1;
76 if (t->hw.flags & SNDRV_TIMER_HW_SLAVE)
77 info.flags |= SNDRV_TIMER_FLG_SLAVE;
78 strlcpy(info.id, t->id, sizeof(info.id));
79 strlcpy(info.name, t->name, sizeof(info.name));
80 info.resolution = t->hw.resolution;
81 if (copy_to_user(_info, &info, sizeof(*_info)))
82 return -EFAULT;
83 return 0;
84}
85
86struct snd_timer_status32 {
87 struct compat_timespec tstamp;
88 u32 resolution;
89 u32 lost;
90 u32 overrun;
91 u32 queue;
92 unsigned char reserved[64];
93};
94
95static int snd_timer_user_status_compat(struct file *file,
96 struct snd_timer_status32 __user *_status)
97{
98 struct snd_timer_user *tu;
99 struct snd_timer_status32 status;
100
101 tu = file->private_data;
102 if (!tu->timeri)
103 return -EBADFD;
104 memset(&status, 0, sizeof(status));
105 status.tstamp.tv_sec = tu->tstamp.tv_sec;
106 status.tstamp.tv_nsec = tu->tstamp.tv_nsec;
107 status.resolution = snd_timer_resolution(tu->timeri);
108 status.lost = tu->timeri->lost;
109 status.overrun = tu->overrun;
110 spin_lock_irq(&tu->qlock);
111 status.queue = tu->qused;
112 spin_unlock_irq(&tu->qlock);
113 if (copy_to_user(_status, &status, sizeof(status)))
114 return -EFAULT;
115 return 0;
116}
117
118#ifdef CONFIG_X86_X32
119
120#define snd_timer_user_status_x32(file, s) \
121 snd_timer_user_status(file, s)
122#endif
123
124
125
126
127enum {
128 SNDRV_TIMER_IOCTL_GPARAMS32 = _IOW('T', 0x04, struct snd_timer_gparams32),
129 SNDRV_TIMER_IOCTL_INFO32 = _IOR('T', 0x11, struct snd_timer_info32),
130 SNDRV_TIMER_IOCTL_STATUS32 = _IOW('T', 0x14, struct snd_timer_status32),
131#ifdef CONFIG_X86_X32
132 SNDRV_TIMER_IOCTL_STATUS_X32 = _IOW('T', 0x14, struct snd_timer_status),
133#endif
134};
135
136static long __snd_timer_user_ioctl_compat(struct file *file, unsigned int cmd,
137 unsigned long arg)
138{
139 void __user *argp = compat_ptr(arg);
140
141 switch (cmd) {
142 case SNDRV_TIMER_IOCTL_PVERSION:
143 case SNDRV_TIMER_IOCTL_TREAD:
144 case SNDRV_TIMER_IOCTL_GINFO:
145 case SNDRV_TIMER_IOCTL_GSTATUS:
146 case SNDRV_TIMER_IOCTL_SELECT:
147 case SNDRV_TIMER_IOCTL_PARAMS:
148 case SNDRV_TIMER_IOCTL_START:
149 case SNDRV_TIMER_IOCTL_START_OLD:
150 case SNDRV_TIMER_IOCTL_STOP:
151 case SNDRV_TIMER_IOCTL_STOP_OLD:
152 case SNDRV_TIMER_IOCTL_CONTINUE:
153 case SNDRV_TIMER_IOCTL_CONTINUE_OLD:
154 case SNDRV_TIMER_IOCTL_PAUSE:
155 case SNDRV_TIMER_IOCTL_PAUSE_OLD:
156 case SNDRV_TIMER_IOCTL_NEXT_DEVICE:
157 return __snd_timer_user_ioctl(file, cmd, (unsigned long)argp);
158 case SNDRV_TIMER_IOCTL_GPARAMS32:
159 return snd_timer_user_gparams_compat(file, argp);
160 case SNDRV_TIMER_IOCTL_INFO32:
161 return snd_timer_user_info_compat(file, argp);
162 case SNDRV_TIMER_IOCTL_STATUS32:
163 return snd_timer_user_status_compat(file, argp);
164#ifdef CONFIG_X86_X32
165 case SNDRV_TIMER_IOCTL_STATUS_X32:
166 return snd_timer_user_status_x32(file, argp);
167#endif
168 }
169 return -ENOIOCTLCMD;
170}
171
172static long snd_timer_user_ioctl_compat(struct file *file, unsigned int cmd,
173 unsigned long arg)
174{
175 struct snd_timer_user *tu = file->private_data;
176 long ret;
177
178 mutex_lock(&tu->ioctl_lock);
179 ret = __snd_timer_user_ioctl_compat(file, cmd, arg);
180 mutex_unlock(&tu->ioctl_lock);
181 return ret;
182}
183