]> git.hungrycats.org Git - linux/commitdiff
[PATCH] sparse: ISDN ->readstat() and ->writecmd() annotation
authorAlexander Viro <viro@www.linux.org.uk>
Mon, 12 Jul 2004 02:08:51 +0000 (19:08 -0700)
committerLinus Torvalds <torvalds@ppc970.osdl.org>
Mon, 12 Jul 2004 02:08:51 +0000 (19:08 -0700)
->readstat() and ->writecmd() are always getting a userland pointer;
marked argument as such, killed "user" flag, killed dead code.

drivers/isdn/act2000/module.c
drivers/isdn/capi/capidrv.c
drivers/isdn/hisax/config.c
drivers/isdn/i4l/isdn_common.c
drivers/isdn/icn/icn.c
drivers/isdn/isdnloop/isdnloop.c
drivers/isdn/pcbit/drv.c
include/linux/isdnif.h

index 6129c8e509d9be7f7ce8a23d672b6b433404bf83..7e20c17aa7c47ad5156578fce3f1fbc96aeb1109 100644 (file)
@@ -463,18 +463,15 @@ act2000_sendbuf(act2000_card *card, int channel, int ack, struct sk_buff *skb)
 
 /* Read the Status-replies from the Interface */
 static int
-act2000_readstatus(u_char * buf, int len, int user, act2000_card * card)
+act2000_readstatus(u_char __user * buf, int len, act2000_card * card)
 {
         int count;
-        u_char *p;
+        u_char __user *p;
 
         for (p = buf, count = 0; count < len; p++, count++) {
                 if (card->status_buf_read == card->status_buf_write)
                         return count;
-                if (user)
-                        put_user(*card->status_buf_read++, p);
-                else
-                        *p = *card->status_buf_read++;
+               put_user(*card->status_buf_read++, p);
                 if (card->status_buf_read > card->status_buf_end)
                         card->status_buf_read = card->status_buf;
         }
@@ -514,7 +511,7 @@ if_command(isdn_ctrl * c)
 }
 
 static int
-if_writecmd(const u_char * buf, int len, int user, int id, int channel)
+if_writecmd(const u_char __user *buf, int len, int id, int channel)
 {
         act2000_card *card = act2000_findcard(id);
 
@@ -529,14 +526,14 @@ if_writecmd(const u_char * buf, int len, int user, int id, int channel)
 }
 
 static int
-if_readstatus(u_char * buf, int len, int user, int id, int channel)
+if_readstatus(u_char __user * buf, int len, int id, int channel)
 {
         act2000_card *card = act2000_findcard(id);
        
         if (card) {
                 if (!card->flags & ACT2000_FLAGS_RUNNING)
                         return -ENODEV;
-                return (act2000_readstatus(buf, len, user, card));
+                return (act2000_readstatus(buf, len, card));
         }
         printk(KERN_ERR
                "act2000: if_readstatus called with invalid driverId!\n");
index b0a223ddb581341a94fda0d2b9e17c4bedf77ae4..710665aff5beb86a182baf41621c680a8d9a6ed7 100644 (file)
@@ -1892,11 +1892,11 @@ static int if_sendbuf(int id, int channel, int doack, struct sk_buff *skb)
        }
 }
 
-static int if_readstat(u8 *buf, int len, int user, int id, int channel)
+static int if_readstat(u8 __user *buf, int len, int id, int channel)
 {
        capidrv_contr *card = findcontrbydriverid(id);
        int count;
-       u8 *p;
+       u8 __user *p;
 
        if (!card) {
                printk(KERN_ERR "capidrv: if_readstat called with invalid driverId %d!\n",
@@ -1905,10 +1905,7 @@ static int if_readstat(u8 *buf, int len, int user, int id, int channel)
        }
 
        for (p=buf, count=0; count < len; p++, count++) {
-               if (user)
-                       put_user(*card->q931_read++, p);
-               else
-                       *p = *card->q931_read++;
+               put_user(*card->q931_read++, p);
                if (card->q931_read > card->q931_end)
                        card->q931_read = card->q931_buf;
        }
index ace5093d042d43160f32f7798a3318a3a52dab9a..7a2d65a911e77f94e589f061ccc2ad69019717f0 100644 (file)
@@ -618,10 +618,10 @@ struct IsdnCardState *hisax_get_card(int cardnr)
        return NULL;
 }
 
-int HiSax_readstatus(u_char * buf, int len, int user, int id, int channel)
+int HiSax_readstatus(u_char __user *buf, int len, int id, int channel)
 {
        int count, cnt;
-       u_char *p = buf;
+       u_char __user *p = buf;
        struct IsdnCardState *cs = hisax_findcard(id);
 
        if (cs) {
@@ -633,10 +633,7 @@ int HiSax_readstatus(u_char * buf, int len, int user, int id, int channel)
                count = cs->status_end - cs->status_read + 1;
                if (count >= len)
                        count = len;
-               if (user)
-                       copy_to_user(p, cs->status_read, count);
-               else
-                       memcpy(p, cs->status_read, count);
+               copy_to_user(p, cs->status_read, count);
                cs->status_read += count;
                if (cs->status_read > cs->status_end)
                        cs->status_read = cs->status_buf;
@@ -647,10 +644,7 @@ int HiSax_readstatus(u_char * buf, int len, int user, int id, int channel)
                                cnt = HISAX_STATUS_BUFSIZE;
                        else
                                cnt = count;
-                       if (user)
-                               copy_to_user(p, cs->status_read, cnt);
-                       else
-                               memcpy(p, cs->status_read, cnt);
+                       copy_to_user(p, cs->status_read, cnt);
                        p += cnt;
                        cs->status_read += cnt % HISAX_STATUS_BUFSIZE;
                        count -= cnt;
index 2e21ba46a7b885956c57f976ea1c0944cbb19e91..eb71c80924a058fc86333b00b47e2b8f3945bac5 100644 (file)
@@ -1018,7 +1018,7 @@ isdn_read(struct file *file, char __user *buf, size_t count, loff_t * off)
                        if (count > dev->drv[drvidx]->stavail)
                                count = dev->drv[drvidx]->stavail;
                        len = dev->drv[drvidx]->interface->
-                               readstat(buf, count, 1, drvidx,
+                               readstat(buf, count, drvidx,
                                         isdn_minor2chan(minor));
                } else {
                        len = 0;
@@ -1091,7 +1091,7 @@ isdn_write(struct file *file, const char __user *buf, size_t count, loff_t * off
                 */
                if (dev->drv[drvidx]->interface->writecmd)
                        retval = dev->drv[drvidx]->interface->
-                               writecmd(buf, count, 1, drvidx, isdn_minor2chan(minor));
+                               writecmd(buf, count, drvidx, isdn_minor2chan(minor));
                else
                        retval = count;
                goto out;
index 391a8f139c082c4a17747c1266c1e1d864a7bcd5..2a924fe1069b25ba9ecc39728b2aed6f8277f248 100644 (file)
@@ -1007,18 +1007,15 @@ icn_loadproto(u_char * buffer, icn_card * card)
 
 /* Read the Status-replies from the Interface */
 static int
-icn_readstatus(u_char * buf, int len, int user, icn_card * card)
+icn_readstatus(u_char __user *buf, int len, icn_card * card)
 {
        int count;
-       u_char *p;
+       u_char __user *p;
 
        for (p = buf, count = 0; count < len; p++, count++) {
                if (card->msg_buf_read == card->msg_buf_write)
                        return count;
-               if (user)
-                       put_user(*card->msg_buf_read++, p);
-               else
-                       *p = *card->msg_buf_read++;
+               put_user(*card->msg_buf_read++, p);
                if (card->msg_buf_read > card->msg_buf_end)
                        card->msg_buf_read = card->msg_buf;
        }
@@ -1470,14 +1467,14 @@ if_command(isdn_ctrl * c)
 }
 
 static int
-if_writecmd(const u_char * buf, int len, int user, int id, int channel)
+if_writecmd(const u_char __user *buf, int len, int id, int channel)
 {
        icn_card *card = icn_findcard(id);
 
        if (card) {
                if (!card->flags & ICN_FLAGS_RUNNING)
                        return -ENODEV;
-               return (icn_writecmd(buf, len, user, card));
+               return (icn_writecmd(buf, len, 1, card));
        }
        printk(KERN_ERR
               "icn: if_writecmd called with invalid driverId!\n");
@@ -1485,14 +1482,14 @@ if_writecmd(const u_char * buf, int len, int user, int id, int channel)
 }
 
 static int
-if_readstatus(u_char * buf, int len, int user, int id, int channel)
+if_readstatus(u_char __user *buf, int len, int id, int channel)
 {
        icn_card *card = icn_findcard(id);
 
        if (card) {
                if (!card->flags & ICN_FLAGS_RUNNING)
                        return -ENODEV;
-               return (icn_readstatus(buf, len, user, card));
+               return (icn_readstatus(buf, len, card));
        }
        printk(KERN_ERR
               "icn: if_readstatus called with invalid driverId!\n");
index fde3db9abb6088415540aa28118f50935058228f..544f41b413ed98683b8f0938ad509b0555d10010 100644 (file)
@@ -443,18 +443,15 @@ isdnloop_sendbuf(int channel, struct sk_buff *skb, isdnloop_card * card)
  *   number of bytes actually transferred.
  */
 static int
-isdnloop_readstatus(u_char * buf, int len, int user, isdnloop_card * card)
+isdnloop_readstatus(u_char __user *buf, int len, isdnloop_card * card)
 {
        int count;
-       u_char *p;
+       u_char __user *p;
 
        for (p = buf, count = 0; count < len; p++, count++) {
                if (card->msg_buf_read == card->msg_buf_write)
                        return count;
-               if (user)
-                       put_user(*card->msg_buf_read++, p);
-               else
-                       *p = *card->msg_buf_read++;
+               put_user(*card->msg_buf_read++, p);
                if (card->msg_buf_read > card->msg_buf_end)
                        card->msg_buf_read = card->msg_buf;
        }
@@ -1388,14 +1385,14 @@ if_command(isdn_ctrl * c)
 }
 
 static int
-if_writecmd(const u_char * buf, int len, int user, int id, int channel)
+if_writecmd(const u_char __user *buf, int len, int id, int channel)
 {
        isdnloop_card *card = isdnloop_findcard(id);
 
        if (card) {
                if (!card->flags & ISDNLOOP_FLAGS_RUNNING)
                        return -ENODEV;
-               return (isdnloop_writecmd(buf, len, user, card));
+               return (isdnloop_writecmd(buf, len, 1, card));
        }
        printk(KERN_ERR
               "isdnloop: if_writecmd called with invalid driverId!\n");
@@ -1403,14 +1400,14 @@ if_writecmd(const u_char * buf, int len, int user, int id, int channel)
 }
 
 static int
-if_readstatus(u_char * buf, int len, int user, int id, int channel)
+if_readstatus(u_char __user *buf, int len, int id, int channel)
 {
        isdnloop_card *card = isdnloop_findcard(id);
 
        if (card) {
                if (!card->flags & ISDNLOOP_FLAGS_RUNNING)
                        return -ENODEV;
-               return (isdnloop_readstatus(buf, len, user, card));
+               return (isdnloop_readstatus(buf, len, card));
        }
        printk(KERN_ERR
               "isdnloop: if_readstatus called with invalid driverId!\n");
index c3f43a56b6f70abf93372cd44d6016fc8e7cfa25..ed8af7ff0a4f43bf10f0d7d19fe658b6e42c2eea 100644 (file)
@@ -57,9 +57,9 @@ static char* pcbit_devname[MAX_PCBIT_CARDS] = {
  */
 
 int pcbit_command(isdn_ctrl* ctl);
-int pcbit_stat(u_char* buf, int len, int user, int, int);
+int pcbit_stat(u_char __user * buf, int len, int, int);
 int pcbit_xmit(int driver, int chan, int ack, struct sk_buff *skb);
-int pcbit_writecmd(const u_char*, int, int, int, int);
+int pcbit_writecmd(const u_char __user *, int, int, int);
 
 static int set_protocol_running(struct pcbit_dev * dev);
 
@@ -389,12 +389,13 @@ int pcbit_xmit(int driver, int chnum, int ack, struct sk_buff *skb)
        return len;
 }
 
-int pcbit_writecmd(const u_char* buf, int len, int user, int driver, int channel)
+int pcbit_writecmd(const u_char __user *buf, int len, int driver, int channel)
 {
        struct pcbit_dev * dev;
        int i, j;
        const u_char * loadbuf;
        u_char * ptr = NULL;
+       u_char *cbuf;
 
        int errstat;
 
@@ -415,37 +416,28 @@ int pcbit_writecmd(const u_char* buf, int len, int user, int driver, int channel
                        return -EINVAL;
                }
 
-               if (user)
-               {
-                       u_char *cbuf = kmalloc(len, GFP_KERNEL);
-                       if (!cbuf)
-                               return -ENOMEM;
+               cbuf = kmalloc(len, GFP_KERNEL);
+               if (!cbuf)
+                       return -ENOMEM;
 
-                       if (copy_from_user(cbuf, buf, len)) {
-                               kfree(cbuf);
-                               return -EFAULT;
-                       }
-                       memcpy_toio(dev->sh_mem, cbuf, len);
+               if (copy_from_user(cbuf, buf, len)) {
                        kfree(cbuf);
+                       return -EFAULT;
                }
-               else
-                       memcpy_toio(dev->sh_mem, buf, len);
+               memcpy_toio(dev->sh_mem, cbuf, len);
+               kfree(cbuf);
                return len;
        case L2_FWMODE:
                /* this is the hard part */
                /* dumb board */
-               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;
+               /* 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;
                }
-               else
-                       loadbuf = buf;
+               loadbuf = ptr;
     
                errstat = 0;
 
@@ -468,9 +460,7 @@ int pcbit_writecmd(const u_char* buf, int len, int user, int driver, int channel
                        if (dev->loadptr > LOAD_ZONE_END)
                                dev->loadptr = LOAD_ZONE_START;
                }
-
-               if (user)
-                       kfree(ptr);
+               kfree(ptr);
 
                return errstat ? errstat : len;
        default:
@@ -723,17 +713,7 @@ static char statbuf[STATBUF_LEN];
 static int stat_st = 0;
 static int stat_end = 0;
 
-
-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 pcbit_stat(u_char __user *buf, int len, int driver, int channel)
 {
        int stat_count;
        stat_count = stat_end - stat_st;
@@ -747,24 +727,23 @@ int pcbit_stat(u_char* buf, int len, int user, int driver, int channel)
 
        if (stat_st < stat_end)
        {
-               memcpy_to_COND(user, buf, statbuf + stat_st, len);
+               copy_to_user(buf, statbuf + stat_st, len);
                stat_st += len;    
        }
        else
        {
                if (len > STATBUF_LEN - stat_st)
                {
-                       memcpy_to_COND(user, buf, statbuf + stat_st, 
+                       copy_to_user(buf, statbuf + stat_st, 
                                       STATBUF_LEN - stat_st);
-                       memcpy_to_COND(user, buf, statbuf, 
+                       copy_to_user(buf, statbuf, 
                                       len - (STATBUF_LEN - stat_st));
 
                        stat_st = len - (STATBUF_LEN - stat_st);
                }
                else
                {
-                       memcpy_to_COND(user, buf, statbuf + stat_st, 
-                                      len);
+                       copy_to_user(buf, statbuf + stat_st, len);
 
                        stat_st += len;
                        
index 823e516b14a206e40df711924af4d5b9e6c2cadc..7a4eacd77cb2eee1710467636d87b8b1a8b410b0 100644 (file)
@@ -502,26 +502,18 @@ typedef struct {
    * Parameters:
    *             u_char pointer data
    *             int    length of data
-   *             int    Flag: 0 = Call form Kernel-Space (use memcpy,
-   *                              no schedule allowed) 
-   *                          1 = Data is in User-Space (use memcpy_fromfs,
-   *                              may schedule)
    *             int    driverId
    *             int    local channel-number (0 ...)
    */
-  int (*writecmd)(const u_char*, int, int, int, int);
+  int (*writecmd)(const u_char __user *, int, int, int);
 
   /* Read raw Status replies
    *             u_char pointer data (volatile)
    *             int    length of buffer
-   *             int    Flag: 0 = Call form Kernel-Space (use memcpy,
-   *                              no schedule allowed) 
-   *                          1 = Data is in User-Space (use memcpy_fromfs,
-   *                              may schedule)
    *             int    driverId
    *             int    local channel-number (0 ...)
    */
-  int (*readstat)(u_char*, int, int, int, int);
+  int (*readstat)(u_char __user *, int, int, int);
 
   char id[20];
 } isdn_if;