vserver 1.9.3
[linux-2.6.git] / sound / isa / wavefront / wavefront_synth.c
index 0b3755f..1d9ee96 100644 (file)
@@ -27,6 +27,7 @@
 #include <linux/delay.h>
 #include <linux/time.h>
 #include <linux/wait.h>
+#include <linux/moduleparam.h>
 #include <sound/core.h>
 #include <sound/snd_wavefront.h>
 #include <sound/initval.h>
@@ -83,25 +84,25 @@ int ramcheck_time = 20;    /* time in seconds to wait while ROM code
 int osrun_time = 10;       /* time in seconds we wait for the OS to
                              start running.
                           */
-MODULE_PARM(wf_raw,"i");
+module_param(wf_raw, int, 0444);
 MODULE_PARM_DESC(wf_raw, "if non-zero, assume that we need to boot the OS");
-MODULE_PARM(fx_raw,"i");
+module_param(fx_raw, int, 0444);
 MODULE_PARM_DESC(fx_raw, "if non-zero, assume that the FX process needs help");
-MODULE_PARM(debug_default,"i");
+module_param(debug_default, int, 0444);
 MODULE_PARM_DESC(debug_default, "debug parameters for card initialization");
-MODULE_PARM(wait_usecs,"i");
+module_param(wait_usecs, int, 0444);
 MODULE_PARM_DESC(wait_usecs, "how long to wait without sleeping, usecs");
-MODULE_PARM(sleep_interval,"i");
+module_param(sleep_interval, int, 0444);
 MODULE_PARM_DESC(sleep_interval, "how long to sleep when waiting for reply");
-MODULE_PARM(sleep_tries,"i");
+module_param(sleep_tries, int, 0444);
 MODULE_PARM_DESC(sleep_tries, "how many times to try sleeping during a wait");
-MODULE_PARM(ospath,"s");
+module_param(ospath, charp, 0444);
 MODULE_PARM_DESC(ospath, "full pathname to processed ICS2115 OS firmware");
-MODULE_PARM(reset_time,"i");
+module_param(reset_time, int, 0444);
 MODULE_PARM_DESC(reset_time, "how long to wait for a reset to take effect");
-MODULE_PARM(ramcheck_time,"i");
+module_param(ramcheck_time, int, 0444);
 MODULE_PARM_DESC(ramcheck_time, "how many seconds to wait for the RAM test");
-MODULE_PARM(osrun_time,"i");
+module_param(osrun_time, int, 0444);
 MODULE_PARM_DESC(osrun_time, "how many seconds to wait for the ICS2115 OS");
 
 /* if WF_DEBUG not defined, no run-time debugging messages will
@@ -122,7 +123,7 @@ MODULE_PARM_DESC(osrun_time, "how many seconds to wait for the ICS2115 OS");
 #else
 #define DPRINT(cond, args...) \
        if ((dev->debug & (cond)) == (cond)) { \
-            snd_printk (##args); \
+            snd_printk (args); \
        }
 #endif
 #else
@@ -164,7 +165,7 @@ static struct {
        { 0x0E, "Bad MIDI channel number" },
        { 0x10, "Download Record Error" },
        { 0x80, "Success" },
-       { 0x0, 0x0 }
+       { 0x0 }
 };
 
 #define NEEDS_ACK 1
@@ -360,7 +361,7 @@ snd_wavefront_cmd (snd_wavefront_t *dev,
 
        if (cmd == WFC_DOWNLOAD_MULTISAMPLE) {
                wfcmd->write_cnt = (unsigned long) rbuf;
-               rbuf = 0;
+               rbuf = NULL;
        }
 
        DPRINT (WF_DEBUG_CMD, "0x%x [%s] (%d,%d,%d)\n",
@@ -611,7 +612,7 @@ wavefront_delete_sample (snd_wavefront_t *dev, int sample_num)
        wbuf[0] = sample_num & 0x7f;
        wbuf[1] = sample_num >> 7;
 
-       if ((x = snd_wavefront_cmd (dev, WFC_DELETE_SAMPLE, 0, wbuf)) == 0) {
+       if ((x = snd_wavefront_cmd (dev, WFC_DELETE_SAMPLE, NULL, wbuf)) == 0) {
                dev->sample_status[sample_num] = WF_ST_EMPTY;
        }
 
@@ -797,7 +798,7 @@ wavefront_send_patch (snd_wavefront_t *dev, wavefront_patch_info *header)
        bptr = munge_int32 (header->number, buf, 2);
        munge_buf ((unsigned char *)&header->hdr.p, bptr, WF_PATCH_BYTES);
     
-       if (snd_wavefront_cmd (dev, WFC_DOWNLOAD_PATCH, 0, buf)) {
+       if (snd_wavefront_cmd (dev, WFC_DOWNLOAD_PATCH, NULL, buf)) {
                snd_printk ("download patch failed\n");
                return -(EIO);
        }
@@ -835,7 +836,7 @@ wavefront_send_program (snd_wavefront_t *dev, wavefront_patch_info *header)
        buf[0] = header->number;
        munge_buf ((unsigned char *)&header->hdr.pr, &buf[1], WF_PROGRAM_BYTES);
     
-       if (snd_wavefront_cmd (dev, WFC_DOWNLOAD_PROGRAM, 0, buf)) {
+       if (snd_wavefront_cmd (dev, WFC_DOWNLOAD_PROGRAM, NULL, buf)) {
                snd_printk ("download patch failed\n"); 
                return -(EIO);
        }
@@ -849,7 +850,7 @@ wavefront_freemem (snd_wavefront_t *dev)
 {
        char rbuf[8];
 
-       if (snd_wavefront_cmd (dev, WFC_REPORT_FREE_MEMORY, rbuf, 0)) {
+       if (snd_wavefront_cmd (dev, WFC_REPORT_FREE_MEMORY, rbuf, NULL)) {
                snd_printk ("can't get memory stats.\n");
                return -1;
        } else {
@@ -860,7 +861,7 @@ wavefront_freemem (snd_wavefront_t *dev)
 static int
 wavefront_send_sample (snd_wavefront_t *dev, 
                       wavefront_patch_info *header,
-                      u16 *dataptr,
+                      u16 __user *dataptr,
                       int data_is_unsigned)
 
 {
@@ -875,7 +876,7 @@ wavefront_send_sample (snd_wavefront_t *dev,
 
        u16 sample_short;
        u32 length;
-       u16 *data_end = 0;
+       u16 __user *data_end = NULL;
        unsigned int i;
        const unsigned int max_blksize = 4096/2;
        unsigned int written;
@@ -1052,7 +1053,7 @@ wavefront_send_sample (snd_wavefront_t *dev,
        if (snd_wavefront_cmd (dev, 
                           header->size ?
                           WFC_DOWNLOAD_SAMPLE : WFC_DOWNLOAD_SAMPLE_HEADER,
-                          0, sample_hdr)) {
+                          NULL, sample_hdr)) {
                snd_printk ("sample %sdownload refused.\n",
                            header->size ? "" : "header ");
                return -(EIO);
@@ -1078,7 +1079,7 @@ wavefront_send_sample (snd_wavefront_t *dev,
                        blocksize = ((length-written+7)&~0x7);
                }
 
-               if (snd_wavefront_cmd (dev, WFC_DOWNLOAD_BLOCK, 0, 0)) {
+               if (snd_wavefront_cmd (dev, WFC_DOWNLOAD_BLOCK, NULL, NULL)) {
                        snd_printk ("download block "
                                    "request refused.\n");
                        return -(EIO);
@@ -1185,7 +1186,7 @@ wavefront_send_alias (snd_wavefront_t *dev, wavefront_patch_info *header)
        munge_int32 (header->hdr.a.FrequencyBias, &alias_hdr[20], 3);
        munge_int32 (*(&header->hdr.a.FrequencyBias+1), &alias_hdr[23], 2);
 
-       if (snd_wavefront_cmd (dev, WFC_DOWNLOAD_SAMPLE_ALIAS, 0, alias_hdr)) {
+       if (snd_wavefront_cmd (dev, WFC_DOWNLOAD_SAMPLE_ALIAS, NULL, alias_hdr)) {
                snd_printk ("download alias failed.\n");
                return -(EIO);
        }
@@ -1313,7 +1314,7 @@ wavefront_send_drum (snd_wavefront_t *dev, wavefront_patch_info *header)
                munge_int32 (((unsigned char *)drum)[i], &drumbuf[1+(i*2)], 2);
        }
 
-       if (snd_wavefront_cmd (dev, WFC_DOWNLOAD_EDRUM_PROGRAM, 0, drumbuf)) {
+       if (snd_wavefront_cmd (dev, WFC_DOWNLOAD_EDRUM_PROGRAM, NULL, drumbuf)) {
                snd_printk ("download drum failed.\n");
                return -(EIO);
        }
@@ -1354,7 +1355,7 @@ wavefront_find_free_patch (snd_wavefront_t *dev)
 #endif
 
 static int
-wavefront_load_patch (snd_wavefront_t *dev, const char *addr)
+wavefront_load_patch (snd_wavefront_t *dev, const char __user *addr)
 
 {
        wavefront_patch_info header;
@@ -1376,8 +1377,7 @@ wavefront_load_patch (snd_wavefront_t *dev, const char *addr)
        switch (header.subkey) {
        case WF_ST_SAMPLE:  /* sample or sample_header, based on patch->size */
 
-               if (copy_from_user ((unsigned char *) &header.hdr.s,
-                                   (unsigned char *) header.hdrptr,
+               if (copy_from_user (&header.hdr.s, header.hdrptr,
                                    sizeof (wavefront_sample)))
                        return -EFAULT;
 
@@ -1385,8 +1385,7 @@ wavefront_load_patch (snd_wavefront_t *dev, const char *addr)
 
        case WF_ST_MULTISAMPLE:
 
-               if (copy_from_user ((unsigned char *) &header.hdr.s,
-                                   (unsigned char *) header.hdrptr,
+               if (copy_from_user (&header.hdr.s, header.hdrptr,
                                    sizeof (wavefront_multisample)))
                        return -EFAULT;
 
@@ -1395,32 +1394,28 @@ wavefront_load_patch (snd_wavefront_t *dev, const char *addr)
 
        case WF_ST_ALIAS:
 
-               if (copy_from_user ((unsigned char *) &header.hdr.a,
-                                   (unsigned char *) header.hdrptr,
+               if (copy_from_user (&header.hdr.a, header.hdrptr,
                                    sizeof (wavefront_alias)))
                        return -EFAULT;
 
                return wavefront_send_alias (dev, &header);
 
        case WF_ST_DRUM:
-               if (copy_from_user ((unsigned char *) &header.hdr.d, 
-                                   (unsigned char *) header.hdrptr,
+               if (copy_from_user (&header.hdr.d, header.hdrptr,
                                    sizeof (wavefront_drum)))
                        return -EFAULT;
 
                return wavefront_send_drum (dev, &header);
 
        case WF_ST_PATCH:
-               if (copy_from_user ((unsigned char *) &header.hdr.p, 
-                                   (unsigned char *) header.hdrptr,
+               if (copy_from_user (&header.hdr.p, header.hdrptr,
                                    sizeof (wavefront_patch)))
                        return -EFAULT;
 
                return wavefront_send_patch (dev, &header);
 
        case WF_ST_PROGRAM:
-               if (copy_from_user ((unsigned char *) &header.hdr.pr, 
-                                   (unsigned char *) header.hdrptr,
+               if (copy_from_user (&header.hdr.pr, header.hdrptr,
                                    sizeof (wavefront_program)))
                        return -EFAULT;
 
@@ -1626,6 +1621,7 @@ snd_wavefront_synth_ioctl (snd_hwdep_t *hw, struct file *file,
        snd_wavefront_t *dev;
        snd_wavefront_card_t *acard;
        wavefront_control wc;
+       void __user *argp = (void __user *)arg;
 
        card = (snd_card_t *) hw->card;
 
@@ -1638,18 +1634,18 @@ snd_wavefront_synth_ioctl (snd_hwdep_t *hw, struct file *file,
        
        switch (cmd) {
        case WFCTL_LOAD_SPP:
-               if (wavefront_load_patch (dev, (char *) arg) != 0) {
+               if (wavefront_load_patch (dev, argp) != 0) {
                        return -EIO;
                }
                break;
 
        case WFCTL_WFCMD:
-               if (copy_from_user (&wc, (void *) arg, sizeof (wc)))
+               if (copy_from_user (&wc, argp, sizeof (wc)))
                        return -EFAULT;
                if (wavefront_synth_control (acard, &wc) < 0) {
                        return -EIO;
                }
-               if (copy_to_user ((void *) arg, &wc, sizeof (wc)))
+               if (copy_to_user (argp, &wc, sizeof (wc)))
                        return -EFAULT;
                break;
 
@@ -1965,6 +1961,12 @@ wavefront_download_firmware (snd_wavefront_t *dev, char *path)
                        break;
                }
 
+               if (section_length < 0 || section_length > WF_SECTION_MAX) {
+                       snd_printk ("invalid firmware section length %d\n",
+                                   section_length);
+                       goto failure;
+               }
+
                if (sys_read (fd, section, section_length) != section_length) {
                        snd_printk ("firmware section "
                                "read error.\n");
@@ -2089,7 +2091,7 @@ wavefront_do_reset (snd_wavefront_t *dev)
 
        voices[0] = 32;
 
-       if (snd_wavefront_cmd (dev, WFC_SET_NVOICES, 0, voices)) {
+       if (snd_wavefront_cmd (dev, WFC_SET_NVOICES, NULL, voices)) {
                snd_printk ("cannot set number of voices to 32.\n");
                goto gone_bad;
        }