Commit 76a64921dad9acd76270dc74249f0dfe11c84bb8

Authored by Arnd Bergmann
Committed by David S. Miller
1 parent d361fd599a

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>

Showing 9 changed files with 48 additions and 46 deletions Side-by-side Diff

drivers/isdn/capi/capi.c
... ... @@ -20,7 +20,6 @@
20 20 #include <linux/signal.h>
21 21 #include <linux/mutex.h>
22 22 #include <linux/mm.h>
23   -#include <linux/smp_lock.h>
24 23 #include <linux/timer.h>
25 24 #include <linux/wait.h>
26 25 #include <linux/tty.h>
... ... @@ -50,6 +49,7 @@
50 49  
51 50 /* -------- driver information -------------------------------------- */
52 51  
  52 +static DEFINE_MUTEX(capi_mutex);
53 53 static struct class *capi_class;
54 54 static int capi_major = 68; /* allocated */
55 55  
56 56  
... ... @@ -985,9 +985,9 @@
985 985 {
986 986 int ret;
987 987  
988   - lock_kernel();
  988 + mutex_lock(&capi_mutex);
989 989 ret = capi_ioctl(file, cmd, arg);
990   - unlock_kernel();
  990 + mutex_unlock(&capi_mutex);
991 991  
992 992 return ret;
993 993 }
drivers/isdn/divert/divert_procfs.c
... ... @@ -20,7 +20,7 @@
20 20 #include <linux/sched.h>
21 21 #include <linux/isdnif.h>
22 22 #include <net/net_namespace.h>
23   -#include <linux/smp_lock.h>
  23 +#include <linux/mutex.h>
24 24 #include "isdn_divert.h"
25 25  
26 26  
... ... @@ -28,6 +28,7 @@
28 28 /* Variables for interface queue */
29 29 /*********************************/
30 30 ulong if_used = 0; /* number of interface users */
  31 +static DEFINE_MUTEX(isdn_divert_mutex);
31 32 static struct divert_info *divert_info_head = NULL; /* head of queue */
32 33 static struct divert_info *divert_info_tail = NULL; /* pointer to last entry */
33 34 static DEFINE_SPINLOCK(divert_info_lock);/* lock for queue */
34 35  
... ... @@ -261,9 +262,9 @@
261 262 {
262 263 long ret;
263 264  
264   - lock_kernel();
  265 + mutex_lock(&isdn_divert_mutex);
265 266 ret = isdn_divert_ioctl_unlocked(file, cmd, arg);
266   - unlock_kernel();
  267 + mutex_unlock(&isdn_divert_mutex);
267 268  
268 269 return ret;
269 270 }
drivers/isdn/hardware/eicon/divamnt.c
... ... @@ -14,7 +14,7 @@
14 14 #include <linux/init.h>
15 15 #include <linux/kernel.h>
16 16 #include <linux/poll.h>
17   -#include <linux/smp_lock.h>
  17 +#include <linux/mutex.h>
18 18 #include <asm/uaccess.h>
19 19  
20 20 #include "platform.h"
... ... @@ -22,6 +22,7 @@
22 22 #include "divasync.h"
23 23 #include "debug_if.h"
24 24  
  25 +static DEFINE_MUTEX(maint_mutex);
25 26 static char *main_revision = "$Revision: 1.32.6.10 $";
26 27  
27 28 static int major;
... ... @@ -130,7 +131,7 @@
130 131 {
131 132 int ret;
132 133  
133   - lock_kernel();
  134 + mutex_lock(&maint_mutex);
134 135 /* only one open is allowed, so we test
135 136 it atomically */
136 137 if (test_and_set_bit(0, &opened))
... ... @@ -139,7 +140,7 @@
139 140 filep->private_data = NULL;
140 141 ret = nonseekable_open(ino, filep);
141 142 }
142   - unlock_kernel();
  143 + mutex_unlock(&maint_mutex);
143 144 return ret;
144 145 }
145 146  
drivers/isdn/hardware/eicon/divasi.c
... ... @@ -18,7 +18,6 @@
18 18 #include <linux/proc_fs.h>
19 19 #include <linux/skbuff.h>
20 20 #include <linux/seq_file.h>
21   -#include <linux/smp_lock.h>
22 21 #include <asm/uaccess.h>
23 22  
24 23 #include "platform.h"
... ... @@ -402,7 +401,6 @@
402 401  
403 402 static int um_idi_open(struct inode *inode, struct file *file)
404 403 {
405   - cycle_kernel_lock();
406 404 return (0);
407 405 }
408 406  
drivers/isdn/hardware/eicon/divasmain.c
... ... @@ -21,7 +21,6 @@
21 21 #include <linux/list.h>
22 22 #include <linux/poll.h>
23 23 #include <linux/kmod.h>
24   -#include <linux/smp_lock.h>
25 24  
26 25 #include "platform.h"
27 26 #undef ID_MASK
... ... @@ -581,7 +580,6 @@
581 580 */
582 581 static int divas_open(struct inode *inode, struct file *file)
583 582 {
584   - cycle_kernel_lock();
585 583 return (0);
586 584 }
587 585  
drivers/isdn/hysdn/hysdn_procconf.c
... ... @@ -17,11 +17,12 @@
17 17 #include <linux/proc_fs.h>
18 18 #include <linux/pci.h>
19 19 #include <linux/slab.h>
20   -#include <linux/smp_lock.h>
  20 +#include <linux/mutex.h>
21 21 #include <net/net_namespace.h>
22 22  
23 23 #include "hysdn_defs.h"
24 24  
  25 +static DEFINE_MUTEX(hysdn_conf_mutex);
25 26 static char *hysdn_procconf_revision = "$Revision: 1.8.6.4 $";
26 27  
27 28 #define INFO_OUT_LEN 80 /* length of info line including lf */
... ... @@ -234,7 +235,7 @@
234 235 char *cp, *tmp;
235 236  
236 237 /* now search the addressed card */
237   - lock_kernel();
  238 + mutex_lock(&hysdn_conf_mutex);
238 239 card = card_root;
239 240 while (card) {
240 241 pd = card->procconf;
... ... @@ -243,7 +244,7 @@
243 244 card = card->next; /* search next entry */
244 245 }
245 246 if (!card) {
246   - unlock_kernel();
  247 + mutex_unlock(&hysdn_conf_mutex);
247 248 return (-ENODEV); /* device is unknown/invalid */
248 249 }
249 250 if (card->debug_flags & (LOG_PROC_OPEN | LOG_PROC_ALL))
... ... @@ -255,7 +256,7 @@
255 256 /* write only access -> write boot file or conf line */
256 257  
257 258 if (!(cnf = kmalloc(sizeof(struct conf_writedata), GFP_KERNEL))) {
258   - unlock_kernel();
  259 + mutex_unlock(&hysdn_conf_mutex);
259 260 return (-EFAULT);
260 261 }
261 262 cnf->card = card;
... ... @@ -267,7 +268,7 @@
267 268 /* read access -> output card info data */
268 269  
269 270 if (!(tmp = kmalloc(INFO_OUT_LEN * 2 + 2, GFP_KERNEL))) {
270   - unlock_kernel();
  271 + mutex_unlock(&hysdn_conf_mutex);
271 272 return (-EFAULT); /* out of memory */
272 273 }
273 274 filep->private_data = tmp; /* start of string */
274 275  
... ... @@ -301,10 +302,10 @@
301 302 *cp++ = '\n';
302 303 *cp = 0; /* end of string */
303 304 } else { /* simultaneous read/write access forbidden ! */
304   - unlock_kernel();
  305 + mutex_unlock(&hysdn_conf_mutex);
305 306 return (-EPERM); /* no permission this time */
306 307 }
307   - unlock_kernel();
  308 + mutex_unlock(&hysdn_conf_mutex);
308 309 return nonseekable_open(ino, filep);
309 310 } /* hysdn_conf_open */
310 311  
... ... @@ -319,7 +320,7 @@
319 320 int retval = 0;
320 321 struct proc_dir_entry *pd;
321 322  
322   - lock_kernel();
  323 + mutex_lock(&hysdn_conf_mutex);
323 324 /* search the addressed card */
324 325 card = card_root;
325 326 while (card) {
... ... @@ -329,7 +330,7 @@
329 330 card = card->next; /* search next entry */
330 331 }
331 332 if (!card) {
332   - unlock_kernel();
  333 + mutex_unlock(&hysdn_conf_mutex);
333 334 return (-ENODEV); /* device is unknown/invalid */
334 335 }
335 336 if (card->debug_flags & (LOG_PROC_OPEN | LOG_PROC_ALL))
... ... @@ -352,7 +353,7 @@
352 353  
353 354 kfree(filep->private_data); /* release memory */
354 355 }
355   - unlock_kernel();
  356 + mutex_unlock(&hysdn_conf_mutex);
356 357 return (retval);
357 358 } /* hysdn_conf_close */
358 359  
drivers/isdn/hysdn/hysdn_proclog.c
... ... @@ -15,13 +15,14 @@
15 15 #include <linux/proc_fs.h>
16 16 #include <linux/sched.h>
17 17 #include <linux/slab.h>
18   -#include <linux/smp_lock.h>
  18 +#include <linux/mutex.h>
19 19  
20 20 #include "hysdn_defs.h"
21 21  
22 22 /* the proc subdir for the interface is defined in the procconf module */
23 23 extern struct proc_dir_entry *hysdn_proc_entry;
24 24  
  25 +static DEFINE_MUTEX(hysdn_log_mutex);
25 26 static void put_log_buffer(hysdn_card * card, char *cp);
26 27  
27 28 /*************************************************/
... ... @@ -251,7 +252,7 @@
251 252 struct procdata *pd = NULL;
252 253 unsigned long flags;
253 254  
254   - lock_kernel();
  255 + mutex_lock(&hysdn_log_mutex);
255 256 card = card_root;
256 257 while (card) {
257 258 pd = card->proclog;
... ... @@ -260,7 +261,7 @@
260 261 card = card->next; /* search next entry */
261 262 }
262 263 if (!card) {
263   - unlock_kernel();
  264 + mutex_unlock(&hysdn_log_mutex);
264 265 return (-ENODEV); /* device is unknown/invalid */
265 266 }
266 267 filep->private_data = card; /* remember our own card */
267 268  
... ... @@ -278,10 +279,10 @@
278 279 filep->private_data = &pd->log_head;
279 280 spin_unlock_irqrestore(&card->hysdn_lock, flags);
280 281 } else { /* simultaneous read/write access forbidden ! */
281   - unlock_kernel();
  282 + mutex_unlock(&hysdn_log_mutex);
282 283 return (-EPERM); /* no permission this time */
283 284 }
284   - unlock_kernel();
  285 + mutex_unlock(&hysdn_log_mutex);
285 286 return nonseekable_open(ino, filep);
286 287 } /* hysdn_log_open */
287 288  
... ... @@ -300,7 +301,7 @@
300 301 hysdn_card *card;
301 302 int retval = 0;
302 303  
303   - lock_kernel();
  304 + mutex_lock(&hysdn_log_mutex);
304 305 if ((filep->f_mode & (FMODE_READ | FMODE_WRITE)) == FMODE_WRITE) {
305 306 /* write only access -> write debug level written */
306 307 retval = 0; /* success */
... ... @@ -339,7 +340,7 @@
339 340 kfree(inf);
340 341 }
341 342 } /* read access */
342   - unlock_kernel();
  343 + mutex_unlock(&hysdn_log_mutex);
343 344  
344 345 return (retval);
345 346 } /* hysdn_log_close */
drivers/isdn/i4l/isdn_common.c
... ... @@ -17,7 +17,7 @@
17 17 #include <linux/slab.h>
18 18 #include <linux/vmalloc.h>
19 19 #include <linux/isdn.h>
20   -#include <linux/smp_lock.h>
  20 +#include <linux/mutex.h>
21 21 #include "isdn_common.h"
22 22 #include "isdn_tty.h"
23 23 #include "isdn_net.h"
... ... @@ -42,6 +42,7 @@
42 42  
43 43 isdn_dev *dev;
44 44  
  45 +static DEFINE_MUTEX(isdn_mutex);
45 46 static char *isdn_revision = "$Revision: 1.1.2.3 $";
46 47  
47 48 extern char *isdn_net_revision;
... ... @@ -1070,7 +1071,7 @@
1070 1071 int retval;
1071 1072 char *p;
1072 1073  
1073   - lock_kernel();
  1074 + mutex_lock(&isdn_mutex);
1074 1075 if (minor == ISDN_MINOR_STATUS) {
1075 1076 if (!file->private_data) {
1076 1077 if (file->f_flags & O_NONBLOCK) {
... ... @@ -1163,7 +1164,7 @@
1163 1164 #endif
1164 1165 retval = -ENODEV;
1165 1166 out:
1166   - unlock_kernel();
  1167 + mutex_unlock(&isdn_mutex);
1167 1168 return retval;
1168 1169 }
1169 1170  
... ... @@ -1180,7 +1181,7 @@
1180 1181 if (!dev->drivers)
1181 1182 return -ENODEV;
1182 1183  
1183   - lock_kernel();
  1184 + mutex_lock(&isdn_mutex);
1184 1185 if (minor <= ISDN_MINOR_BMAX) {
1185 1186 printk(KERN_WARNING "isdn_write minor %d obsolete!\n", minor);
1186 1187 drvidx = isdn_minor2drv(minor);
... ... @@ -1225,7 +1226,7 @@
1225 1226 #endif
1226 1227 retval = -ENODEV;
1227 1228 out:
1228   - unlock_kernel();
  1229 + mutex_unlock(&isdn_mutex);
1229 1230 return retval;
1230 1231 }
1231 1232  
... ... @@ -1236,7 +1237,7 @@
1236 1237 unsigned int minor = iminor(file->f_path.dentry->d_inode);
1237 1238 int drvidx = isdn_minor2drv(minor - ISDN_MINOR_CTRL);
1238 1239  
1239   - lock_kernel();
  1240 + mutex_lock(&isdn_mutex);
1240 1241 if (minor == ISDN_MINOR_STATUS) {
1241 1242 poll_wait(file, &(dev->info_waitq), wait);
1242 1243 /* mask = POLLOUT | POLLWRNORM; */
... ... @@ -1266,7 +1267,7 @@
1266 1267 #endif
1267 1268 mask = POLLERR;
1268 1269 out:
1269   - unlock_kernel();
  1270 + mutex_unlock(&isdn_mutex);
1270 1271 return mask;
1271 1272 }
1272 1273  
1273 1274  
... ... @@ -1727,9 +1728,9 @@
1727 1728 {
1728 1729 int ret;
1729 1730  
1730   - lock_kernel();
  1731 + mutex_lock(&isdn_mutex);
1731 1732 ret = isdn_ioctl(file, cmd, arg);
1732   - unlock_kernel();
  1733 + mutex_unlock(&isdn_mutex);
1733 1734  
1734 1735 return ret;
1735 1736 }
... ... @@ -1745,7 +1746,7 @@
1745 1746 int chidx;
1746 1747 int retval = -ENODEV;
1747 1748  
1748   - lock_kernel();
  1749 + mutex_lock(&isdn_mutex);
1749 1750 if (minor == ISDN_MINOR_STATUS) {
1750 1751 infostruct *p;
1751 1752  
... ... @@ -1796,7 +1797,7 @@
1796 1797 #endif
1797 1798 out:
1798 1799 nonseekable_open(ino, filep);
1799   - unlock_kernel();
  1800 + mutex_unlock(&isdn_mutex);
1800 1801 return retval;
1801 1802 }
1802 1803  
... ... @@ -1805,7 +1806,7 @@
1805 1806 {
1806 1807 uint minor = iminor(ino);
1807 1808  
1808   - lock_kernel();
  1809 + mutex_lock(&isdn_mutex);
1809 1810 if (minor == ISDN_MINOR_STATUS) {
1810 1811 infostruct *p = dev->infochain;
1811 1812 infostruct *q = NULL;
... ... @@ -1839,7 +1840,7 @@
1839 1840 #endif
1840 1841  
1841 1842 out:
1842   - unlock_kernel();
  1843 + mutex_unlock(&isdn_mutex);
1843 1844 return 0;
1844 1845 }
1845 1846  
drivers/isdn/mISDN/timerdev.c
... ... @@ -24,9 +24,10 @@
24 24 #include <linux/miscdevice.h>
25 25 #include <linux/module.h>
26 26 #include <linux/mISDNif.h>
27   -#include <linux/smp_lock.h>
  27 +#include <linux/mutex.h>
28 28 #include "core.h"
29 29  
  30 +static DEFINE_MUTEX(mISDN_mutex);
30 31 static u_int *debug;
31 32  
32 33  
... ... @@ -224,7 +225,7 @@
224 225 if (*debug & DEBUG_TIMER)
225 226 printk(KERN_DEBUG "%s(%p, %x, %lx)\n", __func__,
226 227 filep, cmd, arg);
227   - lock_kernel();
  228 + mutex_lock(&mISDN_mutex);
228 229 switch (cmd) {
229 230 case IMADDTIMER:
230 231 if (get_user(tout, (int __user *)arg)) {
... ... @@ -256,7 +257,7 @@
256 257 default:
257 258 ret = -EINVAL;
258 259 }
259   - unlock_kernel();
  260 + mutex_unlock(&mISDN_mutex);
260 261 return ret;
261 262 }
262 263