[media] tm6000: Add locking for USB transfers
authorThierry Reding <thierry.reding@avionic-design.de>
Thu, 4 Aug 2011 07:14:10 +0000 (04:14 -0300)
committerMauro Carvalho Chehab <mchehab@redhat.com>
Wed, 31 Aug 2011 20:17:18 +0000 (17:17 -0300)
This commit introduces the usb_lock mutex to ensure that a USB request
always gets the proper response. While this is currently not really
necessary it will become important as there are more users.

Signed-off-by: Thierry Reding <thierry.reding@avionic-design.de>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
drivers/staging/tm6000/tm6000-cards.c
drivers/staging/tm6000/tm6000-core.c
drivers/staging/tm6000/tm6000.h

index bac4309a386835a9c3a5cf16d6deaffc29903630..f247e7e685f92c13d2bd873b38d9774678ca2d03 100644 (file)
@@ -1168,6 +1168,7 @@ static int tm6000_usb_probe(struct usb_interface *interface,
                return -ENOMEM;
        }
        spin_lock_init(&dev->slock);
+       mutex_init(&dev->usb_lock);
 
        /* Increment usage count */
        tm6000_devused |= 1<<nr;
index f85e5f2cf75d58e6c9bb9ee52aed7338ff67a2b6..31fdf15477e13221763e7c4ecbdd66d25657b91a 100644 (file)
@@ -39,6 +39,8 @@ int tm6000_read_write_usb(struct tm6000_core *dev, u8 req_type, u8 req,
        unsigned int pipe;
        u8           *data = NULL;
 
+       mutex_lock(&dev->usb_lock);
+
        if (len)
                data = kzalloc(len, GFP_KERNEL);
 
@@ -86,9 +88,9 @@ int tm6000_read_write_usb(struct tm6000_core *dev, u8 req_type, u8 req,
        }
 
        kfree(data);
-
        msleep(5);
 
+       mutex_unlock(&dev->usb_lock);
        return ret;
 }
 
index 4323fc2c1487dd0382eca313d02820bafd52d9f4..cf57e1e3aa62145c6102bf7a03e158d83563bf84 100644 (file)
@@ -245,6 +245,7 @@ struct tm6000_core {
 
        /* locks */
        struct mutex                    lock;
+       struct mutex                    usb_lock;
 
        /* usb transfer */
        struct usb_device               *udev;          /* the usb device */