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/apm-emulation.c | |
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/apm-emulation.c')
-rw-r--r-- | drivers/char/apm-emulation.c | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/drivers/char/apm-emulation.c b/drivers/char/apm-emulation.c index 033e1505fca9..6a420baea268 100644 --- a/drivers/char/apm-emulation.c +++ b/drivers/char/apm-emulation.c | |||
@@ -13,7 +13,7 @@ | |||
13 | #include <linux/module.h> | 13 | #include <linux/module.h> |
14 | #include <linux/poll.h> | 14 | #include <linux/poll.h> |
15 | #include <linux/slab.h> | 15 | #include <linux/slab.h> |
16 | #include <linux/smp_lock.h> | 16 | #include <linux/mutex.h> |
17 | #include <linux/proc_fs.h> | 17 | #include <linux/proc_fs.h> |
18 | #include <linux/seq_file.h> | 18 | #include <linux/seq_file.h> |
19 | #include <linux/miscdevice.h> | 19 | #include <linux/miscdevice.h> |
@@ -126,6 +126,7 @@ struct apm_user { | |||
126 | /* | 126 | /* |
127 | * Local variables | 127 | * Local variables |
128 | */ | 128 | */ |
129 | static DEFINE_MUTEX(apm_mutex); | ||
129 | static atomic_t suspend_acks_pending = ATOMIC_INIT(0); | 130 | static atomic_t suspend_acks_pending = ATOMIC_INIT(0); |
130 | static atomic_t userspace_notification_inhibit = ATOMIC_INIT(0); | 131 | static atomic_t userspace_notification_inhibit = ATOMIC_INIT(0); |
131 | static int apm_disabled; | 132 | static int apm_disabled; |
@@ -274,7 +275,7 @@ apm_ioctl(struct file *filp, u_int cmd, u_long arg) | |||
274 | if (!as->suser || !as->writer) | 275 | if (!as->suser || !as->writer) |
275 | return -EPERM; | 276 | return -EPERM; |
276 | 277 | ||
277 | lock_kernel(); | 278 | mutex_lock(&apm_mutex); |
278 | switch (cmd) { | 279 | switch (cmd) { |
279 | case APM_IOC_SUSPEND: | 280 | case APM_IOC_SUSPEND: |
280 | mutex_lock(&state_lock); | 281 | mutex_lock(&state_lock); |
@@ -335,7 +336,7 @@ apm_ioctl(struct file *filp, u_int cmd, u_long arg) | |||
335 | mutex_unlock(&state_lock); | 336 | mutex_unlock(&state_lock); |
336 | break; | 337 | break; |
337 | } | 338 | } |
338 | unlock_kernel(); | 339 | mutex_unlock(&apm_mutex); |
339 | 340 | ||
340 | return err; | 341 | return err; |
341 | } | 342 | } |
@@ -370,7 +371,7 @@ static int apm_open(struct inode * inode, struct file * filp) | |||
370 | { | 371 | { |
371 | struct apm_user *as; | 372 | struct apm_user *as; |
372 | 373 | ||
373 | lock_kernel(); | 374 | mutex_lock(&apm_mutex); |
374 | as = kzalloc(sizeof(*as), GFP_KERNEL); | 375 | as = kzalloc(sizeof(*as), GFP_KERNEL); |
375 | if (as) { | 376 | if (as) { |
376 | /* | 377 | /* |
@@ -390,7 +391,7 @@ static int apm_open(struct inode * inode, struct file * filp) | |||
390 | 391 | ||
391 | filp->private_data = as; | 392 | filp->private_data = as; |
392 | } | 393 | } |
393 | unlock_kernel(); | 394 | mutex_unlock(&apm_mutex); |
394 | 395 | ||
395 | return as ? 0 : -ENOMEM; | 396 | return as ? 0 : -ENOMEM; |
396 | } | 397 | } |