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/nvram.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/nvram.c')
-rw-r--r-- | drivers/char/nvram.c | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/drivers/char/nvram.c b/drivers/char/nvram.c index 66d2917b003f..166f1e7aaa7e 100644 --- a/drivers/char/nvram.c +++ b/drivers/char/nvram.c | |||
@@ -109,10 +109,11 @@ | |||
109 | #include <linux/spinlock.h> | 109 | #include <linux/spinlock.h> |
110 | #include <linux/io.h> | 110 | #include <linux/io.h> |
111 | #include <linux/uaccess.h> | 111 | #include <linux/uaccess.h> |
112 | #include <linux/smp_lock.h> | 112 | #include <linux/mutex.h> |
113 | 113 | ||
114 | #include <asm/system.h> | 114 | #include <asm/system.h> |
115 | 115 | ||
116 | static DEFINE_MUTEX(nvram_mutex); | ||
116 | static DEFINE_SPINLOCK(nvram_state_lock); | 117 | static DEFINE_SPINLOCK(nvram_state_lock); |
117 | static int nvram_open_cnt; /* #times opened */ | 118 | static int nvram_open_cnt; /* #times opened */ |
118 | static int nvram_open_mode; /* special open modes */ | 119 | static int nvram_open_mode; /* special open modes */ |
@@ -308,7 +309,7 @@ static long nvram_ioctl(struct file *file, unsigned int cmd, | |||
308 | if (!capable(CAP_SYS_ADMIN)) | 309 | if (!capable(CAP_SYS_ADMIN)) |
309 | return -EACCES; | 310 | return -EACCES; |
310 | 311 | ||
311 | lock_kernel(); | 312 | mutex_lock(&nvram_mutex); |
312 | spin_lock_irq(&rtc_lock); | 313 | spin_lock_irq(&rtc_lock); |
313 | 314 | ||
314 | for (i = 0; i < NVRAM_BYTES; ++i) | 315 | for (i = 0; i < NVRAM_BYTES; ++i) |
@@ -316,7 +317,7 @@ static long nvram_ioctl(struct file *file, unsigned int cmd, | |||
316 | __nvram_set_checksum(); | 317 | __nvram_set_checksum(); |
317 | 318 | ||
318 | spin_unlock_irq(&rtc_lock); | 319 | spin_unlock_irq(&rtc_lock); |
319 | unlock_kernel(); | 320 | mutex_unlock(&nvram_mutex); |
320 | return 0; | 321 | return 0; |
321 | 322 | ||
322 | case NVRAM_SETCKS: | 323 | case NVRAM_SETCKS: |
@@ -325,11 +326,11 @@ static long nvram_ioctl(struct file *file, unsigned int cmd, | |||
325 | if (!capable(CAP_SYS_ADMIN)) | 326 | if (!capable(CAP_SYS_ADMIN)) |
326 | return -EACCES; | 327 | return -EACCES; |
327 | 328 | ||
328 | lock_kernel(); | 329 | mutex_lock(&nvram_mutex); |
329 | spin_lock_irq(&rtc_lock); | 330 | spin_lock_irq(&rtc_lock); |
330 | __nvram_set_checksum(); | 331 | __nvram_set_checksum(); |
331 | spin_unlock_irq(&rtc_lock); | 332 | spin_unlock_irq(&rtc_lock); |
332 | unlock_kernel(); | 333 | mutex_unlock(&nvram_mutex); |
333 | return 0; | 334 | return 0; |
334 | 335 | ||
335 | default: | 336 | default: |