1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22#include <sound/core.h>
23#include <sound/hwdep.h>
24#include <linux/uaccess.h>
25#include <linux/nospec.h>
26#include "emux_voice.h"
27
28#define TMP_CLIENT_ID 0x1001
29
30
31
32
33static int
34snd_emux_hwdep_load_patch(struct snd_emux *emu, void __user *arg)
35{
36 int err;
37 struct soundfont_patch_info patch;
38
39 if (copy_from_user(&patch, arg, sizeof(patch)))
40 return -EFAULT;
41
42 if (patch.type >= SNDRV_SFNT_LOAD_INFO &&
43 patch.type <= SNDRV_SFNT_PROBE_DATA) {
44 err = snd_soundfont_load(emu->sflist, arg, patch.len + sizeof(patch), TMP_CLIENT_ID);
45 if (err < 0)
46 return err;
47 } else {
48 if (emu->ops.load_fx)
49 return emu->ops.load_fx(emu, patch.type, patch.optarg, arg, patch.len + sizeof(patch));
50 else
51 return -EINVAL;
52 }
53 return 0;
54}
55
56
57
58
59static int
60snd_emux_hwdep_misc_mode(struct snd_emux *emu, void __user *arg)
61{
62 struct snd_emux_misc_mode info;
63 int i;
64
65 if (copy_from_user(&info, arg, sizeof(info)))
66 return -EFAULT;
67 if (info.mode < 0 || info.mode >= EMUX_MD_END)
68 return -EINVAL;
69 info.mode = array_index_nospec(info.mode, EMUX_MD_END);
70
71 if (info.port < 0) {
72 for (i = 0; i < emu->num_ports; i++)
73 emu->portptrs[i]->ctrls[info.mode] = info.value;
74 } else {
75 if (info.port < emu->num_ports) {
76 info.port = array_index_nospec(info.port, emu->num_ports);
77 emu->portptrs[info.port]->ctrls[info.mode] = info.value;
78 }
79 }
80 return 0;
81}
82
83
84
85
86
87static int
88snd_emux_hwdep_ioctl(struct snd_hwdep * hw, struct file *file,
89 unsigned int cmd, unsigned long arg)
90{
91 struct snd_emux *emu = hw->private_data;
92
93 switch (cmd) {
94 case SNDRV_EMUX_IOCTL_VERSION:
95 return put_user(SNDRV_EMUX_VERSION, (unsigned int __user *)arg);
96 case SNDRV_EMUX_IOCTL_LOAD_PATCH:
97 return snd_emux_hwdep_load_patch(emu, (void __user *)arg);
98 case SNDRV_EMUX_IOCTL_RESET_SAMPLES:
99 snd_soundfont_remove_samples(emu->sflist);
100 break;
101 case SNDRV_EMUX_IOCTL_REMOVE_LAST_SAMPLES:
102 snd_soundfont_remove_unlocked(emu->sflist);
103 break;
104 case SNDRV_EMUX_IOCTL_MEM_AVAIL:
105 if (emu->memhdr) {
106 int size = snd_util_mem_avail(emu->memhdr);
107 return put_user(size, (unsigned int __user *)arg);
108 }
109 break;
110 case SNDRV_EMUX_IOCTL_MISC_MODE:
111 return snd_emux_hwdep_misc_mode(emu, (void __user *)arg);
112 }
113
114 return 0;
115}
116
117
118
119
120
121
122int
123snd_emux_init_hwdep(struct snd_emux *emu)
124{
125 struct snd_hwdep *hw;
126 int err;
127
128 if ((err = snd_hwdep_new(emu->card, SNDRV_EMUX_HWDEP_NAME, emu->hwdep_idx, &hw)) < 0)
129 return err;
130 emu->hwdep = hw;
131 strcpy(hw->name, SNDRV_EMUX_HWDEP_NAME);
132 hw->iface = SNDRV_HWDEP_IFACE_EMUX_WAVETABLE;
133 hw->ops.ioctl = snd_emux_hwdep_ioctl;
134
135
136 hw->ops.ioctl_compat = snd_emux_hwdep_ioctl;
137 hw->exclusive = 1;
138 hw->private_data = emu;
139 if ((err = snd_card_register(emu->card)) < 0)
140 return err;
141
142 return 0;
143}
144
145
146
147
148
149void
150snd_emux_delete_hwdep(struct snd_emux *emu)
151{
152 if (emu->hwdep) {
153 snd_device_free(emu->card, emu->hwdep);
154 emu->hwdep = NULL;
155 }
156}
157