vserver 1.9.3
[linux-2.6.git] / sound / core / seq / oss / seq_oss_ioctl.c
index d5973a8..e86f18d 100644 (file)
 #include "seq_oss_midi.h"
 #include "seq_oss_event.h"
 
+static int snd_seq_oss_synth_info_user(seq_oss_devinfo_t *dp, void __user *arg)
+{
+       struct synth_info info;
+
+       if (copy_from_user(&info, arg, sizeof(info)))
+               return -EFAULT;
+       if (snd_seq_oss_synth_make_info(dp, info.device, &info) < 0)
+               return -EINVAL;
+       if (copy_to_user(arg, &info, sizeof(info)))
+               return -EFAULT;
+       return 0;
+}
+
+static int snd_seq_oss_midi_info_user(seq_oss_devinfo_t *dp, void __user *arg)
+{
+       struct midi_info info;
+
+       if (copy_from_user(&info, arg, sizeof(info)))
+               return -EFAULT;
+       if (snd_seq_oss_midi_make_info(dp, info.device, &info) < 0)
+               return -EINVAL;
+       if (copy_to_user(arg, &info, sizeof(info)))
+               return -EFAULT;
+       return 0;
+}
+
+static int snd_seq_oss_oob_user(seq_oss_devinfo_t *dp, void __user *arg)
+{
+       unsigned char ev[8];
+       snd_seq_event_t tmpev;
+
+       if (copy_from_user(ev, arg, 8))
+               return -EFAULT;
+       memset(&tmpev, 0, sizeof(tmpev));
+       snd_seq_oss_fill_addr(dp, &tmpev, dp->addr.port, dp->addr.client);
+       tmpev.time.tick = 0;
+       if (! snd_seq_oss_process_event(dp, (evrec_t*)ev, &tmpev)) {
+               snd_seq_oss_dispatch(dp, &tmpev, 0, 0);
+       }
+       return 0;
+}
+
 int
 snd_seq_oss_ioctl(seq_oss_devinfo_t *dp, unsigned int cmd, unsigned long carg)
 {
        int dev, val;
-       struct synth_info inf;
-       struct midi_info minf;
-       unsigned char ev[8];
        void __user *arg = (void __user *)carg;
-       snd_seq_event_t tmpev;
+       int __user *p = arg;
 
        switch (cmd) {
        case SNDCTL_TMR_TIMEBASE:
@@ -72,7 +111,7 @@ snd_seq_oss_ioctl(seq_oss_devinfo_t *dp, unsigned int cmd, unsigned long carg)
 
        case SNDCTL_SEQ_TESTMIDI:
                debug_printk(("test midi\n"));
-               if (get_user(dev, (int *)arg))
+               if (get_user(dev, p))
                        return -EFAULT;
                return snd_seq_oss_midi_open(dp, dev, dp->file_mode);
 
@@ -80,42 +119,42 @@ snd_seq_oss_ioctl(seq_oss_devinfo_t *dp, unsigned int cmd, unsigned long carg)
                debug_printk(("get in count\n"));
                if (dp->readq == NULL || ! is_read_mode(dp->file_mode))
                        return 0;
-               return put_user(dp->readq->qlen, (int *)arg) ? -EFAULT : 0;
+               return put_user(dp->readq->qlen, p) ? -EFAULT : 0;
 
        case SNDCTL_SEQ_GETOUTCOUNT:
                debug_printk(("get out count\n"));
                if (! is_write_mode(dp->file_mode) || dp->writeq == NULL)
                        return 0;
-               return put_user(snd_seq_oss_writeq_get_free_size(dp->writeq), (int *)arg) ? -EFAULT : 0;
+               return put_user(snd_seq_oss_writeq_get_free_size(dp->writeq), p) ? -EFAULT : 0;
 
        case SNDCTL_SEQ_GETTIME:
                debug_printk(("get time\n"));
-               return put_user(snd_seq_oss_timer_cur_tick(dp->timer), (int *)arg) ? -EFAULT : 0;
+               return put_user(snd_seq_oss_timer_cur_tick(dp->timer), p) ? -EFAULT : 0;
 
        case SNDCTL_SEQ_RESETSAMPLES:
                debug_printk(("reset samples\n"));
-               if (get_user(dev, (int *)arg))
+               if (get_user(dev, p))
                        return -EFAULT;
                return snd_seq_oss_synth_ioctl(dp, dev, cmd, carg);
 
        case SNDCTL_SEQ_NRSYNTHS:
                debug_printk(("nr synths\n"));
-               return put_user(dp->max_synthdev, (int *)arg) ? -EFAULT : 0;
+               return put_user(dp->max_synthdev, p) ? -EFAULT : 0;
 
        case SNDCTL_SEQ_NRMIDIS:
                debug_printk(("nr midis\n"));
-               return put_user(dp->max_mididev, (int *)arg) ? -EFAULT : 0;
+               return put_user(dp->max_mididev, p) ? -EFAULT : 0;
 
        case SNDCTL_SYNTH_MEMAVL:
                debug_printk(("mem avail\n"));
-               if (get_user(dev, (int *)arg))
+               if (get_user(dev, p))
                        return -EFAULT;
                val = snd_seq_oss_synth_ioctl(dp, dev, cmd, carg);
-               return put_user(val, (int *)arg) ? -EFAULT : 0;
+               return put_user(val, p) ? -EFAULT : 0;
 
        case SNDCTL_FM_4OP_ENABLE:
                debug_printk(("4op\n"));
-               if (get_user(dev, (int *)arg))
+               if (get_user(dev, p))
                        return -EFAULT;
                snd_seq_oss_synth_ioctl(dp, dev, cmd, carg);
                return 0;
@@ -123,41 +162,21 @@ snd_seq_oss_ioctl(seq_oss_devinfo_t *dp, unsigned int cmd, unsigned long carg)
        case SNDCTL_SYNTH_INFO:
        case SNDCTL_SYNTH_ID:
                debug_printk(("synth info\n"));
-               if (copy_from_user(&inf, arg, sizeof(inf)))
-                       return -EFAULT;
-               if (snd_seq_oss_synth_make_info(dp, inf.device, &inf) < 0)
-                       return -EINVAL;
-               if (copy_to_user(arg, &inf, sizeof(inf)))
-                       return -EFAULT;
-               return 0;
+               return snd_seq_oss_synth_info_user(dp, arg);
 
        case SNDCTL_SEQ_OUTOFBAND:
-               debug_printk(("out of bound\n"));
-               if (copy_from_user(ev, arg, 8))
-                       return -EFAULT;
-               memset(&tmpev, 0, sizeof(tmpev));
-               snd_seq_oss_fill_addr(dp, &tmpev, dp->addr.port, dp->addr.client);
-               tmpev.time.tick = 0;
-               if (! snd_seq_oss_process_event(dp, (evrec_t*)ev, &tmpev)) {
-                       snd_seq_oss_dispatch(dp, &tmpev, 0, 0);
-               }
-               return 0;
+               debug_printk(("out of band\n"));
+               return snd_seq_oss_oob_user(dp, arg);
 
        case SNDCTL_MIDI_INFO:
                debug_printk(("midi info\n"));
-               if (copy_from_user(&minf, arg, sizeof(minf)))
-                       return -EFAULT;
-               if (snd_seq_oss_midi_make_info(dp, minf.device, &minf) < 0)
-                       return -EINVAL;
-               if (copy_to_user(arg, &minf, sizeof(minf)))
-                       return -EFAULT;
-               return 0;
+               return snd_seq_oss_midi_info_user(dp, arg);
 
        case SNDCTL_SEQ_THRESHOLD:
                debug_printk(("threshold\n"));
                if (! is_write_mode(dp->file_mode))
                        return 0;
-               if (get_user(val, (int *)arg))
+               if (get_user(val, p))
                        return -EFAULT;
                if (val < 1)
                        val = 1;
@@ -170,14 +189,14 @@ snd_seq_oss_ioctl(seq_oss_devinfo_t *dp, unsigned int cmd, unsigned long carg)
                debug_printk(("pretime\n"));
                if (dp->readq == NULL || !is_read_mode(dp->file_mode))
                        return 0;
-               if (get_user(val, (int *)arg))
+               if (get_user(val, p))
                        return -EFAULT;
                if (val <= 0)
                        val = -1;
                else
                        val = (HZ * val) / 10;
                dp->readq->pre_event_timeout = val;
-               return put_user(val, (int *)arg) ? -EFAULT : 0;
+               return put_user(val, p) ? -EFAULT : 0;
 
        default:
                debug_printk(("others\n"));