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/ds1302.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/ds1302.c')
-rw-r--r-- | drivers/char/ds1302.c | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/drivers/char/ds1302.c b/drivers/char/ds1302.c index 170693c93c73..e3d72aa3cbd2 100644 --- a/drivers/char/ds1302.c +++ b/drivers/char/ds1302.c | |||
@@ -20,7 +20,7 @@ | |||
20 | #include <linux/miscdevice.h> | 20 | #include <linux/miscdevice.h> |
21 | #include <linux/delay.h> | 21 | #include <linux/delay.h> |
22 | #include <linux/bcd.h> | 22 | #include <linux/bcd.h> |
23 | #include <linux/smp_lock.h> | 23 | #include <linux/mutex.h> |
24 | #include <linux/uaccess.h> | 24 | #include <linux/uaccess.h> |
25 | #include <linux/io.h> | 25 | #include <linux/io.h> |
26 | 26 | ||
@@ -32,6 +32,7 @@ | |||
32 | 32 | ||
33 | #define RTC_MAJOR_NR 121 /* local major, change later */ | 33 | #define RTC_MAJOR_NR 121 /* local major, change later */ |
34 | 34 | ||
35 | static DEFINE_MUTEX(rtc_mutex); | ||
35 | static const char ds1302_name[] = "ds1302"; | 36 | static const char ds1302_name[] = "ds1302"; |
36 | 37 | ||
37 | /* Send 8 bits. */ | 38 | /* Send 8 bits. */ |
@@ -164,9 +165,9 @@ static long rtc_ioctl(struct file *file, unsigned int cmd, unsigned long arg) | |||
164 | struct rtc_time rtc_tm; | 165 | struct rtc_time rtc_tm; |
165 | 166 | ||
166 | memset(&rtc_tm, 0, sizeof (struct rtc_time)); | 167 | memset(&rtc_tm, 0, sizeof (struct rtc_time)); |
167 | lock_kernel(); | 168 | mutex_lock(&rtc_mutex); |
168 | get_rtc_time(&rtc_tm); | 169 | get_rtc_time(&rtc_tm); |
169 | unlock_kernel(); | 170 | mutex_unlock(&rtc_mutex); |
170 | if (copy_to_user((struct rtc_time*)arg, &rtc_tm, sizeof(struct rtc_time))) | 171 | if (copy_to_user((struct rtc_time*)arg, &rtc_tm, sizeof(struct rtc_time))) |
171 | return -EFAULT; | 172 | return -EFAULT; |
172 | return 0; | 173 | return 0; |
@@ -218,7 +219,7 @@ static long rtc_ioctl(struct file *file, unsigned int cmd, unsigned long arg) | |||
218 | mon = bin2bcd(mon); | 219 | mon = bin2bcd(mon); |
219 | yrs = bin2bcd(yrs); | 220 | yrs = bin2bcd(yrs); |
220 | 221 | ||
221 | lock_kernel(); | 222 | mutex_lock(&rtc_mutex); |
222 | local_irq_save(flags); | 223 | local_irq_save(flags); |
223 | CMOS_WRITE(yrs, RTC_YEAR); | 224 | CMOS_WRITE(yrs, RTC_YEAR); |
224 | CMOS_WRITE(mon, RTC_MONTH); | 225 | CMOS_WRITE(mon, RTC_MONTH); |
@@ -227,7 +228,7 @@ static long rtc_ioctl(struct file *file, unsigned int cmd, unsigned long arg) | |||
227 | CMOS_WRITE(min, RTC_MINUTES); | 228 | CMOS_WRITE(min, RTC_MINUTES); |
228 | CMOS_WRITE(sec, RTC_SECONDS); | 229 | CMOS_WRITE(sec, RTC_SECONDS); |
229 | local_irq_restore(flags); | 230 | local_irq_restore(flags); |
230 | unlock_kernel(); | 231 | mutex_unlock(&rtc_mutex); |
231 | 232 | ||
232 | /* Notice that at this point, the RTC is updated but | 233 | /* Notice that at this point, the RTC is updated but |
233 | * the kernel is still running with the old time. | 234 | * the kernel is still running with the old time. |
@@ -247,10 +248,10 @@ static long rtc_ioctl(struct file *file, unsigned int cmd, unsigned long arg) | |||
247 | if(copy_from_user(&tcs_val, (int*)arg, sizeof(int))) | 248 | if(copy_from_user(&tcs_val, (int*)arg, sizeof(int))) |
248 | return -EFAULT; | 249 | return -EFAULT; |
249 | 250 | ||
250 | lock_kernel(); | 251 | mutex_lock(&rtc_mutex); |
251 | tcs_val = RTC_TCR_PATTERN | (tcs_val & 0x0F); | 252 | tcs_val = RTC_TCR_PATTERN | (tcs_val & 0x0F); |
252 | ds1302_writereg(RTC_TRICKLECHARGER, tcs_val); | 253 | ds1302_writereg(RTC_TRICKLECHARGER, tcs_val); |
253 | unlock_kernel(); | 254 | mutex_unlock(&rtc_mutex); |
254 | return 0; | 255 | return 0; |
255 | } | 256 | } |
256 | default: | 257 | default: |