diff options
author | Arnd Bergmann <arnd@arndb.de> | 2010-07-11 17:18:56 -0400 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@suse.de> | 2010-08-10 17:35:39 -0400 |
commit | 925ce689bb31960c839804c19ef38d676f1939b9 (patch) | |
tree | 620c9b0f054a613d86aaa62901f93019856de0f9 /drivers/usb/misc | |
parent | 7c7e2d00435bd8129c4bacb73fe4a2d4db4e7d7c (diff) |
USB: autoconvert trivial BKL users to private mutex
All these files use the big kernel lock in a trivial
way to serialize their private file operations,
typically resulting from an earlier semi-automatic
pushdown from VFS.
None of these drivers appears to want to lock against
other code, and they all use the BKL as the top-level
lock in their file operations, meaning that there
is no lock-order inversion problem.
Consequently, we can remove the BKL completely,
replacing it with a per-file mutex in every case.
Using a scripted approach means we can avoid
typos.
file=$1
name=$2
if grep -q lock_kernel ${file} ; then
if grep -q 'include.*linux.mutex.h' ${file} ; then
sed -i '/include.*<linux\/smp_lock.h>/d' ${file}
else
sed -i 's/include.*<linux\/smp_lock.h>.*$/include <linux\/mutex.h>/g' ${file}
fi
sed -i ${file} \
-e "/^#include.*linux.mutex.h/,$ {
1,/^\(static\|int\|long\)/ {
/^\(static\|int\|long\)/istatic DEFINE_MUTEX(${name}_mutex);
} }" \
-e "s/\(un\)*lock_kernel\>[ ]*()/mutex_\1lock(\&${name}_mutex)/g" \
-e '/[ ]*cycle_kernel_lock();/d'
else
sed -i -e '/include.*\<smp_lock.h\>/d' ${file} \
-e '/cycle_kernel_lock()/d'
fi
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'drivers/usb/misc')
-rw-r--r-- | drivers/usb/misc/iowarrior.c | 15 | ||||
-rw-r--r-- | drivers/usb/misc/rio500.c | 15 | ||||
-rw-r--r-- | drivers/usb/misc/usblcd.c | 16 |
3 files changed, 24 insertions, 22 deletions
diff --git a/drivers/usb/misc/iowarrior.c b/drivers/usb/misc/iowarrior.c index 7dc9d3c69984..82966458a004 100644 --- a/drivers/usb/misc/iowarrior.c +++ b/drivers/usb/misc/iowarrior.c | |||
@@ -18,7 +18,7 @@ | |||
18 | #include <linux/init.h> | 18 | #include <linux/init.h> |
19 | #include <linux/slab.h> | 19 | #include <linux/slab.h> |
20 | #include <linux/sched.h> | 20 | #include <linux/sched.h> |
21 | #include <linux/smp_lock.h> | 21 | #include <linux/mutex.h> |
22 | #include <linux/poll.h> | 22 | #include <linux/poll.h> |
23 | #include <linux/usb/iowarrior.h> | 23 | #include <linux/usb/iowarrior.h> |
24 | 24 | ||
@@ -61,6 +61,7 @@ MODULE_DESCRIPTION(DRIVER_DESC); | |||
61 | MODULE_LICENSE("GPL"); | 61 | MODULE_LICENSE("GPL"); |
62 | 62 | ||
63 | /* Module parameters */ | 63 | /* Module parameters */ |
64 | static DEFINE_MUTEX(iowarrior_mutex); | ||
64 | static int debug = 0; | 65 | static int debug = 0; |
65 | module_param(debug, bool, 0644); | 66 | module_param(debug, bool, 0644); |
66 | MODULE_PARM_DESC(debug, "debug=1 enables debugging messages"); | 67 | MODULE_PARM_DESC(debug, "debug=1 enables debugging messages"); |
@@ -493,7 +494,7 @@ static long iowarrior_ioctl(struct file *file, unsigned int cmd, | |||
493 | return -ENOMEM; | 494 | return -ENOMEM; |
494 | 495 | ||
495 | /* lock this object */ | 496 | /* lock this object */ |
496 | lock_kernel(); | 497 | mutex_lock(&iowarrior_mutex); |
497 | mutex_lock(&dev->mutex); | 498 | mutex_lock(&dev->mutex); |
498 | 499 | ||
499 | /* verify that the device wasn't unplugged */ | 500 | /* verify that the device wasn't unplugged */ |
@@ -585,7 +586,7 @@ static long iowarrior_ioctl(struct file *file, unsigned int cmd, | |||
585 | error_out: | 586 | error_out: |
586 | /* unlock the device */ | 587 | /* unlock the device */ |
587 | mutex_unlock(&dev->mutex); | 588 | mutex_unlock(&dev->mutex); |
588 | unlock_kernel(); | 589 | mutex_unlock(&iowarrior_mutex); |
589 | kfree(buffer); | 590 | kfree(buffer); |
590 | return retval; | 591 | return retval; |
591 | } | 592 | } |
@@ -602,12 +603,12 @@ static int iowarrior_open(struct inode *inode, struct file *file) | |||
602 | 603 | ||
603 | dbg("%s", __func__); | 604 | dbg("%s", __func__); |
604 | 605 | ||
605 | lock_kernel(); | 606 | mutex_lock(&iowarrior_mutex); |
606 | subminor = iminor(inode); | 607 | subminor = iminor(inode); |
607 | 608 | ||
608 | interface = usb_find_interface(&iowarrior_driver, subminor); | 609 | interface = usb_find_interface(&iowarrior_driver, subminor); |
609 | if (!interface) { | 610 | if (!interface) { |
610 | unlock_kernel(); | 611 | mutex_unlock(&iowarrior_mutex); |
611 | err("%s - error, can't find device for minor %d", __func__, | 612 | err("%s - error, can't find device for minor %d", __func__, |
612 | subminor); | 613 | subminor); |
613 | return -ENODEV; | 614 | return -ENODEV; |
@@ -617,7 +618,7 @@ static int iowarrior_open(struct inode *inode, struct file *file) | |||
617 | dev = usb_get_intfdata(interface); | 618 | dev = usb_get_intfdata(interface); |
618 | if (!dev) { | 619 | if (!dev) { |
619 | mutex_unlock(&iowarrior_open_disc_lock); | 620 | mutex_unlock(&iowarrior_open_disc_lock); |
620 | unlock_kernel(); | 621 | mutex_unlock(&iowarrior_mutex); |
621 | return -ENODEV; | 622 | return -ENODEV; |
622 | } | 623 | } |
623 | 624 | ||
@@ -644,7 +645,7 @@ static int iowarrior_open(struct inode *inode, struct file *file) | |||
644 | 645 | ||
645 | out: | 646 | out: |
646 | mutex_unlock(&dev->mutex); | 647 | mutex_unlock(&dev->mutex); |
647 | unlock_kernel(); | 648 | mutex_unlock(&iowarrior_mutex); |
648 | return retval; | 649 | return retval; |
649 | } | 650 | } |
650 | 651 | ||
diff --git a/drivers/usb/misc/rio500.c b/drivers/usb/misc/rio500.c index a85771b1563d..cc13ae61712a 100644 --- a/drivers/usb/misc/rio500.c +++ b/drivers/usb/misc/rio500.c | |||
@@ -32,7 +32,7 @@ | |||
32 | #include <linux/kernel.h> | 32 | #include <linux/kernel.h> |
33 | #include <linux/signal.h> | 33 | #include <linux/signal.h> |
34 | #include <linux/sched.h> | 34 | #include <linux/sched.h> |
35 | #include <linux/smp_lock.h> | 35 | #include <linux/mutex.h> |
36 | #include <linux/errno.h> | 36 | #include <linux/errno.h> |
37 | #include <linux/random.h> | 37 | #include <linux/random.h> |
38 | #include <linux/poll.h> | 38 | #include <linux/poll.h> |
@@ -72,6 +72,7 @@ struct rio_usb_data { | |||
72 | struct mutex lock; /* general race avoidance */ | 72 | struct mutex lock; /* general race avoidance */ |
73 | }; | 73 | }; |
74 | 74 | ||
75 | static DEFINE_MUTEX(rio500_mutex); | ||
75 | static struct rio_usb_data rio_instance; | 76 | static struct rio_usb_data rio_instance; |
76 | 77 | ||
77 | static int open_rio(struct inode *inode, struct file *file) | 78 | static int open_rio(struct inode *inode, struct file *file) |
@@ -79,12 +80,12 @@ static int open_rio(struct inode *inode, struct file *file) | |||
79 | struct rio_usb_data *rio = &rio_instance; | 80 | struct rio_usb_data *rio = &rio_instance; |
80 | 81 | ||
81 | /* against disconnect() */ | 82 | /* against disconnect() */ |
82 | lock_kernel(); | 83 | mutex_lock(&rio500_mutex); |
83 | mutex_lock(&(rio->lock)); | 84 | mutex_lock(&(rio->lock)); |
84 | 85 | ||
85 | if (rio->isopen || !rio->present) { | 86 | if (rio->isopen || !rio->present) { |
86 | mutex_unlock(&(rio->lock)); | 87 | mutex_unlock(&(rio->lock)); |
87 | unlock_kernel(); | 88 | mutex_unlock(&rio500_mutex); |
88 | return -EBUSY; | 89 | return -EBUSY; |
89 | } | 90 | } |
90 | rio->isopen = 1; | 91 | rio->isopen = 1; |
@@ -94,7 +95,7 @@ static int open_rio(struct inode *inode, struct file *file) | |||
94 | mutex_unlock(&(rio->lock)); | 95 | mutex_unlock(&(rio->lock)); |
95 | 96 | ||
96 | dev_info(&rio->rio_dev->dev, "Rio opened.\n"); | 97 | dev_info(&rio->rio_dev->dev, "Rio opened.\n"); |
97 | unlock_kernel(); | 98 | mutex_unlock(&rio500_mutex); |
98 | 99 | ||
99 | return 0; | 100 | return 0; |
100 | } | 101 | } |
@@ -491,7 +492,7 @@ static void disconnect_rio(struct usb_interface *intf) | |||
491 | struct rio_usb_data *rio = usb_get_intfdata (intf); | 492 | struct rio_usb_data *rio = usb_get_intfdata (intf); |
492 | 493 | ||
493 | usb_set_intfdata (intf, NULL); | 494 | usb_set_intfdata (intf, NULL); |
494 | lock_kernel(); | 495 | mutex_lock(&rio500_mutex); |
495 | if (rio) { | 496 | if (rio) { |
496 | usb_deregister_dev(intf, &usb_rio_class); | 497 | usb_deregister_dev(intf, &usb_rio_class); |
497 | 498 | ||
@@ -501,7 +502,7 @@ static void disconnect_rio(struct usb_interface *intf) | |||
501 | /* better let it finish - the release will do whats needed */ | 502 | /* better let it finish - the release will do whats needed */ |
502 | rio->rio_dev = NULL; | 503 | rio->rio_dev = NULL; |
503 | mutex_unlock(&(rio->lock)); | 504 | mutex_unlock(&(rio->lock)); |
504 | unlock_kernel(); | 505 | mutex_unlock(&rio500_mutex); |
505 | return; | 506 | return; |
506 | } | 507 | } |
507 | kfree(rio->ibuf); | 508 | kfree(rio->ibuf); |
@@ -512,7 +513,7 @@ static void disconnect_rio(struct usb_interface *intf) | |||
512 | rio->present = 0; | 513 | rio->present = 0; |
513 | mutex_unlock(&(rio->lock)); | 514 | mutex_unlock(&(rio->lock)); |
514 | } | 515 | } |
515 | unlock_kernel(); | 516 | mutex_unlock(&rio500_mutex); |
516 | } | 517 | } |
517 | 518 | ||
518 | static const struct usb_device_id rio_table[] = { | 519 | static const struct usb_device_id rio_table[] = { |
diff --git a/drivers/usb/misc/usblcd.c b/drivers/usb/misc/usblcd.c index 7828c764b323..6ae39e3e5046 100644 --- a/drivers/usb/misc/usblcd.c +++ b/drivers/usb/misc/usblcd.c | |||
@@ -16,7 +16,6 @@ | |||
16 | #include <linux/kernel.h> | 16 | #include <linux/kernel.h> |
17 | #include <linux/init.h> | 17 | #include <linux/init.h> |
18 | #include <linux/slab.h> | 18 | #include <linux/slab.h> |
19 | #include <linux/smp_lock.h> | ||
20 | #include <linux/errno.h> | 19 | #include <linux/errno.h> |
21 | #include <linux/mutex.h> | 20 | #include <linux/mutex.h> |
22 | #include <asm/uaccess.h> | 21 | #include <asm/uaccess.h> |
@@ -30,6 +29,7 @@ | |||
30 | #define IOCTL_GET_DRV_VERSION 2 | 29 | #define IOCTL_GET_DRV_VERSION 2 |
31 | 30 | ||
32 | 31 | ||
32 | static DEFINE_MUTEX(lcd_mutex); | ||
33 | static const struct usb_device_id id_table[] = { | 33 | static const struct usb_device_id id_table[] = { |
34 | { .idVendor = 0x10D2, .match_flags = USB_DEVICE_ID_MATCH_VENDOR, }, | 34 | { .idVendor = 0x10D2, .match_flags = USB_DEVICE_ID_MATCH_VENDOR, }, |
35 | { }, | 35 | { }, |
@@ -74,12 +74,12 @@ static int lcd_open(struct inode *inode, struct file *file) | |||
74 | struct usb_interface *interface; | 74 | struct usb_interface *interface; |
75 | int subminor, r; | 75 | int subminor, r; |
76 | 76 | ||
77 | lock_kernel(); | 77 | mutex_lock(&lcd_mutex); |
78 | subminor = iminor(inode); | 78 | subminor = iminor(inode); |
79 | 79 | ||
80 | interface = usb_find_interface(&lcd_driver, subminor); | 80 | interface = usb_find_interface(&lcd_driver, subminor); |
81 | if (!interface) { | 81 | if (!interface) { |
82 | unlock_kernel(); | 82 | mutex_unlock(&lcd_mutex); |
83 | err ("USBLCD: %s - error, can't find device for minor %d", | 83 | err ("USBLCD: %s - error, can't find device for minor %d", |
84 | __func__, subminor); | 84 | __func__, subminor); |
85 | return -ENODEV; | 85 | return -ENODEV; |
@@ -89,7 +89,7 @@ static int lcd_open(struct inode *inode, struct file *file) | |||
89 | dev = usb_get_intfdata(interface); | 89 | dev = usb_get_intfdata(interface); |
90 | if (!dev) { | 90 | if (!dev) { |
91 | mutex_unlock(&open_disc_mutex); | 91 | mutex_unlock(&open_disc_mutex); |
92 | unlock_kernel(); | 92 | mutex_unlock(&lcd_mutex); |
93 | return -ENODEV; | 93 | return -ENODEV; |
94 | } | 94 | } |
95 | 95 | ||
@@ -101,13 +101,13 @@ static int lcd_open(struct inode *inode, struct file *file) | |||
101 | r = usb_autopm_get_interface(interface); | 101 | r = usb_autopm_get_interface(interface); |
102 | if (r < 0) { | 102 | if (r < 0) { |
103 | kref_put(&dev->kref, lcd_delete); | 103 | kref_put(&dev->kref, lcd_delete); |
104 | unlock_kernel(); | 104 | mutex_unlock(&lcd_mutex); |
105 | return r; | 105 | return r; |
106 | } | 106 | } |
107 | 107 | ||
108 | /* save our object in the file's private structure */ | 108 | /* save our object in the file's private structure */ |
109 | file->private_data = dev; | 109 | file->private_data = dev; |
110 | unlock_kernel(); | 110 | mutex_unlock(&lcd_mutex); |
111 | 111 | ||
112 | return 0; | 112 | return 0; |
113 | } | 113 | } |
@@ -164,14 +164,14 @@ static long lcd_ioctl(struct file *file, unsigned int cmd, unsigned long arg) | |||
164 | 164 | ||
165 | switch (cmd) { | 165 | switch (cmd) { |
166 | case IOCTL_GET_HARD_VERSION: | 166 | case IOCTL_GET_HARD_VERSION: |
167 | lock_kernel(); | 167 | mutex_lock(&lcd_mutex); |
168 | bcdDevice = le16_to_cpu((dev->udev)->descriptor.bcdDevice); | 168 | bcdDevice = le16_to_cpu((dev->udev)->descriptor.bcdDevice); |
169 | sprintf(buf,"%1d%1d.%1d%1d", | 169 | sprintf(buf,"%1d%1d.%1d%1d", |
170 | (bcdDevice & 0xF000)>>12, | 170 | (bcdDevice & 0xF000)>>12, |
171 | (bcdDevice & 0xF00)>>8, | 171 | (bcdDevice & 0xF00)>>8, |
172 | (bcdDevice & 0xF0)>>4, | 172 | (bcdDevice & 0xF0)>>4, |
173 | (bcdDevice & 0xF)); | 173 | (bcdDevice & 0xF)); |
174 | unlock_kernel(); | 174 | mutex_unlock(&lcd_mutex); |
175 | if (copy_to_user((void __user *)arg,buf,strlen(buf))!=0) | 175 | if (copy_to_user((void __user *)arg,buf,strlen(buf))!=0) |
176 | return -EFAULT; | 176 | return -EFAULT; |
177 | break; | 177 | break; |