diff options
author | Arnd Bergmann <arnd@arndb.de> | 2010-06-02 08:28:52 -0400 |
---|---|---|
committer | Arnd Bergmann <arnd@arndb.de> | 2010-10-05 09:01:04 -0400 |
commit | 613655fa39ff6957754fa8ceb8559980920eb8ee (patch) | |
tree | ad19600cb81207b24188683d7fc4ae88013339d1 /drivers/char/pcmcia | |
parent | 609146fdb319cebce93be550938ab852f7bade90 (diff) |
drivers: 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.
These drivers do not seem to be under active
maintainance from my brief investigation. Apologies
to those maintainers that I have missed.
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>
Diffstat (limited to 'drivers/char/pcmcia')
-rw-r--r-- | drivers/char/pcmcia/cm4000_cs.c | 11 | ||||
-rw-r--r-- | drivers/char/pcmcia/cm4040_cs.c | 7 |
2 files changed, 10 insertions, 8 deletions
diff --git a/drivers/char/pcmcia/cm4000_cs.c b/drivers/char/pcmcia/cm4000_cs.c index ec73d9f6d9ed..7d091b68d247 100644 --- a/drivers/char/pcmcia/cm4000_cs.c +++ b/drivers/char/pcmcia/cm4000_cs.c | |||
@@ -30,7 +30,7 @@ | |||
30 | #include <linux/fs.h> | 30 | #include <linux/fs.h> |
31 | #include <linux/delay.h> | 31 | #include <linux/delay.h> |
32 | #include <linux/bitrev.h> | 32 | #include <linux/bitrev.h> |
33 | #include <linux/smp_lock.h> | 33 | #include <linux/mutex.h> |
34 | #include <linux/uaccess.h> | 34 | #include <linux/uaccess.h> |
35 | #include <linux/io.h> | 35 | #include <linux/io.h> |
36 | 36 | ||
@@ -55,6 +55,7 @@ | |||
55 | __func__ , ## args); \ | 55 | __func__ , ## args); \ |
56 | } while (0) | 56 | } while (0) |
57 | 57 | ||
58 | static DEFINE_MUTEX(cmm_mutex); | ||
58 | static char *version = "cm4000_cs.c v2.4.0gm6 - All bugs added by Harald Welte"; | 59 | static char *version = "cm4000_cs.c v2.4.0gm6 - All bugs added by Harald Welte"; |
59 | 60 | ||
60 | #define T_1SEC (HZ) | 61 | #define T_1SEC (HZ) |
@@ -1418,7 +1419,7 @@ static long cmm_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) | |||
1418 | iminor(inode), ioctl_names[_IOC_NR(cmd)]); | 1419 | iminor(inode), ioctl_names[_IOC_NR(cmd)]); |
1419 | #endif | 1420 | #endif |
1420 | 1421 | ||
1421 | lock_kernel(); | 1422 | mutex_lock(&cmm_mutex); |
1422 | rc = -ENODEV; | 1423 | rc = -ENODEV; |
1423 | link = dev_table[iminor(inode)]; | 1424 | link = dev_table[iminor(inode)]; |
1424 | if (!pcmcia_dev_present(link)) { | 1425 | if (!pcmcia_dev_present(link)) { |
@@ -1626,7 +1627,7 @@ static long cmm_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) | |||
1626 | rc = -ENOTTY; | 1627 | rc = -ENOTTY; |
1627 | } | 1628 | } |
1628 | out: | 1629 | out: |
1629 | unlock_kernel(); | 1630 | mutex_unlock(&cmm_mutex); |
1630 | return rc; | 1631 | return rc; |
1631 | } | 1632 | } |
1632 | 1633 | ||
@@ -1640,7 +1641,7 @@ static int cmm_open(struct inode *inode, struct file *filp) | |||
1640 | if (minor >= CM4000_MAX_DEV) | 1641 | if (minor >= CM4000_MAX_DEV) |
1641 | return -ENODEV; | 1642 | return -ENODEV; |
1642 | 1643 | ||
1643 | lock_kernel(); | 1644 | mutex_lock(&cmm_mutex); |
1644 | link = dev_table[minor]; | 1645 | link = dev_table[minor]; |
1645 | if (link == NULL || !pcmcia_dev_present(link)) { | 1646 | if (link == NULL || !pcmcia_dev_present(link)) { |
1646 | ret = -ENODEV; | 1647 | ret = -ENODEV; |
@@ -1685,7 +1686,7 @@ static int cmm_open(struct inode *inode, struct file *filp) | |||
1685 | DEBUGP(2, dev, "<- cmm_open\n"); | 1686 | DEBUGP(2, dev, "<- cmm_open\n"); |
1686 | ret = nonseekable_open(inode, filp); | 1687 | ret = nonseekable_open(inode, filp); |
1687 | out: | 1688 | out: |
1688 | unlock_kernel(); | 1689 | mutex_unlock(&cmm_mutex); |
1689 | return ret; | 1690 | return ret; |
1690 | } | 1691 | } |
1691 | 1692 | ||
diff --git a/drivers/char/pcmcia/cm4040_cs.c b/drivers/char/pcmcia/cm4040_cs.c index 815cde1d0570..04c0a895740e 100644 --- a/drivers/char/pcmcia/cm4040_cs.c +++ b/drivers/char/pcmcia/cm4040_cs.c | |||
@@ -24,7 +24,7 @@ | |||
24 | #include <linux/fs.h> | 24 | #include <linux/fs.h> |
25 | #include <linux/delay.h> | 25 | #include <linux/delay.h> |
26 | #include <linux/poll.h> | 26 | #include <linux/poll.h> |
27 | #include <linux/smp_lock.h> | 27 | #include <linux/mutex.h> |
28 | #include <linux/wait.h> | 28 | #include <linux/wait.h> |
29 | #include <asm/uaccess.h> | 29 | #include <asm/uaccess.h> |
30 | #include <asm/io.h> | 30 | #include <asm/io.h> |
@@ -49,6 +49,7 @@ | |||
49 | __func__ , ## args); \ | 49 | __func__ , ## args); \ |
50 | } while (0) | 50 | } while (0) |
51 | 51 | ||
52 | static DEFINE_MUTEX(cm4040_mutex); | ||
52 | static char *version = | 53 | static char *version = |
53 | "OMNIKEY CardMan 4040 v1.1.0gm5 - All bugs added by Harald Welte"; | 54 | "OMNIKEY CardMan 4040 v1.1.0gm5 - All bugs added by Harald Welte"; |
54 | 55 | ||
@@ -444,7 +445,7 @@ static int cm4040_open(struct inode *inode, struct file *filp) | |||
444 | if (minor >= CM_MAX_DEV) | 445 | if (minor >= CM_MAX_DEV) |
445 | return -ENODEV; | 446 | return -ENODEV; |
446 | 447 | ||
447 | lock_kernel(); | 448 | mutex_lock(&cm4040_mutex); |
448 | link = dev_table[minor]; | 449 | link = dev_table[minor]; |
449 | if (link == NULL || !pcmcia_dev_present(link)) { | 450 | if (link == NULL || !pcmcia_dev_present(link)) { |
450 | ret = -ENODEV; | 451 | ret = -ENODEV; |
@@ -473,7 +474,7 @@ static int cm4040_open(struct inode *inode, struct file *filp) | |||
473 | DEBUGP(2, dev, "<- cm4040_open (successfully)\n"); | 474 | DEBUGP(2, dev, "<- cm4040_open (successfully)\n"); |
474 | ret = nonseekable_open(inode, filp); | 475 | ret = nonseekable_open(inode, filp); |
475 | out: | 476 | out: |
476 | unlock_kernel(); | 477 | mutex_unlock(&cm4040_mutex); |
477 | return ret; | 478 | return ret; |
478 | } | 479 | } |
479 | 480 | ||