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>

+216 -190
+4 -3
drivers/block/paride/pg.c
··· 162 162 #include <linux/pg.h> 163 163 #include <linux/device.h> 164 164 #include <linux/sched.h> /* current, TASK_* */ 165 - #include <linux/smp_lock.h> 165 + #include <linux/mutex.h> 166 166 #include <linux/jiffies.h> 167 167 168 168 #include <asm/uaccess.h> ··· 193 193 194 194 #define ATAPI_IDENTIFY 0x12 195 195 196 + static DEFINE_MUTEX(pg_mutex); 196 197 static int pg_open(struct inode *inode, struct file *file); 197 198 static int pg_release(struct inode *inode, struct file *file); 198 199 static ssize_t pg_read(struct file *filp, char __user *buf, ··· 519 518 struct pg *dev = &devices[unit]; 520 519 int ret = 0; 521 520 522 - lock_kernel(); 521 + mutex_lock(&pg_mutex); 523 522 if ((unit >= PG_UNITS) || (!dev->present)) { 524 523 ret = -ENODEV; 525 524 goto out; ··· 548 547 file->private_data = dev; 549 548 550 549 out: 551 - unlock_kernel(); 550 + mutex_unlock(&pg_mutex); 552 551 return ret; 553 552 } 554 553
+10 -9
drivers/block/paride/pt.c
··· 146 146 #include <linux/mtio.h> 147 147 #include <linux/device.h> 148 148 #include <linux/sched.h> /* current, TASK_*, schedule_timeout() */ 149 - #include <linux/smp_lock.h> 149 + #include <linux/mutex.h> 150 150 151 151 #include <asm/uaccess.h> 152 152 ··· 189 189 #define ATAPI_MODE_SENSE 0x1a 190 190 #define ATAPI_LOG_SENSE 0x4d 191 191 192 + static DEFINE_MUTEX(pt_mutex); 192 193 static int pt_open(struct inode *inode, struct file *file); 193 194 static long pt_ioctl(struct file *file, unsigned int cmd, unsigned long arg); 194 195 static int pt_release(struct inode *inode, struct file *file); ··· 651 650 struct pt_unit *tape = pt + unit; 652 651 int err; 653 652 654 - lock_kernel(); 653 + mutex_lock(&pt_mutex); 655 654 if (unit >= PT_UNITS || (!tape->present)) { 656 - unlock_kernel(); 655 + mutex_unlock(&pt_mutex); 657 656 return -ENODEV; 658 657 } 659 658 ··· 682 681 } 683 682 684 683 file->private_data = tape; 685 - unlock_kernel(); 684 + mutex_unlock(&pt_mutex); 686 685 return 0; 687 686 688 687 out: 689 688 atomic_inc(&tape->available); 690 - unlock_kernel(); 689 + mutex_unlock(&pt_mutex); 691 690 return err; 692 691 } 693 692 ··· 705 704 switch (mtop.mt_op) { 706 705 707 706 case MTREW: 708 - lock_kernel(); 707 + mutex_lock(&pt_mutex); 709 708 pt_rewind(tape); 710 - unlock_kernel(); 709 + mutex_unlock(&pt_mutex); 711 710 return 0; 712 711 713 712 case MTWEOF: 714 - lock_kernel(); 713 + mutex_lock(&pt_mutex); 715 714 pt_write_fm(tape); 716 - unlock_kernel(); 715 + mutex_unlock(&pt_mutex); 717 716 return 0; 718 717 719 718 default:
+6 -5
drivers/char/apm-emulation.c
··· 13 13 #include <linux/module.h> 14 14 #include <linux/poll.h> 15 15 #include <linux/slab.h> 16 - #include <linux/smp_lock.h> 16 + #include <linux/mutex.h> 17 17 #include <linux/proc_fs.h> 18 18 #include <linux/seq_file.h> 19 19 #include <linux/miscdevice.h> ··· 126 126 /* 127 127 * Local variables 128 128 */ 129 + static DEFINE_MUTEX(apm_mutex); 129 130 static atomic_t suspend_acks_pending = ATOMIC_INIT(0); 130 131 static atomic_t userspace_notification_inhibit = ATOMIC_INIT(0); 131 132 static int apm_disabled; ··· 275 274 if (!as->suser || !as->writer) 276 275 return -EPERM; 277 276 278 - lock_kernel(); 277 + mutex_lock(&apm_mutex); 279 278 switch (cmd) { 280 279 case APM_IOC_SUSPEND: 281 280 mutex_lock(&state_lock); ··· 336 335 mutex_unlock(&state_lock); 337 336 break; 338 337 } 339 - unlock_kernel(); 338 + mutex_unlock(&apm_mutex); 340 339 341 340 return err; 342 341 } ··· 371 370 { 372 371 struct apm_user *as; 373 372 374 - lock_kernel(); 373 + mutex_lock(&apm_mutex); 375 374 as = kzalloc(sizeof(*as), GFP_KERNEL); 376 375 if (as) { 377 376 /* ··· 391 390 392 391 filp->private_data = as; 393 392 } 394 - unlock_kernel(); 393 + mutex_unlock(&apm_mutex); 395 394 396 395 return as ? 0 : -ENOMEM; 397 396 }
+5 -4
drivers/char/applicom.c
··· 26 26 #include <linux/sched.h> 27 27 #include <linux/slab.h> 28 28 #include <linux/errno.h> 29 - #include <linux/smp_lock.h> 29 + #include <linux/mutex.h> 30 30 #include <linux/miscdevice.h> 31 31 #include <linux/pci.h> 32 32 #include <linux/wait.h> ··· 60 60 #define PCI_DEVICE_ID_APPLICOM_PCI2000PFB 0x0003 61 61 #endif 62 62 63 + static DEFINE_MUTEX(ac_mutex); 63 64 static char *applicom_pci_devnames[] = { 64 65 "PCI board", 65 66 "PCI2000IBS / PCI2000CAN", ··· 708 707 if (IS_ERR(adgl)) 709 708 return PTR_ERR(adgl); 710 709 711 - lock_kernel(); 710 + mutex_lock(&ac_mutex); 712 711 IndexCard = adgl->num_card-1; 713 712 714 713 if(cmd != 6 && ((IndexCard >= MAX_BOARD) || !apbs[IndexCard].RamIO)) { ··· 718 717 warncount--; 719 718 } 720 719 kfree(adgl); 721 - unlock_kernel(); 720 + mutex_unlock(&ac_mutex); 722 721 return -EINVAL; 723 722 } 724 723 ··· 836 835 } 837 836 Dummy = readb(apbs[IndexCard].RamIO + VERS); 838 837 kfree(adgl); 839 - unlock_kernel(); 838 + mutex_unlock(&ac_mutex); 840 839 return 0; 841 840 } 842 841
+8 -7
drivers/char/ds1302.c
··· 20 20 #include <linux/miscdevice.h> 21 21 #include <linux/delay.h> 22 22 #include <linux/bcd.h> 23 - #include <linux/smp_lock.h> 23 + #include <linux/mutex.h> 24 24 #include <linux/uaccess.h> 25 25 #include <linux/io.h> 26 26 ··· 32 32 33 33 #define RTC_MAJOR_NR 121 /* local major, change later */ 34 34 35 + static DEFINE_MUTEX(rtc_mutex); 35 36 static const char ds1302_name[] = "ds1302"; 36 37 37 38 /* Send 8 bits. */ ··· 165 164 struct rtc_time rtc_tm; 166 165 167 166 memset(&rtc_tm, 0, sizeof (struct rtc_time)); 168 - lock_kernel(); 167 + mutex_lock(&rtc_mutex); 169 168 get_rtc_time(&rtc_tm); 170 - unlock_kernel(); 169 + mutex_unlock(&rtc_mutex); 171 170 if (copy_to_user((struct rtc_time*)arg, &rtc_tm, sizeof(struct rtc_time))) 172 171 return -EFAULT; 173 172 return 0; ··· 219 218 mon = bin2bcd(mon); 220 219 yrs = bin2bcd(yrs); 221 220 222 - lock_kernel(); 221 + mutex_lock(&rtc_mutex); 223 222 local_irq_save(flags); 224 223 CMOS_WRITE(yrs, RTC_YEAR); 225 224 CMOS_WRITE(mon, RTC_MONTH); ··· 228 227 CMOS_WRITE(min, RTC_MINUTES); 229 228 CMOS_WRITE(sec, RTC_SECONDS); 230 229 local_irq_restore(flags); 231 - unlock_kernel(); 230 + mutex_unlock(&rtc_mutex); 232 231 233 232 /* Notice that at this point, the RTC is updated but 234 233 * the kernel is still running with the old time. ··· 248 247 if(copy_from_user(&tcs_val, (int*)arg, sizeof(int))) 249 248 return -EFAULT; 250 249 251 - lock_kernel(); 250 + mutex_lock(&rtc_mutex); 252 251 tcs_val = RTC_TCR_PATTERN | (tcs_val & 0x0F); 253 252 ds1302_writereg(RTC_TRICKLECHARGER, tcs_val); 254 - unlock_kernel(); 253 + mutex_unlock(&rtc_mutex); 255 254 return 0; 256 255 } 257 256 default:
+4 -4
drivers/char/ds1620.c
··· 8 8 #include <linux/proc_fs.h> 9 9 #include <linux/capability.h> 10 10 #include <linux/init.h> 11 - #include <linux/smp_lock.h> 11 + #include <linux/mutex.h> 12 12 13 13 #include <mach/hardware.h> 14 14 #include <asm/mach-types.h> ··· 34 34 #define CFG_CPU 2 35 35 #define CFG_1SHOT 1 36 36 37 + static DEFINE_MUTEX(ds1620_mutex); 37 38 static const char *fan_state[] = { "off", "on", "on (hardwired)" }; 38 39 39 40 /* ··· 211 210 212 211 static int ds1620_open(struct inode *inode, struct file *file) 213 212 { 214 - cycle_kernel_lock(); 215 213 return nonseekable_open(inode, file); 216 214 } 217 215 ··· 321 321 { 322 322 int ret; 323 323 324 - lock_kernel(); 324 + mutex_lock(&ds1620_mutex); 325 325 ret = ds1620_ioctl(file, cmd, arg); 326 - unlock_kernel(); 326 + mutex_unlock(&ds1620_mutex); 327 327 328 328 return ret; 329 329 }
+14 -13
drivers/char/dsp56k.c
··· 32 32 #include <linux/mm.h> 33 33 #include <linux/init.h> 34 34 #include <linux/device.h> 35 - #include <linux/smp_lock.h> 35 + #include <linux/mutex.h> 36 36 #include <linux/firmware.h> 37 37 #include <linux/platform_device.h> 38 38 #include <linux/uaccess.h> /* For put_user and get_user */ ··· 94 94 } \ 95 95 } 96 96 97 + static DEFINE_MUTEX(dsp56k_mutex); 97 98 static struct dsp56k_device { 98 99 unsigned long in_use; 99 100 long maxio, timeout; ··· 331 330 if (len > DSP56K_MAX_BINARY_LENGTH) { 332 331 return -EINVAL; 333 332 } 334 - lock_kernel(); 333 + mutex_lock(&dsp56k_mutex); 335 334 r = dsp56k_upload(bin, len); 336 - unlock_kernel(); 335 + mutex_unlock(&dsp56k_mutex); 337 336 if (r < 0) { 338 337 return r; 339 338 } ··· 343 342 case DSP56K_SET_TX_WSIZE: 344 343 if (arg > 4 || arg < 1) 345 344 return -EINVAL; 346 - lock_kernel(); 345 + mutex_lock(&dsp56k_mutex); 347 346 dsp56k.tx_wsize = (int) arg; 348 - unlock_kernel(); 347 + mutex_unlock(&dsp56k_mutex); 349 348 break; 350 349 case DSP56K_SET_RX_WSIZE: 351 350 if (arg > 4 || arg < 1) 352 351 return -EINVAL; 353 - lock_kernel(); 352 + mutex_lock(&dsp56k_mutex); 354 353 dsp56k.rx_wsize = (int) arg; 355 - unlock_kernel(); 354 + mutex_unlock(&dsp56k_mutex); 356 355 break; 357 356 case DSP56K_HOST_FLAGS: 358 357 { ··· 364 363 if(get_user(out, &hf->out) < 0) 365 364 return -EFAULT; 366 365 367 - lock_kernel(); 366 + mutex_lock(&dsp56k_mutex); 368 367 if ((dir & 0x1) && (out & 0x1)) 369 368 dsp56k_host_interface.icr |= DSP56K_ICR_HF0; 370 369 else if (dir & 0x1) ··· 379 378 if (dsp56k_host_interface.icr & DSP56K_ICR_HF1) status |= 0x2; 380 379 if (dsp56k_host_interface.isr & DSP56K_ISR_HF2) status |= 0x4; 381 380 if (dsp56k_host_interface.isr & DSP56K_ISR_HF3) status |= 0x8; 382 - unlock_kernel(); 381 + mutex_unlock(&dsp56k_mutex); 383 382 return put_user(status, &hf->status); 384 383 } 385 384 case DSP56K_HOST_CMD: 386 385 if (arg > 31 || arg < 0) 387 386 return -EINVAL; 388 - lock_kernel(); 387 + mutex_lock(&dsp56k_mutex); 389 388 dsp56k_host_interface.cvr = (u_char)((arg & DSP56K_CVR_HV_MASK) | 390 389 DSP56K_CVR_HC); 391 - unlock_kernel(); 390 + mutex_unlock(&dsp56k_mutex); 392 391 break; 393 392 default: 394 393 return -EINVAL; ··· 428 427 int dev = iminor(inode) & 0x0f; 429 428 int ret = 0; 430 429 431 - lock_kernel(); 430 + mutex_lock(&dsp56k_mutex); 432 431 switch(dev) 433 432 { 434 433 case DSP56K_DEV_56001: ··· 455 454 ret = -ENODEV; 456 455 } 457 456 out: 458 - unlock_kernel(); 457 + mutex_unlock(&dsp56k_mutex); 459 458 return ret; 460 459 } 461 460
+4 -4
drivers/char/dtlk.c
··· 57 57 #include <linux/ioport.h> /* for request_region */ 58 58 #include <linux/delay.h> /* for loops_per_jiffy */ 59 59 #include <linux/sched.h> 60 - #include <linux/smp_lock.h> /* cycle_kernel_lock() */ 60 + #include <linux/mutex.h> 61 61 #include <asm/io.h> /* for inb_p, outb_p, inb, outb, etc. */ 62 62 #include <asm/uaccess.h> /* for get_user, etc. */ 63 63 #include <linux/wait.h> /* for wait_queue */ ··· 73 73 #define TRACE_RET ((void) 0) 74 74 #endif /* TRACING */ 75 75 76 + static DEFINE_MUTEX(dtlk_mutex); 76 77 static void dtlk_timer_tick(unsigned long data); 77 78 78 79 static int dtlk_major; ··· 276 275 switch (cmd) { 277 276 278 277 case DTLK_INTERROGATE: 279 - lock_kernel(); 278 + mutex_lock(&dtlk_mutex); 280 279 sp = dtlk_interrogate(); 281 - unlock_kernel(); 280 + mutex_unlock(&dtlk_mutex); 282 281 if (copy_to_user(argp, sp, sizeof(struct dtlk_settings))) 283 282 return -EINVAL; 284 283 return 0; ··· 297 296 { 298 297 TRACE_TEXT("(dtlk_open"); 299 298 300 - cycle_kernel_lock(); 301 299 nonseekable_open(inode, file); 302 300 switch (iminor(inode)) { 303 301 case DTLK_MINOR:
+4 -3
drivers/char/generic_nvram.c
··· 19 19 #include <linux/miscdevice.h> 20 20 #include <linux/fcntl.h> 21 21 #include <linux/init.h> 22 - #include <linux/smp_lock.h> 22 + #include <linux/mutex.h> 23 23 #include <asm/uaccess.h> 24 24 #include <asm/nvram.h> 25 25 #ifdef CONFIG_PPC_PMAC ··· 28 28 29 29 #define NVRAM_SIZE 8192 30 30 31 + static DEFINE_MUTEX(nvram_mutex); 31 32 static ssize_t nvram_len; 32 33 33 34 static loff_t nvram_llseek(struct file *file, loff_t offset, int origin) ··· 121 120 { 122 121 int ret; 123 122 124 - lock_kernel(); 123 + mutex_lock(&nvram_mutex); 125 124 ret = nvram_ioctl(file, cmd, arg); 126 - unlock_kernel(); 125 + mutex_unlock(&nvram_mutex); 127 126 128 127 return ret; 129 128 }
+7 -6
drivers/char/genrtc.c
··· 52 52 #include <linux/init.h> 53 53 #include <linux/poll.h> 54 54 #include <linux/proc_fs.h> 55 - #include <linux/smp_lock.h> 55 + #include <linux/mutex.h> 56 56 #include <linux/workqueue.h> 57 57 58 58 #include <asm/uaccess.h> ··· 66 66 * ioctls. 67 67 */ 68 68 69 + static DEFINE_MUTEX(gen_rtc_mutex); 69 70 static DECLARE_WAIT_QUEUE_HEAD(gen_rtc_wait); 70 71 71 72 /* ··· 338 337 { 339 338 int ret; 340 339 341 - lock_kernel(); 340 + mutex_lock(&gen_rtc_mutex); 342 341 ret = gen_rtc_ioctl(file, cmd, arg); 343 - unlock_kernel(); 342 + mutex_unlock(&gen_rtc_mutex); 344 343 345 344 return ret; 346 345 } ··· 353 352 354 353 static int gen_rtc_open(struct inode *inode, struct file *file) 355 354 { 356 - lock_kernel(); 355 + mutex_lock(&gen_rtc_mutex); 357 356 if (gen_rtc_status & RTC_IS_OPEN) { 358 - unlock_kernel(); 357 + mutex_unlock(&gen_rtc_mutex); 359 358 return -EBUSY; 360 359 } 361 360 362 361 gen_rtc_status |= RTC_IS_OPEN; 363 362 gen_rtc_irq_data = 0; 364 363 irq_active = 0; 365 - unlock_kernel(); 364 + mutex_unlock(&gen_rtc_mutex); 366 365 367 366 return 0; 368 367 }
+4 -3
drivers/char/i8k.c
··· 23 23 #include <linux/seq_file.h> 24 24 #include <linux/dmi.h> 25 25 #include <linux/capability.h> 26 - #include <linux/smp_lock.h> 26 + #include <linux/mutex.h> 27 27 #include <asm/uaccess.h> 28 28 #include <asm/io.h> 29 29 ··· 56 56 57 57 #define I8K_TEMPERATURE_BUG 1 58 58 59 + static DEFINE_MUTEX(i8k_mutex); 59 60 static char bios_version[4]; 60 61 61 62 MODULE_AUTHOR("Massimo Dal Zotto (dz@debian.org)"); ··· 400 399 { 401 400 long ret; 402 401 403 - lock_kernel(); 402 + mutex_lock(&i8k_mutex); 404 403 ret = i8k_ioctl_unlocked(fp, cmd, arg); 405 - unlock_kernel(); 404 + mutex_unlock(&i8k_mutex); 406 405 407 406 return ret; 408 407 }
+4 -4
drivers/char/ip2/ip2main.c
··· 98 98 #include <linux/major.h> 99 99 #include <linux/wait.h> 100 100 #include <linux/device.h> 101 - #include <linux/smp_lock.h> 101 + #include <linux/mutex.h> 102 102 #include <linux/firmware.h> 103 103 #include <linux/platform_device.h> 104 104 ··· 138 138 #include <linux/proc_fs.h> 139 139 #include <linux/seq_file.h> 140 140 141 + static DEFINE_MUTEX(ip2_mutex); 141 142 static const struct file_operations ip2mem_proc_fops; 142 143 static const struct file_operations ip2_proc_fops; 143 144 ··· 2898 2897 printk (KERN_DEBUG "IP2IPL: ioctl cmd %d, arg %ld\n", cmd, arg ); 2899 2898 #endif 2900 2899 2901 - lock_kernel(); 2900 + mutex_lock(&ip2_mutex); 2902 2901 2903 2902 switch ( iplminor ) { 2904 2903 case 0: // IPL device ··· 2962 2961 rc = -ENODEV; 2963 2962 break; 2964 2963 } 2965 - unlock_kernel(); 2964 + mutex_unlock(&ip2_mutex); 2966 2965 return rc; 2967 2966 } 2968 2967 ··· 2983 2982 #ifdef IP2DEBUG_IPL 2984 2983 printk (KERN_DEBUG "IP2IPL: open\n" ); 2985 2984 #endif 2986 - cycle_kernel_lock(); 2987 2985 return 0; 2988 2986 } 2989 2987
+8 -7
drivers/char/lp.c
··· 126 126 #include <linux/device.h> 127 127 #include <linux/wait.h> 128 128 #include <linux/jiffies.h> 129 - #include <linux/smp_lock.h> 129 + #include <linux/mutex.h> 130 130 #include <linux/compat.h> 131 131 132 132 #include <linux/parport.h> ··· 140 140 /* if you have more than 8 printers, remember to increase LP_NO */ 141 141 #define LP_NO 8 142 142 143 + static DEFINE_MUTEX(lp_mutex); 143 144 static struct lp_struct lp_table[LP_NO]; 144 145 145 146 static unsigned int lp_count = 0; ··· 494 493 unsigned int minor = iminor(inode); 495 494 int ret = 0; 496 495 497 - lock_kernel(); 496 + mutex_lock(&lp_mutex); 498 497 if (minor >= LP_NO) { 499 498 ret = -ENXIO; 500 499 goto out; ··· 555 554 lp_release_parport (&lp_table[minor]); 556 555 lp_table[minor].current_mode = IEEE1284_MODE_COMPAT; 557 556 out: 558 - unlock_kernel(); 557 + mutex_unlock(&lp_mutex); 559 558 return ret; 560 559 } 561 560 ··· 681 680 int ret; 682 681 683 682 minor = iminor(file->f_path.dentry->d_inode); 684 - lock_kernel(); 683 + mutex_lock(&lp_mutex); 685 684 switch (cmd) { 686 685 case LPSETTIMEOUT: 687 686 if (copy_from_user(&par_timeout, (void __user *)arg, ··· 695 694 ret = lp_do_ioctl(minor, cmd, arg, (void __user *)arg); 696 695 break; 697 696 } 698 - unlock_kernel(); 697 + mutex_unlock(&lp_mutex); 699 698 700 699 return ret; 701 700 } ··· 710 709 int ret; 711 710 712 711 minor = iminor(file->f_path.dentry->d_inode); 713 - lock_kernel(); 712 + mutex_lock(&lp_mutex); 714 713 switch (cmd) { 715 714 case LPSETTIMEOUT: 716 715 tc = compat_ptr(arg); ··· 731 730 ret = lp_do_ioctl(minor, cmd, arg, compat_ptr(arg)); 732 731 break; 733 732 } 734 - unlock_kernel(); 733 + mutex_unlock(&lp_mutex); 735 734 736 735 return ret; 737 736 }
+4 -4
drivers/char/mbcs.c
··· 25 25 #include <linux/mm.h> 26 26 #include <linux/uio.h> 27 27 #include <linux/mutex.h> 28 - #include <linux/smp_lock.h> 29 28 #include <linux/slab.h> 30 29 #include <asm/io.h> 31 30 #include <asm/uaccess.h> ··· 41 42 #else 42 43 #define DBG(fmt...) 43 44 #endif 45 + static DEFINE_MUTEX(mbcs_mutex); 44 46 static int mbcs_major; 45 47 46 48 static LIST_HEAD(soft_list); ··· 385 385 struct mbcs_soft *soft; 386 386 int minor; 387 387 388 - lock_kernel(); 388 + mutex_lock(&mbcs_mutex); 389 389 minor = iminor(ip); 390 390 391 391 /* Nothing protects access to this list... */ 392 392 list_for_each_entry(soft, &soft_list, list) { 393 393 if (soft->nasid == minor) { 394 394 fp->private_data = soft->cxdev; 395 - unlock_kernel(); 395 + mutex_unlock(&mbcs_mutex); 396 396 return 0; 397 397 } 398 398 } 399 399 400 - unlock_kernel(); 400 + mutex_unlock(&mbcs_mutex); 401 401 return -ENODEV; 402 402 } 403 403
+4 -3
drivers/char/mmtimer.c
··· 32 32 #include <linux/interrupt.h> 33 33 #include <linux/time.h> 34 34 #include <linux/math64.h> 35 - #include <linux/smp_lock.h> 35 + #include <linux/mutex.h> 36 36 #include <linux/slab.h> 37 37 38 38 #include <asm/uaccess.h> ··· 59 59 60 60 #define rtc_time() (*RTC_COUNTER_ADDR) 61 61 62 + static DEFINE_MUTEX(mmtimer_mutex); 62 63 static long mmtimer_ioctl(struct file *file, unsigned int cmd, 63 64 unsigned long arg); 64 65 static int mmtimer_mmap(struct file *file, struct vm_area_struct *vma); ··· 372 371 { 373 372 int ret = 0; 374 373 375 - lock_kernel(); 374 + mutex_lock(&mmtimer_mutex); 376 375 377 376 switch (cmd) { 378 377 case MMTIMER_GETOFFSET: /* offset of the counter */ ··· 415 414 ret = -ENOTTY; 416 415 break; 417 416 } 418 - unlock_kernel(); 417 + mutex_unlock(&mmtimer_mutex); 419 418 return ret; 420 419 } 421 420
+22 -22
drivers/char/mwave/mwavedd.c
··· 56 56 #include <linux/serial.h> 57 57 #include <linux/sched.h> 58 58 #include <linux/spinlock.h> 59 - #include <linux/smp_lock.h> 59 + #include <linux/mutex.h> 60 60 #include <linux/delay.h> 61 61 #include <linux/serial_8250.h> 62 62 #include "smapi.h" ··· 73 73 * checks are made against other devices (ie. superio) for conflicts. 74 74 * We'll depend on users using the tpctl utility to do that for now 75 75 */ 76 + static DEFINE_MUTEX(mwave_mutex); 76 77 int mwave_debug = 0; 77 78 int mwave_3780i_irq = 0; 78 79 int mwave_3780i_io = 0; ··· 102 101 PRINTK_2(TRACE_MWAVE, 103 102 "mwavedd::mwave_open, exit return retval %x\n", retval); 104 103 105 - cycle_kernel_lock(); 106 104 return retval; 107 105 } 108 106 ··· 136 136 PRINTK_1(TRACE_MWAVE, 137 137 "mwavedd::mwave_ioctl, IOCTL_MW_RESET" 138 138 " calling tp3780I_ResetDSP\n"); 139 - lock_kernel(); 139 + mutex_lock(&mwave_mutex); 140 140 retval = tp3780I_ResetDSP(&pDrvData->rBDData); 141 - unlock_kernel(); 141 + mutex_unlock(&mwave_mutex); 142 142 PRINTK_2(TRACE_MWAVE, 143 143 "mwavedd::mwave_ioctl, IOCTL_MW_RESET" 144 144 " retval %x from tp3780I_ResetDSP\n", ··· 149 149 PRINTK_1(TRACE_MWAVE, 150 150 "mwavedd::mwave_ioctl, IOCTL_MW_RUN" 151 151 " calling tp3780I_StartDSP\n"); 152 - lock_kernel(); 152 + mutex_lock(&mwave_mutex); 153 153 retval = tp3780I_StartDSP(&pDrvData->rBDData); 154 - unlock_kernel(); 154 + mutex_unlock(&mwave_mutex); 155 155 PRINTK_2(TRACE_MWAVE, 156 156 "mwavedd::mwave_ioctl, IOCTL_MW_RUN" 157 157 " retval %x from tp3780I_StartDSP\n", ··· 165 165 "mwavedd::mwave_ioctl," 166 166 " IOCTL_MW_DSP_ABILITIES calling" 167 167 " tp3780I_QueryAbilities\n"); 168 - lock_kernel(); 168 + mutex_lock(&mwave_mutex); 169 169 retval = tp3780I_QueryAbilities(&pDrvData->rBDData, 170 170 &rAbilities); 171 - unlock_kernel(); 171 + mutex_unlock(&mwave_mutex); 172 172 PRINTK_2(TRACE_MWAVE, 173 173 "mwavedd::mwave_ioctl, IOCTL_MW_DSP_ABILITIES" 174 174 " retval %x from tp3780I_QueryAbilities\n", ··· 199 199 "mwavedd::mwave_ioctl IOCTL_MW_READ_DATA," 200 200 " size %lx, ioarg %lx pusBuffer %p\n", 201 201 rReadData.ulDataLength, ioarg, pusBuffer); 202 - lock_kernel(); 202 + mutex_lock(&mwave_mutex); 203 203 retval = tp3780I_ReadWriteDspDStore(&pDrvData->rBDData, 204 204 iocmd, 205 205 pusBuffer, 206 206 rReadData.ulDataLength, 207 207 rReadData.usDspAddress); 208 - unlock_kernel(); 208 + mutex_unlock(&mwave_mutex); 209 209 } 210 210 break; 211 211 ··· 223 223 " size %lx, ioarg %lx pusBuffer %p\n", 224 224 rReadData.ulDataLength / 2, ioarg, 225 225 pusBuffer); 226 - lock_kernel(); 226 + mutex_lock(&mwave_mutex); 227 227 retval = tp3780I_ReadWriteDspDStore(&pDrvData->rBDData, 228 228 iocmd, pusBuffer, 229 229 rReadData.ulDataLength / 2, 230 230 rReadData.usDspAddress); 231 - unlock_kernel(); 231 + mutex_unlock(&mwave_mutex); 232 232 } 233 233 break; 234 234 ··· 246 246 " size %lx, ioarg %lx pusBuffer %p\n", 247 247 rWriteData.ulDataLength, ioarg, 248 248 pusBuffer); 249 - lock_kernel(); 249 + mutex_lock(&mwave_mutex); 250 250 retval = tp3780I_ReadWriteDspDStore(&pDrvData->rBDData, 251 251 iocmd, pusBuffer, 252 252 rWriteData.ulDataLength, 253 253 rWriteData.usDspAddress); 254 - unlock_kernel(); 254 + mutex_unlock(&mwave_mutex); 255 255 } 256 256 break; 257 257 ··· 269 269 " size %lx, ioarg %lx pusBuffer %p\n", 270 270 rWriteData.ulDataLength, ioarg, 271 271 pusBuffer); 272 - lock_kernel(); 272 + mutex_lock(&mwave_mutex); 273 273 retval = tp3780I_ReadWriteDspIStore(&pDrvData->rBDData, 274 274 iocmd, pusBuffer, 275 275 rWriteData.ulDataLength, 276 276 rWriteData.usDspAddress); 277 - unlock_kernel(); 277 + mutex_unlock(&mwave_mutex); 278 278 } 279 279 break; 280 280 ··· 295 295 ipcnum, 296 296 pDrvData->IPCs[ipcnum].usIntCount); 297 297 298 - lock_kernel(); 298 + mutex_lock(&mwave_mutex); 299 299 pDrvData->IPCs[ipcnum].bIsHere = FALSE; 300 300 pDrvData->IPCs[ipcnum].bIsEnabled = TRUE; 301 - unlock_kernel(); 301 + mutex_unlock(&mwave_mutex); 302 302 303 303 PRINTK_2(TRACE_MWAVE, 304 304 "mwavedd::mwave_ioctl IOCTL_MW_REGISTER_IPC" ··· 323 323 ipcnum, 324 324 pDrvData->IPCs[ipcnum].usIntCount); 325 325 326 - lock_kernel(); 326 + mutex_lock(&mwave_mutex); 327 327 if (pDrvData->IPCs[ipcnum].bIsEnabled == TRUE) { 328 328 DECLARE_WAITQUEUE(wait, current); 329 329 ··· 364 364 " processing\n", 365 365 ipcnum); 366 366 } 367 - unlock_kernel(); 367 + mutex_unlock(&mwave_mutex); 368 368 } 369 369 break; 370 370 ··· 383 383 ipcnum); 384 384 return -EINVAL; 385 385 } 386 - lock_kernel(); 386 + mutex_lock(&mwave_mutex); 387 387 if (pDrvData->IPCs[ipcnum].bIsEnabled == TRUE) { 388 388 pDrvData->IPCs[ipcnum].bIsEnabled = FALSE; 389 389 if (pDrvData->IPCs[ipcnum].bIsHere == TRUE) { 390 390 wake_up_interruptible(&pDrvData->IPCs[ipcnum].ipc_wait_queue); 391 391 } 392 392 } 393 - unlock_kernel(); 393 + mutex_unlock(&mwave_mutex); 394 394 } 395 395 break; 396 396
+6 -5
drivers/char/nvram.c
··· 109 109 #include <linux/spinlock.h> 110 110 #include <linux/io.h> 111 111 #include <linux/uaccess.h> 112 - #include <linux/smp_lock.h> 112 + #include <linux/mutex.h> 113 113 114 114 #include <asm/system.h> 115 115 116 + static DEFINE_MUTEX(nvram_mutex); 116 117 static DEFINE_SPINLOCK(nvram_state_lock); 117 118 static int nvram_open_cnt; /* #times opened */ 118 119 static int nvram_open_mode; /* special open modes */ ··· 309 308 if (!capable(CAP_SYS_ADMIN)) 310 309 return -EACCES; 311 310 312 - lock_kernel(); 311 + mutex_lock(&nvram_mutex); 313 312 spin_lock_irq(&rtc_lock); 314 313 315 314 for (i = 0; i < NVRAM_BYTES; ++i) ··· 317 316 __nvram_set_checksum(); 318 317 319 318 spin_unlock_irq(&rtc_lock); 320 - unlock_kernel(); 319 + mutex_unlock(&nvram_mutex); 321 320 return 0; 322 321 323 322 case NVRAM_SETCKS: ··· 326 325 if (!capable(CAP_SYS_ADMIN)) 327 326 return -EACCES; 328 327 329 - lock_kernel(); 328 + mutex_lock(&nvram_mutex); 330 329 spin_lock_irq(&rtc_lock); 331 330 __nvram_set_checksum(); 332 331 spin_unlock_irq(&rtc_lock); 333 - unlock_kernel(); 332 + mutex_unlock(&nvram_mutex); 334 333 return 0; 335 334 336 335 default:
+6 -6
drivers/char/nwflash.c
··· 25 25 #include <linux/spinlock.h> 26 26 #include <linux/rwsem.h> 27 27 #include <linux/init.h> 28 - #include <linux/smp_lock.h> 29 28 #include <linux/mutex.h> 30 29 #include <linux/jiffies.h> 31 30 ··· 40 41 41 42 #define NWFLASH_VERSION "6.4" 42 43 44 + static DEFINE_MUTEX(flash_mutex); 43 45 static void kick_open(void); 44 46 static int get_flash_id(void); 45 47 static int erase_block(int nBlock); ··· 96 96 97 97 static long flash_ioctl(struct file *filep, unsigned int cmd, unsigned long arg) 98 98 { 99 - lock_kernel(); 99 + mutex_lock(&flash_mutex); 100 100 switch (cmd) { 101 101 case CMD_WRITE_DISABLE: 102 102 gbWriteBase64Enable = 0; ··· 114 114 default: 115 115 gbWriteBase64Enable = 0; 116 116 gbWriteEnable = 0; 117 - unlock_kernel(); 117 + mutex_unlock(&flash_mutex); 118 118 return -EINVAL; 119 119 } 120 - unlock_kernel(); 120 + mutex_unlock(&flash_mutex); 121 121 return 0; 122 122 } 123 123 ··· 282 282 { 283 283 loff_t ret; 284 284 285 - lock_kernel(); 285 + mutex_lock(&flash_mutex); 286 286 if (flashdebug) 287 287 printk(KERN_DEBUG "flash_llseek: offset=0x%X, orig=0x%X.\n", 288 288 (unsigned int) offset, orig); ··· 317 317 default: 318 318 ret = -EINVAL; 319 319 } 320 - unlock_kernel(); 320 + mutex_unlock(&flash_mutex); 321 321 return ret; 322 322 } 323 323
+6 -5
drivers/char/pcmcia/cm4000_cs.c
··· 30 30 #include <linux/fs.h> 31 31 #include <linux/delay.h> 32 32 #include <linux/bitrev.h> 33 - #include <linux/smp_lock.h> 33 + #include <linux/mutex.h> 34 34 #include <linux/uaccess.h> 35 35 #include <linux/io.h> 36 36 ··· 55 55 __func__ , ## args); \ 56 56 } while (0) 57 57 58 + static DEFINE_MUTEX(cmm_mutex); 58 59 static char *version = "cm4000_cs.c v2.4.0gm6 - All bugs added by Harald Welte"; 59 60 60 61 #define T_1SEC (HZ) ··· 1419 1418 iminor(inode), ioctl_names[_IOC_NR(cmd)]); 1420 1419 #endif 1421 1420 1422 - lock_kernel(); 1421 + mutex_lock(&cmm_mutex); 1423 1422 rc = -ENODEV; 1424 1423 link = dev_table[iminor(inode)]; 1425 1424 if (!pcmcia_dev_present(link)) { ··· 1627 1626 rc = -ENOTTY; 1628 1627 } 1629 1628 out: 1630 - unlock_kernel(); 1629 + mutex_unlock(&cmm_mutex); 1631 1630 return rc; 1632 1631 } 1633 1632 ··· 1641 1640 if (minor >= CM4000_MAX_DEV) 1642 1641 return -ENODEV; 1643 1642 1644 - lock_kernel(); 1643 + mutex_lock(&cmm_mutex); 1645 1644 link = dev_table[minor]; 1646 1645 if (link == NULL || !pcmcia_dev_present(link)) { 1647 1646 ret = -ENODEV; ··· 1686 1685 DEBUGP(2, dev, "<- cmm_open\n"); 1687 1686 ret = nonseekable_open(inode, filp); 1688 1687 out: 1689 - unlock_kernel(); 1688 + mutex_unlock(&cmm_mutex); 1690 1689 return ret; 1691 1690 } 1692 1691
+4 -3
drivers/char/pcmcia/cm4040_cs.c
··· 24 24 #include <linux/fs.h> 25 25 #include <linux/delay.h> 26 26 #include <linux/poll.h> 27 - #include <linux/smp_lock.h> 27 + #include <linux/mutex.h> 28 28 #include <linux/wait.h> 29 29 #include <asm/uaccess.h> 30 30 #include <asm/io.h> ··· 49 49 __func__ , ## args); \ 50 50 } while (0) 51 51 52 + static DEFINE_MUTEX(cm4040_mutex); 52 53 static char *version = 53 54 "OMNIKEY CardMan 4040 v1.1.0gm5 - All bugs added by Harald Welte"; 54 55 ··· 445 444 if (minor >= CM_MAX_DEV) 446 445 return -ENODEV; 447 446 448 - lock_kernel(); 447 + mutex_lock(&cm4040_mutex); 449 448 link = dev_table[minor]; 450 449 if (link == NULL || !pcmcia_dev_present(link)) { 451 450 ret = -ENODEV; ··· 474 473 DEBUGP(2, dev, "<- cm4040_open (successfully)\n"); 475 474 ret = nonseekable_open(inode, filp); 476 475 out: 477 - unlock_kernel(); 476 + mutex_unlock(&cm4040_mutex); 478 477 return ret; 479 478 } 480 479
+4 -4
drivers/char/ppdev.c
··· 67 67 #include <linux/slab.h> 68 68 #include <linux/major.h> 69 69 #include <linux/ppdev.h> 70 - #include <linux/smp_lock.h> 70 + #include <linux/mutex.h> 71 71 #include <linux/uaccess.h> 72 72 73 73 #define PP_VERSION "ppdev: user-space parallel port driver" ··· 97 97 /* ROUND_UP macro from fs/select.c */ 98 98 #define ROUND_UP(x,y) (((x)+(y)-1)/(y)) 99 99 100 + static DEFINE_MUTEX(pp_do_mutex); 100 101 static inline void pp_enable_irq (struct pp_struct *pp) 101 102 { 102 103 struct parport *port = pp->pdev->port; ··· 631 630 static long pp_ioctl(struct file *file, unsigned int cmd, unsigned long arg) 632 631 { 633 632 long ret; 634 - lock_kernel(); 633 + mutex_lock(&pp_do_mutex); 635 634 ret = pp_do_ioctl(file, cmd, arg); 636 - unlock_kernel(); 635 + mutex_unlock(&pp_do_mutex); 637 636 return ret; 638 637 } 639 638 ··· 642 641 unsigned int minor = iminor(inode); 643 642 struct pp_struct *pp; 644 643 645 - cycle_kernel_lock(); 646 644 if (minor >= PARPORT_MAX) 647 645 return -ENXIO; 648 646
+4 -3
drivers/char/rio/rio_linux.c
··· 44 44 #include <linux/delay.h> 45 45 #include <linux/pci.h> 46 46 #include <linux/slab.h> 47 - #include <linux/smp_lock.h> 47 + #include <linux/mutex.h> 48 48 #include <linux/miscdevice.h> 49 49 #include <linux/init.h> 50 50 ··· 122 122 123 123 124 124 /* These constants are derived from SCO Source */ 125 + static DEFINE_MUTEX(rio_fw_mutex); 125 126 static struct Conf 126 127 RIOConf = { 127 128 /* locator */ "RIO Config here", ··· 567 566 func_enter(); 568 567 569 568 /* The "dev" argument isn't used. */ 570 - lock_kernel(); 569 + mutex_lock(&rio_fw_mutex); 571 570 rc = riocontrol(p, 0, cmd, arg, capable(CAP_SYS_ADMIN)); 572 - unlock_kernel(); 571 + mutex_unlock(&rio_fw_mutex); 573 572 574 573 func_exit(); 575 574 return rc;
+5 -4
drivers/char/snsc.c
··· 21 21 #include <linux/poll.h> 22 22 #include <linux/module.h> 23 23 #include <linux/slab.h> 24 - #include <linux/smp_lock.h> 24 + #include <linux/mutex.h> 25 25 #include <asm/sn/io.h> 26 26 #include <asm/sn/sn_sal.h> 27 27 #include <asm/sn/module.h> ··· 34 34 #define SCDRV_BUFSZ 2048 35 35 #define SCDRV_TIMEOUT 1000 36 36 37 + static DEFINE_MUTEX(scdrv_mutex); 37 38 static irqreturn_t 38 39 scdrv_interrupt(int irq, void *subch_data) 39 40 { ··· 106 105 file->private_data = sd; 107 106 108 107 /* hook this subchannel up to the system controller interrupt */ 109 - lock_kernel(); 108 + mutex_lock(&scdrv_mutex); 110 109 rv = request_irq(SGI_UART_VECTOR, scdrv_interrupt, 111 110 IRQF_SHARED | IRQF_DISABLED, 112 111 SYSCTL_BASENAME, sd); ··· 114 113 ia64_sn_irtr_close(sd->sd_nasid, sd->sd_subch); 115 114 kfree(sd); 116 115 printk("%s: irq request failed (%d)\n", __func__, rv); 117 - unlock_kernel(); 116 + mutex_unlock(&scdrv_mutex); 118 117 return -EBUSY; 119 118 } 120 - unlock_kernel(); 119 + mutex_unlock(&scdrv_mutex); 121 120 return 0; 122 121 } 123 122
+5 -4
drivers/char/toshiba.c
··· 68 68 #include <linux/stat.h> 69 69 #include <linux/proc_fs.h> 70 70 #include <linux/seq_file.h> 71 - #include <linux/smp_lock.h> 71 + #include <linux/mutex.h> 72 72 #include <linux/toshiba.h> 73 73 74 74 #define TOSH_MINOR_DEV 181 ··· 78 78 MODULE_DESCRIPTION("Toshiba laptop SMM driver"); 79 79 MODULE_SUPPORTED_DEVICE("toshiba"); 80 80 81 + static DEFINE_MUTEX(tosh_mutex); 81 82 static int tosh_fn; 82 83 module_param_named(fn, tosh_fn, int, 0); 83 84 MODULE_PARM_DESC(fn, "User specified Fn key detection port"); ··· 275 274 return -EINVAL; 276 275 277 276 /* do we need to emulate the fan ? */ 278 - lock_kernel(); 277 + mutex_lock(&tosh_mutex); 279 278 if (tosh_fan==1) { 280 279 if (((ax==0xf300) || (ax==0xf400)) && (bx==0x0004)) { 281 280 err = tosh_emulate_fan(&regs); 282 - unlock_kernel(); 281 + mutex_unlock(&tosh_mutex); 283 282 break; 284 283 } 285 284 } 286 285 err = tosh_smm(&regs); 287 - unlock_kernel(); 286 + mutex_unlock(&tosh_mutex); 288 287 break; 289 288 default: 290 289 return -EINVAL;
+6 -5
drivers/char/viotape.c
··· 46 46 #include <linux/completion.h> 47 47 #include <linux/proc_fs.h> 48 48 #include <linux/seq_file.h> 49 - #include <linux/smp_lock.h> 49 + #include <linux/mutex.h> 50 50 #include <linux/slab.h> 51 51 52 52 #include <asm/uaccess.h> ··· 64 64 #define VIOTAPE_KERN_WARN KERN_WARNING "viotape: " 65 65 #define VIOTAPE_KERN_INFO KERN_INFO "viotape: " 66 66 67 + static DEFINE_MUTEX(proc_viotape_mutex); 67 68 static int viotape_numdev; 68 69 69 70 /* ··· 685 684 { 686 685 long rc; 687 686 688 - lock_kernel(); 687 + mutex_lock(&proc_viotape_mutex); 689 688 rc = viotap_ioctl(file->f_path.dentry->d_inode, file, cmd, arg); 690 - unlock_kernel(); 689 + mutex_unlock(&proc_viotape_mutex); 691 690 return rc; 692 691 } 693 692 ··· 701 700 if (op == NULL) 702 701 return -ENOMEM; 703 702 704 - lock_kernel(); 703 + mutex_lock(&proc_viotape_mutex); 705 704 get_dev_info(file->f_path.dentry->d_inode, &devi); 706 705 707 706 /* Note: We currently only support one mode! */ ··· 732 731 733 732 free_op: 734 733 free_op_struct(op); 735 - unlock_kernel(); 734 + mutex_unlock(&proc_viotape_mutex); 736 735 return ret; 737 736 } 738 737
+3 -3
drivers/char/xilinx_hwicap/xilinx_hwicap.c
··· 81 81 #include <linux/poll.h> 82 82 #include <linux/proc_fs.h> 83 83 #include <linux/mutex.h> 84 - #include <linux/smp_lock.h> 85 84 #include <linux/sysctl.h> 86 85 #include <linux/fs.h> 87 86 #include <linux/cdev.h> ··· 111 112 #define HWICAP_DEVICES 1 112 113 113 114 /* An array, which is set to true when the device is registered. */ 115 + static DEFINE_MUTEX(hwicap_mutex); 114 116 static bool probed_devices[HWICAP_DEVICES]; 115 117 static struct mutex icap_sem; 116 118 ··· 502 502 struct hwicap_drvdata *drvdata; 503 503 int status; 504 504 505 - lock_kernel(); 505 + mutex_lock(&hwicap_mutex); 506 506 drvdata = container_of(inode->i_cdev, struct hwicap_drvdata, cdev); 507 507 508 508 status = mutex_lock_interruptible(&drvdata->sem); ··· 528 528 error: 529 529 mutex_unlock(&drvdata->sem); 530 530 out: 531 - unlock_kernel(); 531 + mutex_unlock(&hwicap_mutex); 532 532 return status; 533 533 } 534 534
+3 -3
drivers/hwmon/fschmd.c
··· 38 38 #include <linux/i2c.h> 39 39 #include <linux/hwmon.h> 40 40 #include <linux/hwmon-sysfs.h> 41 - #include <linux/smp_lock.h> 42 41 #include <linux/err.h> 43 42 #include <linux/mutex.h> 44 43 #include <linux/sysfs.h> ··· 49 50 #include <linux/kref.h> 50 51 51 52 /* Addresses to scan */ 53 + static DEFINE_MUTEX(watchdog_mutex); 52 54 static const unsigned short normal_i2c[] = { 0x73, I2C_CLIENT_END }; 53 55 54 56 /* Insmod parameters */ ··· 858 858 int i, ret = 0; 859 859 struct fschmd_data *data = filp->private_data; 860 860 861 - lock_kernel(); 861 + mutex_lock(&watchdog_mutex); 862 862 switch (cmd) { 863 863 case WDIOC_GETSUPPORT: 864 864 ident.firmware_version = data->revision; ··· 915 915 default: 916 916 ret = -ENOTTY; 917 917 } 918 - unlock_kernel(); 918 + mutex_unlock(&watchdog_mutex); 919 919 return ret; 920 920 } 921 921
+3 -3
drivers/hwmon/w83793.c
··· 35 35 #include <linux/slab.h> 36 36 #include <linux/i2c.h> 37 37 #include <linux/hwmon.h> 38 - #include <linux/smp_lock.h> 39 38 #include <linux/hwmon-vid.h> 40 39 #include <linux/hwmon-sysfs.h> 41 40 #include <linux/err.h> ··· 51 52 #define WATCHDOG_TIMEOUT 2 /* 2 minute default timeout */ 52 53 53 54 /* Addresses to scan */ 55 + static DEFINE_MUTEX(watchdog_mutex); 54 56 static const unsigned short normal_i2c[] = { 0x2c, 0x2d, 0x2e, 0x2f, 55 57 I2C_CLIENT_END }; 56 58 ··· 1333 1333 int val, ret = 0; 1334 1334 struct w83793_data *data = filp->private_data; 1335 1335 1336 - lock_kernel(); 1336 + mutex_lock(&watchdog_mutex); 1337 1337 switch (cmd) { 1338 1338 case WDIOC_GETSUPPORT: 1339 1339 if (!nowayout) ··· 1387 1387 default: 1388 1388 ret = -ENOTTY; 1389 1389 } 1390 - unlock_kernel(); 1390 + mutex_unlock(&watchdog_mutex); 1391 1391 return ret; 1392 1392 } 1393 1393
+4 -3
drivers/input/misc/hp_sdc_rtc.c
··· 43 43 #include <linux/proc_fs.h> 44 44 #include <linux/poll.h> 45 45 #include <linux/rtc.h> 46 - #include <linux/smp_lock.h> 46 + #include <linux/mutex.h> 47 47 #include <linux/semaphore.h> 48 48 49 49 MODULE_AUTHOR("Brian S. Julin <bri@calyx.com>"); ··· 52 52 53 53 #define RTC_VERSION "1.10d" 54 54 55 + static DEFINE_MUTEX(hp_sdc_rtc_mutex); 55 56 static unsigned long epoch = 2000; 56 57 57 58 static struct semaphore i8042tregs; ··· 666 665 { 667 666 int ret; 668 667 669 - lock_kernel(); 668 + mutex_lock(&hp_sdc_rtc_mutex); 670 669 ret = hp_sdc_rtc_ioctl(file, cmd, arg); 671 - unlock_kernel(); 670 + mutex_unlock(&hp_sdc_rtc_mutex); 672 671 673 672 return ret; 674 673 }
+6 -5
drivers/misc/phantom.c
··· 24 24 #include <linux/slab.h> 25 25 #include <linux/phantom.h> 26 26 #include <linux/sched.h> 27 - #include <linux/smp_lock.h> 27 + #include <linux/mutex.h> 28 28 29 29 #include <asm/atomic.h> 30 30 #include <asm/io.h> ··· 38 38 #define PHB_RUNNING 1 39 39 #define PHB_NOT_OH 2 40 40 41 + static DEFINE_MUTEX(phantom_mutex); 41 42 static struct class *phantom_class; 42 43 static int phantom_major; 43 44 ··· 216 215 struct phantom_device *dev = container_of(inode->i_cdev, 217 216 struct phantom_device, cdev); 218 217 219 - lock_kernel(); 218 + mutex_lock(&phantom_mutex); 220 219 nonseekable_open(inode, file); 221 220 222 221 if (mutex_lock_interruptible(&dev->open_lock)) { 223 - unlock_kernel(); 222 + mutex_unlock(&phantom_mutex); 224 223 return -ERESTARTSYS; 225 224 } 226 225 227 226 if (dev->opened) { 228 227 mutex_unlock(&dev->open_lock); 229 - unlock_kernel(); 228 + mutex_unlock(&phantom_mutex); 230 229 return -EINVAL; 231 230 } 232 231 ··· 237 236 atomic_set(&dev->counter, 0); 238 237 dev->opened++; 239 238 mutex_unlock(&dev->open_lock); 240 - unlock_kernel(); 239 + mutex_unlock(&phantom_mutex); 241 240 return 0; 242 241 } 243 242
+7 -6
drivers/pci/hotplug/cpqphp_sysfs.c
··· 34 34 #include <linux/workqueue.h> 35 35 #include <linux/pci.h> 36 36 #include <linux/pci_hotplug.h> 37 - #include <linux/smp_lock.h> 37 + #include <linux/mutex.h> 38 38 #include <linux/debugfs.h> 39 39 #include "cpqphp.h" 40 40 41 + static DEFINE_MUTEX(cpqphp_mutex); 41 42 static int show_ctrl (struct controller *ctrl, char *buf) 42 43 { 43 44 char *out = buf; ··· 148 147 struct ctrl_dbg *dbg; 149 148 int retval = -ENOMEM; 150 149 151 - lock_kernel(); 150 + mutex_lock(&cpqphp_mutex); 152 151 dbg = kmalloc(sizeof(*dbg), GFP_KERNEL); 153 152 if (!dbg) 154 153 goto exit; ··· 161 160 file->private_data = dbg; 162 161 retval = 0; 163 162 exit: 164 - unlock_kernel(); 163 + mutex_unlock(&cpqphp_mutex); 165 164 return retval; 166 165 } 167 166 ··· 170 169 struct ctrl_dbg *dbg; 171 170 loff_t new = -1; 172 171 173 - lock_kernel(); 172 + mutex_lock(&cpqphp_mutex); 174 173 dbg = file->private_data; 175 174 176 175 switch (whence) { ··· 182 181 break; 183 182 } 184 183 if (new < 0 || new > dbg->size) { 185 - unlock_kernel(); 184 + mutex_unlock(&cpqphp_mutex); 186 185 return -EINVAL; 187 186 } 188 - unlock_kernel(); 187 + mutex_unlock(&cpqphp_mutex); 189 188 return (file->f_pos = new); 190 189 } 191 190
+7 -6
drivers/rtc/rtc-m41t80.c
··· 20 20 #include <linux/module.h> 21 21 #include <linux/rtc.h> 22 22 #include <linux/slab.h> 23 - #include <linux/smp_lock.h> 23 + #include <linux/mutex.h> 24 24 #include <linux/string.h> 25 25 #ifdef CONFIG_RTC_DRV_M41T80_WDT 26 26 #include <linux/fs.h> ··· 68 68 69 69 #define DRV_VERSION "0.05" 70 70 71 + static DEFINE_MUTEX(m41t80_rtc_mutex); 71 72 static const struct i2c_device_id m41t80_id[] = { 72 73 { "m41t62", M41T80_FEATURE_SQ | M41T80_FEATURE_SQ_ALT }, 73 74 { "m41t65", M41T80_FEATURE_HT | M41T80_FEATURE_WD }, ··· 678 677 { 679 678 int ret; 680 679 681 - lock_kernel(); 680 + mutex_lock(&m41t80_rtc_mutex); 682 681 ret = wdt_ioctl(file, cmd, arg); 683 - unlock_kernel(); 682 + mutex_unlock(&m41t80_rtc_mutex); 684 683 685 684 return ret; 686 685 } ··· 694 693 static int wdt_open(struct inode *inode, struct file *file) 695 694 { 696 695 if (MINOR(inode->i_rdev) == WATCHDOG_MINOR) { 697 - lock_kernel(); 696 + mutex_lock(&m41t80_rtc_mutex); 698 697 if (test_and_set_bit(0, &wdt_is_open)) { 699 - unlock_kernel(); 698 + mutex_unlock(&m41t80_rtc_mutex); 700 699 return -EBUSY; 701 700 } 702 701 /* 703 702 * Activate 704 703 */ 705 704 wdt_is_open = 1; 706 - unlock_kernel(); 705 + mutex_unlock(&m41t80_rtc_mutex); 707 706 return nonseekable_open(inode, file); 708 707 } 709 708 return -ENODEV;
+13 -11
drivers/sbus/char/jsflash.c
··· 27 27 */ 28 28 29 29 #include <linux/module.h> 30 - #include <linux/smp_lock.h> 30 + #include <linux/mutex.h> 31 31 #include <linux/types.h> 32 32 #include <linux/errno.h> 33 33 #include <linux/miscdevice.h> ··· 67 67 #define JSF_NPART 3 /* 3 minors per flash device */ 68 68 #define JSF_PART_BITS 2 /* 2 bits of minors to cover JSF_NPART */ 69 69 #define JSF_PART_MASK 0x3 /* 2 bits mask */ 70 + 71 + static DEFINE_MUTEX(jsf_mutex); 70 72 71 73 /* 72 74 * Access functions. ··· 227 225 { 228 226 loff_t ret; 229 227 230 - lock_kernel(); 228 + mutex_lock(&jsf_mutex); 231 229 switch (orig) { 232 230 case 0: 233 231 file->f_pos = offset; ··· 240 238 default: 241 239 ret = -EINVAL; 242 240 } 243 - unlock_kernel(); 241 + mutex_unlock(&jsf_mutex); 244 242 return ret; 245 243 } 246 244 ··· 386 384 387 385 static long jsf_ioctl(struct file *f, unsigned int cmd, unsigned long arg) 388 386 { 389 - lock_kernel(); 387 + mutex_lock(&jsf_mutex); 390 388 int error = -ENOTTY; 391 389 void __user *argp = (void __user *)arg; 392 390 393 391 if (!capable(CAP_SYS_ADMIN)) { 394 - unlock_kernel(); 392 + mutex_unlock(&jsf_mutex); 395 393 return -EPERM; 396 394 } 397 395 switch (cmd) { 398 396 case JSFLASH_IDENT: 399 397 if (copy_to_user(argp, &jsf0.id, JSFIDSZ)) { 400 - unlock_kernel(); 398 + mutex_unlock(&jsf_mutex); 401 399 return -EFAULT; 402 400 } 403 401 break; ··· 409 407 break; 410 408 } 411 409 412 - unlock_kernel(); 410 + mutex_unlock(&jsf_mutex); 413 411 return error; 414 412 } 415 413 ··· 420 418 421 419 static int jsf_open(struct inode * inode, struct file * filp) 422 420 { 423 - lock_kernel(); 421 + mutex_lock(&jsf_mutex); 424 422 if (jsf0.base == 0) { 425 - unlock_kernel(); 423 + mutex_unlock(&jsf_mutex); 426 424 return -ENXIO; 427 425 } 428 426 if (test_and_set_bit(0, (void *)&jsf0.busy) != 0) { 429 - unlock_kernel(); 427 + mutex_unlock(&jsf_mutex); 430 428 return -EBUSY; 431 429 } 432 430 433 - unlock_kernel(); 431 + mutex_unlock(&jsf_mutex); 434 432 return 0; /* XXX What security? */ 435 433 } 436 434
+4 -3
drivers/telephony/ixj.c
··· 257 257 #include <linux/fs.h> /* everything... */ 258 258 #include <linux/errno.h> /* error codes */ 259 259 #include <linux/slab.h> 260 - #include <linux/smp_lock.h> 260 + #include <linux/mutex.h> 261 261 #include <linux/mm.h> 262 262 #include <linux/ioport.h> 263 263 #include <linux/interrupt.h> ··· 277 277 #define TYPE(inode) (iminor(inode) >> 4) 278 278 #define NUM(inode) (iminor(inode) & 0xf) 279 279 280 + static DEFINE_MUTEX(ixj_mutex); 280 281 static int ixjdebug; 281 282 static int hertz = HZ; 282 283 static int samplerate = 100; ··· 6656 6655 static long ixj_ioctl(struct file *file_p, unsigned int cmd, unsigned long arg) 6657 6656 { 6658 6657 long ret; 6659 - lock_kernel(); 6658 + mutex_lock(&ixj_mutex); 6660 6659 ret = do_ixj_ioctl(file_p, cmd, arg); 6661 - unlock_kernel(); 6660 + mutex_unlock(&ixj_mutex); 6662 6661 return ret; 6663 6662 } 6664 6663
+8 -7
drivers/watchdog/cpwd.c
··· 25 25 #include <linux/ioport.h> 26 26 #include <linux/timer.h> 27 27 #include <linux/slab.h> 28 - #include <linux/smp_lock.h> 28 + #include <linux/mutex.h> 29 29 #include <linux/io.h> 30 30 #include <linux/of.h> 31 31 #include <linux/of_device.h> ··· 89 89 } devs[WD_NUMDEVS]; 90 90 }; 91 91 92 + static DEFINE_MUTEX(cpwd_mutex); 92 93 static struct cpwd *cpwd_device; 93 94 94 95 /* Sun uses Altera PLD EPF8820ATC144-4 ··· 369 368 { 370 369 struct cpwd *p = cpwd_device; 371 370 372 - lock_kernel(); 371 + mutex_lock(&cpwd_mutex); 373 372 switch (iminor(inode)) { 374 373 case WD0_MINOR: 375 374 case WD1_MINOR: ··· 377 376 break; 378 377 379 378 default: 380 - unlock_kernel(); 379 + mutex_unlock(&cpwd_mutex); 381 380 return -ENODEV; 382 381 } 383 382 ··· 387 386 IRQF_SHARED, DRIVER_NAME, p)) { 388 387 printk(KERN_ERR PFX "Cannot register IRQ %d\n", 389 388 p->irq); 390 - unlock_kernel(); 389 + mutex_unlock(&cpwd_mutex); 391 390 return -EBUSY; 392 391 } 393 392 p->initialized = true; 394 393 } 395 394 396 - unlock_kernel(); 395 + mutex_unlock(&cpwd_mutex); 397 396 398 397 return nonseekable_open(inode, f); 399 398 } ··· 483 482 case WIOCSTART: 484 483 case WIOCSTOP: 485 484 case WIOCGSTAT: 486 - lock_kernel(); 485 + mutex_lock(&cpwd_mutex); 487 486 rval = cpwd_ioctl(file, cmd, arg); 488 - unlock_kernel(); 487 + mutex_unlock(&cpwd_mutex); 489 488 break; 490 489 491 490 /* everything else is handled by the generic compat layer */