]> pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - drivers/usb/misc/usbtest.c
USB: use DIV_ROUND_UP
[linux-2.6-omap-h63xx.git] / drivers / usb / misc / usbtest.c
index e901d31e051b3d579e3dcebdf1e66f161e2a31ba..17100471e461fcf1637a6eaeda531f19eb011974 100644 (file)
@@ -6,6 +6,7 @@
 #include <linux/module.h>
 #include <linux/moduleparam.h>
 #include <linux/scatterlist.h>
+#include <linux/mutex.h>
 
 #include <linux/usb.h>
 
@@ -64,7 +65,7 @@ struct usbtest_dev {
        int                     in_iso_pipe;
        int                     out_iso_pipe;
        struct usb_endpoint_descriptor  *iso_in, *iso_out;
-       struct semaphore        sem;
+       struct mutex            lock;
 
 #define TBUF_SIZE      256
        u8                      *buf;
@@ -360,9 +361,9 @@ static void free_sglist (struct scatterlist *sg, int nents)
        if (!sg)
                return;
        for (i = 0; i < nents; i++) {
-               if (!sg [i].page)
+               if (!sg_page(&sg[i]))
                        continue;
-               kfree (page_address (sg [i].page) + sg [i].offset);
+               kfree (sg_virt(&sg[i]));
        }
        kfree (sg);
 }
@@ -377,6 +378,7 @@ alloc_sglist (int nents, int max, int vary)
        sg = kmalloc (nents * sizeof *sg, GFP_KERNEL);
        if (!sg)
                return NULL;
+       sg_init_table(sg, nents);
 
        for (i = 0; i < nents; i++) {
                char            *buf;
@@ -389,7 +391,7 @@ alloc_sglist (int nents, int max, int vary)
                }
 
                /* kmalloc pages are always physically contiguous! */
-               sg_init_one(&sg[i], buf, size);
+               sg_set_buf(&sg[i], buf, size);
 
                switch (pattern) {
                case 0:
@@ -1151,6 +1153,7 @@ static int verify_halted (int ep, struct urb *urb)
                dbg ("ep %02x couldn't get halt status, %d", ep, retval);
                return retval;
        }
+       le16_to_cpus(&status);
        if (status != 1) {
                dbg ("ep %02x bogus status: %04x != 1", ep, status);
                return -EINVAL;
@@ -1310,7 +1313,7 @@ static int ctrl_out (struct usbtest_dev *dev,
                len += vary;
 
                /* [real world] the "zero bytes IN" case isn't really used.
-                * hardware can easily trip up in this wierd case, since its
+                * hardware can easily trip up in this weird case, since its
                 * status stage is IN, not OUT like other ep0in transfers.
                 */
                if (len > length)
@@ -1401,7 +1404,7 @@ static struct urb *iso_alloc_urb (
                return NULL;
        maxp = 0x7ff & le16_to_cpu(desc->wMaxPacketSize);
        maxp *= 1 + (0x3 & (le16_to_cpu(desc->wMaxPacketSize) >> 11));
-       packets = (bytes + maxp - 1) / maxp;
+       packets = DIV_ROUND_UP(bytes, maxp);
 
        urb = usb_alloc_urb (packets, GFP_KERNEL);
        if (!urb)
@@ -1558,11 +1561,11 @@ usbtest_ioctl (struct usb_interface *intf, unsigned int code, void *buf)
                        || param->sglen < 0 || param->vary < 0)
                return -EINVAL;
 
-       if (down_interruptible (&dev->sem))
+       if (mutex_lock_interruptible(&dev->lock))
                return -ERESTARTSYS;
 
        if (intf->dev.power.power_state.event != PM_EVENT_ON) {
-               up (&dev->sem);
+               mutex_unlock(&dev->lock);
                return -EHOSTUNREACH;
        }
 
@@ -1574,7 +1577,7 @@ usbtest_ioctl (struct usb_interface *intf, unsigned int code, void *buf)
                int     res;
 
                if (intf->altsetting->desc.bInterfaceNumber) {
-                       up (&dev->sem);
+                       mutex_unlock(&dev->lock);
                        return -ENODEV;
                }
                res = set_altsetting (dev, dev->info->alt);
@@ -1582,7 +1585,7 @@ usbtest_ioctl (struct usb_interface *intf, unsigned int code, void *buf)
                        dev_err (&intf->dev,
                                        "set altsetting to %d failed, %d\n",
                                        dev->info->alt, res);
-                       up (&dev->sem);
+                       mutex_unlock(&dev->lock);
                        return res;
                }
        }
@@ -1855,7 +1858,7 @@ usbtest_ioctl (struct usb_interface *intf, unsigned int code, void *buf)
                param->duration.tv_usec += 1000 * 1000;
                param->duration.tv_sec -= 1;
        }
-       up (&dev->sem);
+       mutex_unlock(&dev->lock);
        return retval;
 }
 
@@ -1905,7 +1908,7 @@ usbtest_probe (struct usb_interface *intf, const struct usb_device_id *id)
                return -ENOMEM;
        info = (struct usbtest_info *) id->driver_info;
        dev->info = info;
-       init_MUTEX (&dev->sem);
+       mutex_init(&dev->lock);
 
        dev->intf = intf;
 
@@ -1990,8 +1993,6 @@ static void usbtest_disconnect (struct usb_interface *intf)
 {
        struct usbtest_dev      *dev = usb_get_intfdata (intf);
 
-       down (&dev->sem);
-
        usb_set_intfdata (intf, NULL);
        dev_dbg (&intf->dev, "disconnect\n");
        kfree (dev);