This commit was manufactured by cvs2svn to create tag
[linux-2.6.git] / drivers / isdn / pcbit / drv.c
index ed8af7f..c3f43a5 100644 (file)
@@ -57,9 +57,9 @@ static char* pcbit_devname[MAX_PCBIT_CARDS] = {
  */
 
 int pcbit_command(isdn_ctrl* ctl);
-int pcbit_stat(u_char __user * buf, int len, int, int);
+int pcbit_stat(u_char* buf, int len, int user, int, int);
 int pcbit_xmit(int driver, int chan, int ack, struct sk_buff *skb);
-int pcbit_writecmd(const u_char __user *, int, int, int);
+int pcbit_writecmd(const u_char*, int, int, int, int);
 
 static int set_protocol_running(struct pcbit_dev * dev);
 
@@ -389,13 +389,12 @@ int pcbit_xmit(int driver, int chnum, int ack, struct sk_buff *skb)
        return len;
 }
 
-int pcbit_writecmd(const u_char __user *buf, int len, int driver, int channel)
+int pcbit_writecmd(const u_char* buf, int len, int user, int driver, int channel)
 {
        struct pcbit_dev * dev;
        int i, j;
        const u_char * loadbuf;
        u_char * ptr = NULL;
-       u_char *cbuf;
 
        int errstat;
 
@@ -416,28 +415,37 @@ int pcbit_writecmd(const u_char __user *buf, int len, int driver, int channel)
                        return -EINVAL;
                }
 
-               cbuf = kmalloc(len, GFP_KERNEL);
-               if (!cbuf)
-                       return -ENOMEM;
+               if (user)
+               {
+                       u_char *cbuf = kmalloc(len, GFP_KERNEL);
+                       if (!cbuf)
+                               return -ENOMEM;
 
-               if (copy_from_user(cbuf, buf, len)) {
+                       if (copy_from_user(cbuf, buf, len)) {
+                               kfree(cbuf);
+                               return -EFAULT;
+                       }
+                       memcpy_toio(dev->sh_mem, cbuf, len);
                        kfree(cbuf);
-                       return -EFAULT;
                }
-               memcpy_toio(dev->sh_mem, cbuf, len);
-               kfree(cbuf);
+               else
+                       memcpy_toio(dev->sh_mem, buf, len);
                return len;
        case L2_FWMODE:
                /* this is the hard part */
                /* dumb board */
-               /* get it into kernel space */
-               if ((ptr = kmalloc(len, GFP_KERNEL))==NULL)
-                       return -ENOMEM;
-               if (copy_from_user(ptr, buf, len)) {
-                       kfree(ptr);
-                       return -EFAULT;
+               if (user) {             
+                       /* get it into kernel space */
+                       if ((ptr = kmalloc(len, GFP_KERNEL))==NULL)
+                               return -ENOMEM;
+                       if (copy_from_user(ptr, buf, len)) {
+                               kfree(ptr);
+                               return -EFAULT;
+                       }
+                       loadbuf = ptr;
                }
-               loadbuf = ptr;
+               else
+                       loadbuf = buf;
     
                errstat = 0;
 
@@ -460,7 +468,9 @@ int pcbit_writecmd(const u_char __user *buf, int len, int driver, int channel)
                        if (dev->loadptr > LOAD_ZONE_END)
                                dev->loadptr = LOAD_ZONE_START;
                }
-               kfree(ptr);
+
+               if (user)
+                       kfree(ptr);
 
                return errstat ? errstat : len;
        default:
@@ -713,7 +723,17 @@ static char statbuf[STATBUF_LEN];
 static int stat_st = 0;
 static int stat_end = 0;
 
-int pcbit_stat(u_char __user *buf, int len, int driver, int channel)
+
+static __inline void
+memcpy_to_COND(int flag, char *d, const char *s, int len) {
+       if (flag)
+               copy_to_user(d, s, len);
+       else
+               memcpy(d, s, len);
+}
+
+
+int pcbit_stat(u_char* buf, int len, int user, int driver, int channel)
 {
        int stat_count;
        stat_count = stat_end - stat_st;
@@ -727,23 +747,24 @@ int pcbit_stat(u_char __user *buf, int len, int driver, int channel)
 
        if (stat_st < stat_end)
        {
-               copy_to_user(buf, statbuf + stat_st, len);
+               memcpy_to_COND(user, buf, statbuf + stat_st, len);
                stat_st += len;    
        }
        else
        {
                if (len > STATBUF_LEN - stat_st)
                {
-                       copy_to_user(buf, statbuf + stat_st, 
+                       memcpy_to_COND(user, buf, statbuf + stat_st, 
                                       STATBUF_LEN - stat_st);
-                       copy_to_user(buf, statbuf, 
+                       memcpy_to_COND(user, buf, statbuf, 
                                       len - (STATBUF_LEN - stat_st));
 
                        stat_st = len - (STATBUF_LEN - stat_st);
                }
                else
                {
-                       copy_to_user(buf, statbuf + stat_st, len);
+                       memcpy_to_COND(user, buf, statbuf + stat_st, 
+                                      len);
 
                        stat_st += len;