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/sbus/char/jsflash.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/sbus/char/jsflash.c')
| -rw-r--r-- | drivers/sbus/char/jsflash.c | 24 |
1 files changed, 13 insertions, 11 deletions
diff --git a/drivers/sbus/char/jsflash.c b/drivers/sbus/char/jsflash.c index 4942050dc5b6..13f48e28a1e1 100644 --- a/drivers/sbus/char/jsflash.c +++ b/drivers/sbus/char/jsflash.c | |||
| @@ -27,7 +27,7 @@ | |||
| 27 | */ | 27 | */ |
| 28 | 28 | ||
| 29 | #include <linux/module.h> | 29 | #include <linux/module.h> |
| 30 | #include <linux/smp_lock.h> | 30 | #include <linux/mutex.h> |
| 31 | #include <linux/types.h> | 31 | #include <linux/types.h> |
| 32 | #include <linux/errno.h> | 32 | #include <linux/errno.h> |
| 33 | #include <linux/miscdevice.h> | 33 | #include <linux/miscdevice.h> |
| @@ -68,6 +68,8 @@ | |||
| 68 | #define JSF_PART_BITS 2 /* 2 bits of minors to cover JSF_NPART */ | 68 | #define JSF_PART_BITS 2 /* 2 bits of minors to cover JSF_NPART */ |
| 69 | #define JSF_PART_MASK 0x3 /* 2 bits mask */ | 69 | #define JSF_PART_MASK 0x3 /* 2 bits mask */ |
| 70 | 70 | ||
| 71 | static DEFINE_MUTEX(jsf_mutex); | ||
| 72 | |||
| 71 | /* | 73 | /* |
| 72 | * Access functions. | 74 | * Access functions. |
| 73 | * We could ioremap(), but it's easier this way. | 75 | * We could ioremap(), but it's easier this way. |
| @@ -225,7 +227,7 @@ static loff_t jsf_lseek(struct file * file, loff_t offset, int orig) | |||
| 225 | { | 227 | { |
| 226 | loff_t ret; | 228 | loff_t ret; |
| 227 | 229 | ||
| 228 | lock_kernel(); | 230 | mutex_lock(&jsf_mutex); |
| 229 | switch (orig) { | 231 | switch (orig) { |
| 230 | case 0: | 232 | case 0: |
| 231 | file->f_pos = offset; | 233 | file->f_pos = offset; |
| @@ -238,7 +240,7 @@ static loff_t jsf_lseek(struct file * file, loff_t offset, int orig) | |||
| 238 | default: | 240 | default: |
| 239 | ret = -EINVAL; | 241 | ret = -EINVAL; |
| 240 | } | 242 | } |
| 241 | unlock_kernel(); | 243 | mutex_unlock(&jsf_mutex); |
| 242 | return ret; | 244 | return ret; |
| 243 | } | 245 | } |
| 244 | 246 | ||
| @@ -384,18 +386,18 @@ static int jsf_ioctl_program(void __user *arg) | |||
| 384 | 386 | ||
| 385 | static long jsf_ioctl(struct file *f, unsigned int cmd, unsigned long arg) | 387 | static long jsf_ioctl(struct file *f, unsigned int cmd, unsigned long arg) |
| 386 | { | 388 | { |
| 387 | lock_kernel(); | 389 | mutex_lock(&jsf_mutex); |
| 388 | int error = -ENOTTY; | 390 | int error = -ENOTTY; |
| 389 | void __user *argp = (void __user *)arg; | 391 | void __user *argp = (void __user *)arg; |
| 390 | 392 | ||
| 391 | if (!capable(CAP_SYS_ADMIN)) { | 393 | if (!capable(CAP_SYS_ADMIN)) { |
| 392 | unlock_kernel(); | 394 | mutex_unlock(&jsf_mutex); |
| 393 | return -EPERM; | 395 | return -EPERM; |
| 394 | } | 396 | } |
| 395 | switch (cmd) { | 397 | switch (cmd) { |
| 396 | case JSFLASH_IDENT: | 398 | case JSFLASH_IDENT: |
| 397 | if (copy_to_user(argp, &jsf0.id, JSFIDSZ)) { | 399 | if (copy_to_user(argp, &jsf0.id, JSFIDSZ)) { |
| 398 | unlock_kernel(); | 400 | mutex_unlock(&jsf_mutex); |
| 399 | return -EFAULT; | 401 | return -EFAULT; |
| 400 | } | 402 | } |
| 401 | break; | 403 | break; |
| @@ -407,7 +409,7 @@ static long jsf_ioctl(struct file *f, unsigned int cmd, unsigned long arg) | |||
| 407 | break; | 409 | break; |
| 408 | } | 410 | } |
| 409 | 411 | ||
| 410 | unlock_kernel(); | 412 | mutex_unlock(&jsf_mutex); |
| 411 | return error; | 413 | return error; |
| 412 | } | 414 | } |
| 413 | 415 | ||
| @@ -418,17 +420,17 @@ static int jsf_mmap(struct file * file, struct vm_area_struct * vma) | |||
| 418 | 420 | ||
| 419 | static int jsf_open(struct inode * inode, struct file * filp) | 421 | static int jsf_open(struct inode * inode, struct file * filp) |
| 420 | { | 422 | { |
| 421 | lock_kernel(); | 423 | mutex_lock(&jsf_mutex); |
| 422 | if (jsf0.base == 0) { | 424 | if (jsf0.base == 0) { |
| 423 | unlock_kernel(); | 425 | mutex_unlock(&jsf_mutex); |
| 424 | return -ENXIO; | 426 | return -ENXIO; |
| 425 | } | 427 | } |
| 426 | if (test_and_set_bit(0, (void *)&jsf0.busy) != 0) { | 428 | if (test_and_set_bit(0, (void *)&jsf0.busy) != 0) { |
| 427 | unlock_kernel(); | 429 | mutex_unlock(&jsf_mutex); |
| 428 | return -EBUSY; | 430 | return -EBUSY; |
| 429 | } | 431 | } |
| 430 | 432 | ||
| 431 | unlock_kernel(); | 433 | mutex_unlock(&jsf_mutex); |
| 432 | return 0; /* XXX What security? */ | 434 | return 0; /* XXX What security? */ |
| 433 | } | 435 | } |
| 434 | 436 | ||
