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/usblcd.c | |
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/usblcd.c')
-rw-r--r-- | drivers/usb/misc/usblcd.c | 16 |
1 files changed, 8 insertions, 8 deletions
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; |