Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 72577
b: refs/heads/master
c: 54d2bc0
h: refs/heads/master
i:
  72575: 2fc1927
v: v3
  • Loading branch information
Oliver Neukum authored and Greg Kroah-Hartman committed Oct 25, 2007
1 parent 0e7cc15 commit c6adb60
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 18 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 439a903a9663c0caa8094f3907ca60069d6c36e7
refs/heads/master: 54d2bc068fd21bcb096660938bce7c7265613a24
45 changes: 28 additions & 17 deletions trunk/drivers/usb/misc/idmouse.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ static struct usb_device_id idmouse_table[] = {
USB_TYPE_VENDOR | USB_RECIP_ENDPOINT | USB_DIR_OUT, value, index, NULL, 0, 1000)

MODULE_DEVICE_TABLE(usb, idmouse_table);
static DEFINE_MUTEX(open_disc_mutex);

/* structure to hold all of our device specific stuff */
struct usb_idmouse {
Expand All @@ -80,7 +81,7 @@ struct usb_idmouse {

int open; /* if the port is open or not */
int present; /* if the device is not disconnected */
struct semaphore sem; /* locks this structure */
struct mutex lock; /* locks this structure */

};

Expand Down Expand Up @@ -213,13 +214,17 @@ static int idmouse_open(struct inode *inode, struct file *file)
if (!interface)
return -ENODEV;

mutex_lock(&open_disc_mutex);
/* get the device information block from the interface */
dev = usb_get_intfdata(interface);
if (!dev)
if (!dev) {
mutex_unlock(&open_disc_mutex);
return -ENODEV;
}

/* lock this device */
down(&dev->sem);
mutex_lock(&dev->lock);
mutex_unlock(&open_disc_mutex);

/* check if already open */
if (dev->open) {
Expand All @@ -245,7 +250,7 @@ static int idmouse_open(struct inode *inode, struct file *file)
error:

/* unlock this device */
up(&dev->sem);
mutex_unlock(&dev->lock);
return result;
}

Expand All @@ -258,23 +263,27 @@ static int idmouse_release(struct inode *inode, struct file *file)
if (dev == NULL)
return -ENODEV;

mutex_lock(&open_disc_mutex);
/* lock our device */
down(&dev->sem);
mutex_lock(&dev->lock);

/* are we really open? */
if (dev->open <= 0) {
up(&dev->sem);
mutex_unlock(&dev->lock);
mutex_unlock(&open_disc_mutex);
return -ENODEV;
}

--dev->open;

if (!dev->present) {
/* the device was unplugged before the file was released */
up(&dev->sem);
mutex_unlock(&dev->lock);
mutex_unlock(&open_disc_mutex);
idmouse_delete(dev);
} else {
up(&dev->sem);
mutex_unlock(&dev->lock);
mutex_unlock(&open_disc_mutex);
}
return 0;
}
Expand All @@ -286,18 +295,18 @@ static ssize_t idmouse_read(struct file *file, char __user *buffer, size_t count
int result;

/* lock this object */
down(&dev->sem);
mutex_lock(&dev->lock);

/* verify that the device wasn't unplugged */
if (!dev->present) {
up(&dev->sem);
mutex_unlock(&dev->lock);
return -ENODEV;
}

result = simple_read_from_buffer(buffer, count, ppos,
dev->bulk_in_buffer, IMGSIZE);
/* unlock the device */
up(&dev->sem);
mutex_unlock(&dev->lock);
return result;
}

Expand All @@ -320,7 +329,7 @@ static int idmouse_probe(struct usb_interface *interface,
if (dev == NULL)
return -ENOMEM;

init_MUTEX(&dev->sem);
mutex_init(&dev->lock);
dev->udev = udev;
dev->interface = interface;

Expand Down Expand Up @@ -372,24 +381,26 @@ static void idmouse_disconnect(struct usb_interface *interface)

/* get device structure */
dev = usb_get_intfdata(interface);
usb_set_intfdata(interface, NULL);

/* give back our minor */
usb_deregister_dev(interface, &idmouse_class);

/* lock it */
down(&dev->sem);
mutex_lock(&open_disc_mutex);
usb_set_intfdata(interface, NULL);
/* lock the device */
mutex_lock(&dev->lock);
mutex_unlock(&open_disc_mutex);

/* prevent device read, write and ioctl */
dev->present = 0;

/* if the device is opened, idmouse_release will clean this up */
if (!dev->open) {
up(&dev->sem);
mutex_unlock(&dev->lock);
idmouse_delete(dev);
} else {
/* unlock */
up(&dev->sem);
mutex_unlock(&dev->lock);
}

info("%s disconnected", DRIVER_DESC);
Expand Down

0 comments on commit c6adb60

Please sign in to comment.