ChangeSet 1.1525.6.6, 2003/07/01 13:45:23-07:00, lkml001@vrfy.org [PATCH] USB: usb-skeleton.c usb_buffer_free() not called dev->udev was set to NULL to indicate a device disconnect but we need this value for usb_buffer_free() when device is still opened and cleanup is delayed until skel_release(). I've added a dev->present for preventing device read, write and ioctl. Also URB_NO_DMA_MAP is changed to URB_NO_TRANSFER_DMA_MAP and a unused var is removed. drivers/usb/usb-skeleton.c | 22 +++++++++++++--------- 1 files changed, 13 insertions(+), 9 deletions(-) diff -Nru a/drivers/usb/usb-skeleton.c b/drivers/usb/usb-skeleton.c --- a/drivers/usb/usb-skeleton.c Tue Jul 1 14:22:21 2003 +++ b/drivers/usb/usb-skeleton.c Tue Jul 1 14:22:21 2003 @@ -112,6 +112,7 @@ struct completion write_finished; /* wait for the write to finish */ int open; /* if the port is open or not */ + int present; /* if the device is not disconnected */ struct semaphore sem; /* locks this structure */ }; @@ -296,7 +297,7 @@ dev->open = 0; - if (dev->udev == NULL) { + if (!dev->present) { /* the device was unplugged before the file was released */ up (&dev->sem); skel_delete (dev); @@ -326,7 +327,7 @@ down (&dev->sem); /* verify that the device wasn't unplugged */ - if (dev->udev == NULL) { + if (!dev->present) { up (&dev->sem); return -ENODEV; } @@ -382,7 +383,7 @@ down (&dev->sem); /* verify that the device wasn't unplugged */ - if (dev->udev == NULL) { + if (!dev->present) { retval = -ENODEV; goto exit; } @@ -452,7 +453,7 @@ down (&dev->sem); /* verify that the device wasn't unplugged */ - if (dev->udev == NULL) { + if (!dev->present) { up (&dev->sem); return -ENODEV; } @@ -507,8 +508,6 @@ size_t buffer_size; int i; int retval; - char name[14]; - /* See if the device offered us matches what we can accept */ if ((udev->descriptor.idVendor != USB_SKEL_VENDOR_ID) || @@ -580,7 +579,7 @@ */ buffer_size = endpoint->wMaxPacketSize; dev->bulk_out_size = buffer_size; - dev->write_urb->transfer_flags = (URB_NO_DMA_MAP | + dev->write_urb->transfer_flags = (URB_NO_TRANSFER_DMA_MAP | URB_ASYNC_UNLINK); dev->bulk_out_buffer = usb_buffer_alloc (udev, buffer_size, GFP_KERNEL, @@ -601,6 +600,9 @@ goto error; } + /* allow device read, write and ioctl */ + dev->present = 1; + /* let the user know what node this device is now attached to */ info ("USB Skeleton device now attached to USBSkel-%d", dev->minor); @@ -663,10 +665,12 @@ wait_for_completion (&dev->write_finished); } - dev->udev = NULL; + /* prevent device read, write and ioctl */ + dev->present = 0; + up (&dev->sem); - /* if the device is not opened, then we clean up right now */ + /* if the device is opened, skel_release will clean this up */ if (!dev->open) skel_delete (dev);