Hi,

On Tue, Dec 24, 2002 at 09:26:12PM +0100, Oliver Neukum wrote:
> > It's against which tree? I can't apply the patch to 2.4 because of
> > lines like that one:
> 
> 2.4.18 SuSE-tree. I have no vanilla tree on this laptop, sorry. I am
> travelling.

Ah, ok. I'll attach a re-diffed patch against the already applied 2.4
stuff.

> I forgot to enable these options. Here's a new version with those debug
> statements killed. Do you think that the conditional compile for that
> scanner should be kept conditional?

I wouldn't enable it by default, these are not officialy ioctls
anyway. In fact I think the PV8630 stuff can be removed. At least
it's not used by any backend that's currently in the SANE
distribution. Anything that doesn't use SCANNER_IOCTL_CTRLMSG
nowerdays is almost certainly bit-rotten anyway.

On the other hand, it doesn't really hurt.

Bye,
  Henning


--- linux-2.4.21-pre1.altsetting/drivers/usb/scanner.c  2002-12-22 12:06:52.000000000 
+0100
+++ linux-2.4.21-pre1.ioctl/drivers/usb/scanner.c       2002-12-24 22:08:07.000000000 
++0100
@@ -327,6 +327,8 @@
  *    - Accept devices with more than one interface. Only use interfaces that
  *      look like belonging to scanners.
  *    - Use altsetting[0], not altsetting[ifnum].
+ *    - Add locking to ioctl_scanner(). Thanks to Oliver Neukum
+ *      <[EMAIL PROTECTED]>.
  *
  * TODO
  *    - Remove the 2/3 endpoint limitation
@@ -420,7 +422,7 @@
 
        dev = scn->scn_dev;
 
-       down(&(scn->sem));      /* Now protect the scn_usb_data structure */ 
+       down(&(scn->sem));      /* Now protect the scn_usb_data structure */
 
        up(&scn_mutex); /* Now handled by the above */
 
@@ -659,7 +661,7 @@
                                goto data_recvd;
                        }
                }
-               
+
                if (result == -EPIPE) { /* No hope */
                        if(usb_clear_halt(dev, scn->bulk_in_ep)) {
                                err("read_scanner(%d): Failure to clear endpoint halt 
condition (%Zd).", scn_minor, ret);
@@ -707,30 +709,26 @@
 ioctl_scanner(struct inode *inode, struct file *file,
              unsigned int cmd, unsigned long arg)
 {
+       struct scn_usb_data *scn;
        struct usb_device *dev;
+       int retval = -ENOTTY;
 
-       kdev_t scn_minor;
-
-       scn_minor = USB_SCN_MINOR(inode);
-
-       if (!p_scn_table[scn_minor]) {
-               err("ioctl_scanner(%d): invalid scn_minor", scn_minor);
-               return -ENODEV;
-       }
+       scn = file->private_data;
+       down(&(scn->sem));
 
-       dev = p_scn_table[scn_minor]->scn_dev;
+       dev = scn->scn_dev;
 
        switch (cmd)
        {
        case SCANNER_IOCTL_VENDOR :
-               return (put_user(dev->descriptor.idVendor, (unsigned int *) arg));
+               retval = (put_user(dev->descriptor.idVendor, (unsigned int *) arg));
+               break;
        case SCANNER_IOCTL_PRODUCT :
-               return (put_user(dev->descriptor.idProduct, (unsigned int *) arg));
+               retval = (put_user(dev->descriptor.idProduct, (unsigned int *) arg));
+               break;
 #ifdef PV8630
        case PV8630_IOCTL_INREQUEST :
        {
-               int result;
-
                struct {
                        __u8  data;
                        __u8  request;
@@ -738,48 +736,42 @@
                        __u16 index;
                } args;
 
-               if (copy_from_user(&args, (void *)arg, sizeof(args)))
-                       return -EFAULT;
+               if (copy_from_user(&args, (void *)arg, sizeof(args))) {
+                       retval = -EFAULT;
+                       break;
+               }
 
-               result = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0),
+               retval = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0),
                                         args.request, USB_TYPE_VENDOR|
                                         USB_RECIP_DEVICE|USB_DIR_IN,
                                         args.value, args.index, &args.data,
                                         1, HZ*5);
 
-               dbg("ioctl_scanner(%d): inreq: args.data:%x args.value:%x 
args.index:%x args.request:%x\n", scn_minor, args.data, args.value, args.index, 
args.request);
-
                if (copy_to_user((void *)arg, &args, sizeof(args)))
-                       return -EFAULT;
-
-               dbg("ioctl_scanner(%d): inreq: result:%d\n", scn_minor, result);
+                       retval = -EFAULT;
 
-               return result;
+               break;
        }
        case PV8630_IOCTL_OUTREQUEST :
        {
-               int result;
-
                struct {
                        __u8  request;
                        __u16 value;
                        __u16 index;
                } args;
 
-               if (copy_from_user(&args, (void *)arg, sizeof(args)))
-                       return -EFAULT;
-
-               dbg("ioctl_scanner(%d): outreq: args.value:%x args.index:%x 
args.request:%x\n", scn_minor, args.value, args.index, args.request);
+               if (copy_from_user(&args, (void *)arg, sizeof(args))) {
+                       retval = -EFAULT;
+                       break;
+               }
 
-               result = usb_control_msg(dev, usb_sndctrlpipe(dev, 0),
+               retval = usb_control_msg(dev, usb_sndctrlpipe(dev, 0),
                                         args.request, USB_TYPE_VENDOR|
                                         USB_RECIP_DEVICE|USB_DIR_OUT,
                                         args.value, args.index, NULL,
                                         0, HZ*5);
 
-               dbg("ioctl_scanner(%d): outreq: result:%d\n", scn_minor, result);
-
-               return result;
+               break;
        }
 #endif /* PV8630 */
        case SCANNER_IOCTL_CTRLMSG:
@@ -790,19 +782,26 @@
                } cmsg;
                int pipe, nb, ret;
                unsigned char buf[64];
- 
-               if (copy_from_user(&cmsg, (void *)arg, sizeof(cmsg)))
-                       return -EFAULT;
+               retval = 0;
+
+               if (copy_from_user(&cmsg, (void *)arg, sizeof(cmsg))) {
+                       retval = -EFAULT;
+                       break;
+               }
 
                nb = cmsg.req.wLength;
 
-               if (nb > sizeof(buf))
-                       return -EINVAL;
+               if (nb > sizeof(buf)) {
+                       retval = -EINVAL;
+                       break;
+               }
 
                if ((cmsg.req.bRequestType & 0x80) == 0) {
                        pipe = usb_sndctrlpipe(dev, 0);
-                       if (nb > 0 && copy_from_user(buf, cmsg.data, nb))
-                               return -EFAULT;
+                       if (nb > 0 && copy_from_user(buf, cmsg.data, nb)) {
+                               retval = -EFAULT;
+                               break;
+                       }
                } else {
                        pipe = usb_rcvctrlpipe(dev, 0);
                }
@@ -814,19 +813,21 @@
                                      buf, nb, HZ);
 
                if (ret < 0) {
-                       err("ioctl_scanner(%d): control_msg returned %d\n", scn_minor, 
ret);
-                       return -EIO;
+                       err("ioctl_scanner: control_msg returned %d\n", ret);
+                       retval = -EIO;
+                       break;
                }
 
                if (nb > 0 && (cmsg.req.bRequestType & 0x80) && 
copy_to_user(cmsg.data, buf, nb))
-                       return -EFAULT;
+                       retval = -EFAULT;
 
-               return 0;
+               break;
        }
        default:
-               return -ENOTTY;
+               break;
        }
-       return 0;
+       up(&(scn->sem));
+       return retval;
 }
 
 static struct


-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf
_______________________________________________
[EMAIL PROTECTED]
To unsubscribe, use the last form field at:
https://lists.sourceforge.net/lists/listinfo/linux-usb-devel

Reply via email to