vserver 1.9.5.x5
[linux-2.6.git] / sound / isa / sscape.c
index b685311..3959ed6 100644 (file)
 #include <linux/delay.h>
 #include <linux/pnp.h>
 #include <linux/spinlock.h>
+#include <linux/moduleparam.h>
 #include <asm/dma.h>
 #include <sound/core.h>
 #include <sound/hwdep.h>
 #include <sound/cs4231.h>
 #include <sound/mpu401.h>
-#define SNDRV_GET_ID
 #include <sound/initval.h>
 
 #include <sound/sscape_ioctl.h>
 
-#define chip_t cs4231_t
-
 
 MODULE_AUTHOR("Chris Rankin");
 MODULE_DESCRIPTION("ENSONIQ SoundScape PnP driver");
@@ -50,29 +48,23 @@ static int irq[SNDRV_CARDS] __devinitdata = SNDRV_DEFAULT_IRQ;
 static int mpu_irq[SNDRV_CARDS] __devinitdata = SNDRV_DEFAULT_IRQ;
 static int dma[SNDRV_CARDS] __devinitdata = SNDRV_DEFAULT_DMA;
 
-MODULE_PARM(index, "1-" __MODULE_STRING(SNDRV_CARDS) "i");
+module_param_array(index, int, NULL, 0444);
 MODULE_PARM_DESC(index, "Index number for SoundScape soundcard");
-MODULE_PARM_SYNTAX(index, SNDRV_INDEX_DESC);
 
-MODULE_PARM(id, "1-" __MODULE_STRING(SNDRV_CARDS) "s");
+module_param_array(id, charp, NULL, 0444);
 MODULE_PARM_DESC(id, "Description for SoundScape card");
-MODULE_PARM_SYNTAX(id, SNDRV_ID_DESC);
 
-MODULE_PARM(port, "1-" __MODULE_STRING(SNDRV_CARDS) "l");
+module_param_array(port, long, NULL, 0444);
 MODULE_PARM_DESC(port, "Port # for SoundScape driver.");
-MODULE_PARM_SYNTAX(port, SNDRV_ENABLED);
 
-MODULE_PARM(irq, "1-" __MODULE_STRING(SNDRV_CARDS) "i");
+module_param_array(irq, int, NULL, 0444);
 MODULE_PARM_DESC(irq, "IRQ # for SoundScape driver.");
-MODULE_PARM_SYNTAX(irq, SNDRV_IRQ_DESC);
 
-MODULE_PARM(mpu_irq, "1-" __MODULE_STRING(SNDRV_CARDS) "i");
+module_param_array(mpu_irq, int, NULL, 0444);
 MODULE_PARM_DESC(mpu_irq, "MPU401 IRQ # for SoundScape driver.");
-MODULE_PARM_SYNTAX(mpu_irq, SNDRV_IRQ_DESC);
 
-MODULE_PARM(dma, "1-" __MODULE_STRING(SNDRV_CARDS) "i");
+module_param_array(dma, int, NULL, 0444);
 MODULE_PARM_DESC(dma, "DMA # for SoundScape driver.");
-MODULE_PARM_SYNTAX(dma, SNDRV_DMA8_DESC);
   
 #ifdef CONFIG_PNP
 static struct pnp_card_device_id sscape_pnpids[] = {
@@ -176,11 +168,8 @@ static inline struct soundscape *get_hwdep_soundscape(snd_hwdep_t * hw)
 static struct snd_dma_buffer *get_dmabuf(struct snd_dma_buffer *buf, unsigned long size)
 {
        if (buf) {
-               struct snd_dma_device dev;
-               memset(&dev, 0, sizeof(dev));
-               dev.type = SNDRV_DMA_TYPE_DEV;
-               dev.dev = snd_dma_isa_data();
-               if (snd_dma_alloc_pages_fallback(&dev, size, buf) < 0) {
+               if (snd_dma_alloc_pages_fallback(SNDRV_DMA_TYPE_DEV, snd_dma_isa_data(),
+                                                size, buf) < 0) {
                        snd_printk(KERN_ERR "sscape: Failed to allocate %lu bytes for DMA\n", size);
                        return NULL;
                }
@@ -194,13 +183,8 @@ static struct snd_dma_buffer *get_dmabuf(struct snd_dma_buffer *buf, unsigned lo
  */
 static void free_dmabuf(struct snd_dma_buffer *buf)
 {
-       if (buf && buf->area) {
-               struct snd_dma_device dev;
-               memset(&dev, 0, sizeof(dev));
-               dev.type = SNDRV_DMA_TYPE_DEV;
-               dev.dev = snd_dma_isa_data();
-               snd_dma_free_pages(&dev, buf);
-       }
+       if (buf && buf->area)
+               snd_dma_free_pages(buf);
 }
 
 
@@ -454,7 +438,7 @@ static int host_startup_ack(struct soundscape *s, unsigned timeout)
  * Upload a byte-stream into the SoundScape using DMA channel A.
  */
 static int upload_dma_data(struct soundscape *s,
-                           const unsigned char *data,
+                           const unsigned char __user *data,
                            size_t size)
 {
        unsigned long flags;
@@ -503,7 +487,7 @@ static int upload_dma_data(struct soundscape *s,
                 * the userspace pointer ...
                 */
                len = min(size, dma.bytes);
-               __copy_from_user(dma.area, data, len);
+               len -= __copy_from_user(dma.area, data, len);
                data += len;
                size -= len;
 
@@ -568,7 +552,7 @@ static int upload_dma_data(struct soundscape *s,
  *       However, we have already verified its memory
  *       addresses by the time we get here.
  */
-static int sscape_upload_bootblock(struct soundscape *sscape, struct sscape_bootblock *bb)
+static int sscape_upload_bootblock(struct soundscape *sscape, struct sscape_bootblock __user *bb)
 {
        unsigned long flags;
        int data = 0;
@@ -587,8 +571,9 @@ static int sscape_upload_bootblock(struct soundscape *sscape, struct sscape_boot
                if (data < 0) {
                        snd_printk(KERN_ERR "sscape: timeout reading firmware version\n");
                        ret = -EAGAIN;
-               } else {
-                       __copy_to_user(&bb->version, &data, sizeof(bb->version));
+               }
+               else if (__copy_to_user(&bb->version, &data, sizeof(bb->version))) {
+                       ret = -EFAULT;
                }
        }
 
@@ -603,11 +588,11 @@ static int sscape_upload_bootblock(struct soundscape *sscape, struct sscape_boot
  * SPACE, and save ourselves from copying it at all.
  */
 static int sscape_upload_microcode(struct soundscape *sscape,
-                                   const struct sscape_microcode *mc)
+                                   const struct sscape_microcode __user *mc)
 {
        unsigned long flags;
-       char *code;
-       int err, ret;
+       char __user *code;
+       int err;
 
        /*
         * We are going to have to copy this data into a special
@@ -617,12 +602,11 @@ static int sscape_upload_microcode(struct soundscape *sscape,
         * NOTE: This buffer is 64K long! That's WAY too big to
         *       copy into a stack-temporary anyway.
         */
-       if (get_user(code, &mc->code))
+       if ( get_user(code, &mc->code) ||
+            !access_ok(VERIFY_READ, code, SSCAPE_MICROCODE_SIZE) )
                return -EFAULT;
-       if ((err = verify_area(VERIFY_READ, code, SSCAPE_MICROCODE_SIZE)) != 0)
-               return err;
 
-       if ((ret = upload_dma_data(sscape, code, SSCAPE_MICROCODE_SIZE)) == 0) {
+       if ((err = upload_dma_data(sscape, code, SSCAPE_MICROCODE_SIZE)) == 0) {
                snd_printk(KERN_INFO "sscape: MIDI firmware loaded\n");
        }
 
@@ -632,7 +616,7 @@ static int sscape_upload_microcode(struct soundscape *sscape,
 
        initialise_mpu401(sscape->mpu);
 
-       return ret;
+       return err;
 }
 
 /*
@@ -682,21 +666,21 @@ static int sscape_hw_ioctl(snd_hwdep_t * hw, struct file *file,
        switch (cmd) {
        case SND_SSCAPE_LOAD_BOOTB:
                {
-                       register struct sscape_bootblock *bb = (struct sscape_bootblock *) arg;
+                       register struct sscape_bootblock __user *bb = (struct sscape_bootblock __user *) arg;
 
                        /*
                         * We are going to have to copy this data into a special
                         * DMA-able buffer before we can upload it. We shall therefore
                         * just check that the data pointer is valid for now ...
                         */
-                       if ((err = verify_area(VERIFY_READ, bb->code, sizeof(bb->code))) != 0)
-                               return err;
+                       if ( !access_ok(VERIFY_READ, bb->code, sizeof(bb->code)) )
+                               return -EFAULT;
 
                        /*
                         * Now check that we can write the firmware version number too...
                         */
-                       if ((err = verify_area(VERIFY_WRITE, &bb->version, sizeof(bb->version))) != 0)
-                               return err;
+                       if ( !access_ok(VERIFY_WRITE, &bb->version, sizeof(bb->version)) )
+                               return -EFAULT;
 
                        err = sscape_upload_bootblock(sscape, bb);
                }
@@ -704,7 +688,7 @@ static int sscape_hw_ioctl(snd_hwdep_t * hw, struct file *file,
 
        case SND_SSCAPE_LOAD_MCODE:
                {
-                       register const struct sscape_microcode *mc = (const struct sscape_microcode *) arg;
+                       register const struct sscape_microcode __user *mc = (const struct sscape_microcode __user *) arg;
 
                        err = sscape_upload_microcode(sscape, mc);
                }
@@ -1531,30 +1515,3 @@ static int __init sscape_init(void)
 
 module_init(sscape_init);
 module_exit(sscape_exit);
-
-#ifndef MODULE
-
-/* format is: snd-sscape=index,id,port,irq,mpu_irq,dma */
-
-static int __init builtin_sscape_setup(char *str)
-{
-       static unsigned __initdata nr_dev;
-
-       if (nr_dev >= SNDRV_CARDS)
-               return 0;
-
-       (void)((get_option(&str, &index[nr_dev]) == 2) &&
-              (get_id(&str, &id[nr_dev]) == 2) &&
-              (get_option_long(&str, &port[nr_dev]) == 2) &&
-              (get_option(&str, &irq[nr_dev]) == 2) &&
-              (get_option(&str, &mpu_irq[nr_dev]) == 2) &&
-              (get_option(&str, &dma[nr_dev]) == 2)); 
-       ++nr_dev;
-       return 1;
-}
-
-__setup("snd-sscape=", builtin_sscape_setup);
-
-#endif
-