diff options
author | Arnd Bergmann <arnd@arndb.de> | 2010-07-11 07:18:53 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2010-07-12 23:21:47 -0400 |
commit | 76a64921dad9acd76270dc74249f0dfe11c84bb8 (patch) | |
tree | 42eaa62b3c886e46b29bbae354fe87bf8475d970 /drivers/isdn/hysdn/hysdn_procconf.c | |
parent | d361fd599a991ff6c1d522a599c635b35d61ef30 (diff) |
isdn: 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.
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>
Cc: Karsten Keil <isdn@linux-pingi.de>
Cc: netdev@vger.kernel.org
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'drivers/isdn/hysdn/hysdn_procconf.c')
-rw-r--r-- | drivers/isdn/hysdn/hysdn_procconf.c | 21 |
1 files changed, 11 insertions, 10 deletions
diff --git a/drivers/isdn/hysdn/hysdn_procconf.c b/drivers/isdn/hysdn/hysdn_procconf.c index 80966462d6dc..96b3e39c3356 100644 --- a/drivers/isdn/hysdn/hysdn_procconf.c +++ b/drivers/isdn/hysdn/hysdn_procconf.c | |||
@@ -17,11 +17,12 @@ | |||
17 | #include <linux/proc_fs.h> | 17 | #include <linux/proc_fs.h> |
18 | #include <linux/pci.h> | 18 | #include <linux/pci.h> |
19 | #include <linux/slab.h> | 19 | #include <linux/slab.h> |
20 | #include <linux/smp_lock.h> | 20 | #include <linux/mutex.h> |
21 | #include <net/net_namespace.h> | 21 | #include <net/net_namespace.h> |
22 | 22 | ||
23 | #include "hysdn_defs.h" | 23 | #include "hysdn_defs.h" |
24 | 24 | ||
25 | static DEFINE_MUTEX(hysdn_conf_mutex); | ||
25 | static char *hysdn_procconf_revision = "$Revision: 1.8.6.4 $"; | 26 | static char *hysdn_procconf_revision = "$Revision: 1.8.6.4 $"; |
26 | 27 | ||
27 | #define INFO_OUT_LEN 80 /* length of info line including lf */ | 28 | #define INFO_OUT_LEN 80 /* length of info line including lf */ |
@@ -234,7 +235,7 @@ hysdn_conf_open(struct inode *ino, struct file *filep) | |||
234 | char *cp, *tmp; | 235 | char *cp, *tmp; |
235 | 236 | ||
236 | /* now search the addressed card */ | 237 | /* now search the addressed card */ |
237 | lock_kernel(); | 238 | mutex_lock(&hysdn_conf_mutex); |
238 | card = card_root; | 239 | card = card_root; |
239 | while (card) { | 240 | while (card) { |
240 | pd = card->procconf; | 241 | pd = card->procconf; |
@@ -243,7 +244,7 @@ hysdn_conf_open(struct inode *ino, struct file *filep) | |||
243 | card = card->next; /* search next entry */ | 244 | card = card->next; /* search next entry */ |
244 | } | 245 | } |
245 | if (!card) { | 246 | if (!card) { |
246 | unlock_kernel(); | 247 | mutex_unlock(&hysdn_conf_mutex); |
247 | return (-ENODEV); /* device is unknown/invalid */ | 248 | return (-ENODEV); /* device is unknown/invalid */ |
248 | } | 249 | } |
249 | if (card->debug_flags & (LOG_PROC_OPEN | LOG_PROC_ALL)) | 250 | if (card->debug_flags & (LOG_PROC_OPEN | LOG_PROC_ALL)) |
@@ -255,7 +256,7 @@ hysdn_conf_open(struct inode *ino, struct file *filep) | |||
255 | /* write only access -> write boot file or conf line */ | 256 | /* write only access -> write boot file or conf line */ |
256 | 257 | ||
257 | if (!(cnf = kmalloc(sizeof(struct conf_writedata), GFP_KERNEL))) { | 258 | if (!(cnf = kmalloc(sizeof(struct conf_writedata), GFP_KERNEL))) { |
258 | unlock_kernel(); | 259 | mutex_unlock(&hysdn_conf_mutex); |
259 | return (-EFAULT); | 260 | return (-EFAULT); |
260 | } | 261 | } |
261 | cnf->card = card; | 262 | cnf->card = card; |
@@ -267,7 +268,7 @@ hysdn_conf_open(struct inode *ino, struct file *filep) | |||
267 | /* read access -> output card info data */ | 268 | /* read access -> output card info data */ |
268 | 269 | ||
269 | if (!(tmp = kmalloc(INFO_OUT_LEN * 2 + 2, GFP_KERNEL))) { | 270 | if (!(tmp = kmalloc(INFO_OUT_LEN * 2 + 2, GFP_KERNEL))) { |
270 | unlock_kernel(); | 271 | mutex_unlock(&hysdn_conf_mutex); |
271 | return (-EFAULT); /* out of memory */ | 272 | return (-EFAULT); /* out of memory */ |
272 | } | 273 | } |
273 | filep->private_data = tmp; /* start of string */ | 274 | filep->private_data = tmp; /* start of string */ |
@@ -301,10 +302,10 @@ hysdn_conf_open(struct inode *ino, struct file *filep) | |||
301 | *cp++ = '\n'; | 302 | *cp++ = '\n'; |
302 | *cp = 0; /* end of string */ | 303 | *cp = 0; /* end of string */ |
303 | } else { /* simultaneous read/write access forbidden ! */ | 304 | } else { /* simultaneous read/write access forbidden ! */ |
304 | unlock_kernel(); | 305 | mutex_unlock(&hysdn_conf_mutex); |
305 | return (-EPERM); /* no permission this time */ | 306 | return (-EPERM); /* no permission this time */ |
306 | } | 307 | } |
307 | unlock_kernel(); | 308 | mutex_unlock(&hysdn_conf_mutex); |
308 | return nonseekable_open(ino, filep); | 309 | return nonseekable_open(ino, filep); |
309 | } /* hysdn_conf_open */ | 310 | } /* hysdn_conf_open */ |
310 | 311 | ||
@@ -319,7 +320,7 @@ hysdn_conf_close(struct inode *ino, struct file *filep) | |||
319 | int retval = 0; | 320 | int retval = 0; |
320 | struct proc_dir_entry *pd; | 321 | struct proc_dir_entry *pd; |
321 | 322 | ||
322 | lock_kernel(); | 323 | mutex_lock(&hysdn_conf_mutex); |
323 | /* search the addressed card */ | 324 | /* search the addressed card */ |
324 | card = card_root; | 325 | card = card_root; |
325 | while (card) { | 326 | while (card) { |
@@ -329,7 +330,7 @@ hysdn_conf_close(struct inode *ino, struct file *filep) | |||
329 | card = card->next; /* search next entry */ | 330 | card = card->next; /* search next entry */ |
330 | } | 331 | } |
331 | if (!card) { | 332 | if (!card) { |
332 | unlock_kernel(); | 333 | mutex_unlock(&hysdn_conf_mutex); |
333 | return (-ENODEV); /* device is unknown/invalid */ | 334 | return (-ENODEV); /* device is unknown/invalid */ |
334 | } | 335 | } |
335 | if (card->debug_flags & (LOG_PROC_OPEN | LOG_PROC_ALL)) | 336 | if (card->debug_flags & (LOG_PROC_OPEN | LOG_PROC_ALL)) |
@@ -352,7 +353,7 @@ hysdn_conf_close(struct inode *ino, struct file *filep) | |||
352 | 353 | ||
353 | kfree(filep->private_data); /* release memory */ | 354 | kfree(filep->private_data); /* release memory */ |
354 | } | 355 | } |
355 | unlock_kernel(); | 356 | mutex_unlock(&hysdn_conf_mutex); |
356 | return (retval); | 357 | return (retval); |
357 | } /* hysdn_conf_close */ | 358 | } /* hysdn_conf_close */ |
358 | 359 | ||