--- local_tree.orig/drivers/usb/core/devio.c    2004-07-26 00:39:13.980826658 +0200
+++ local_tree/drivers/usb/core/devio.c 2004-07-26 00:55:05.361216844 +0200
@@ -1184,11 +1184,12 @@
 static int proc_ioctl (struct dev_state *ps, void __user *arg)
 {
        struct usbdevfs_ioctl   ctrl;
-       int                     size;
        void                    *buf = NULL;
-       int                     retval = 0;
-       struct usb_interface    *intf = NULL;
-       struct usb_driver       *driver = NULL;
+       struct usb_device       *dev = ps->dev;
+       struct usb_driver       *driver = NULL;
+       struct usb_interface    *intf = NULL;
+       int                     ret = 0;
+       int                     size;
 
        /* get input parameters and alloc buffer */
        if (copy_from_user(&ctrl, arg, sizeof (ctrl)))
@@ -1206,17 +1207,23 @@
                }
        }
 
-       if (!connected(ps->dev)) {
-               if (buf)
-                       kfree(buf);
-               return -ENODEV;
+       down(&dev->serialize);
+       if (!connected(dev)) {
+               ret = -ENODEV;
+               goto out;
        }
 
-       if (ps->dev->state != USB_STATE_CONFIGURED)
-               retval = -ENODEV;
-       else if (!(intf = usb_ifnum_to_if (ps->dev, ctrl.ifno)))
-               retval = -EINVAL;
-       else switch (ctrl.ioctl_code) {
+       if (dev->state != USB_STATE_CONFIGURED) {
+               ret = -ENODEV;
+               goto out;
+       }
+
+       if (!(intf = usb_ifnum_to_if (dev, ctrl.ifno))) {
+               ret = -EINVAL;
+               goto out;
+       }
+
+       switch (ctrl.ioctl_code) {
 
        /* disconnect kernel driver from interface */
        case USBDEVFS_DISCONNECT:
@@ -1226,7 +1233,7 @@
                        dev_dbg (&intf->dev, "disconnect by usbfs\n");
                        usb_driver_release_interface(driver, intf);
                } else
-                       retval = -ENODATA;
+                       ret = -ENODATA;
                up_write(&usb_bus_type.subsys.rwsem);
                break;
 
@@ -1241,24 +1248,26 @@
                if (intf->dev.driver)
                        driver = to_usb_driver(intf->dev.driver);
                if (driver == 0 || driver->ioctl == 0) {
-                       retval = -ENOTTY;
+                       ret = -ENOTTY;
                } else {
-                       retval = driver->ioctl (intf, ctrl.ioctl_code, buf);
-                       if (retval == -ENOIOCTLCMD)
-                               retval = -ENOTTY;
+                       ret = driver->ioctl (intf, ctrl.ioctl_code, buf);
+                       if (ret == -ENOIOCTLCMD)
+                               ret = -ENOTTY;
                }
                up_read(&usb_bus_type.subsys.rwsem);
        }
 
        /* cleanup and return */
-       if (retval >= 0
-                       && (_IOC_DIR (ctrl.ioctl_code) & _IOC_READ) != 0
-                       && size > 0
-                       && copy_to_user (ctrl.data, buf, size) != 0)
-               retval = -EFAULT;
-       if (buf != 0)
-               kfree (buf);
-       return retval;
+       if (ret < 0 || !(_IOC_DIR (ctrl.ioctl_code) & _IOC_READ) || size <= 0)
+               goto out;
+
+       kfree (buf);
+       up(&dev->serialize);
+       return copy_to_user (ctrl.data, buf, size) ? -EFAULT : 0;
+out:
+       kfree (buf);
+       up(&dev->serialize);
+       return ret;
 }
 
 /*
@@ -1386,14 +1395,8 @@
                break;
 
        case USBDEVFS_IOCTL:
-               down(&dev->serialize);
-               if (!connected(dev)) {
-                       up(&dev->serialize);
-                       return -ENODEV;
-               }
                snoop(&dev->dev, "%s: IOCTL\n", __FUNCTION__);
                ret = proc_ioctl(ps, p);
-               up(&dev->serialize);
                break;
        }
        if (ret >= 0)


-------------------------------------------------------
This SF.Net email is sponsored by OSTG. Have you noticed the changes on
Linux.com, ITManagersJournal and NewsForge in the past few weeks? Now,
one more big change to announce. We are now OSTG- Open Source Technology
Group. Come see the changes on the new OSTG site. www.ostg.com
_______________________________________________
[EMAIL PROTECTED]
To unsubscribe, use the last form field at:
https://lists.sourceforge.net/lists/listinfo/linux-usb-devel

Reply via email to