@@ -425,23 +425,22 @@ static vm_fault_t vas_mmap_fault(struct vm_fault *vmf)
425
425
return VM_FAULT_SIGBUS ;
426
426
}
427
427
428
- mutex_lock (& txwin -> task_ref .mmap_mutex );
429
428
/*
430
429
* The window may be inactive due to lost credit (Ex: core
431
430
* removal with DLPAR). If the window is active again when
432
431
* the credit is available, map the new paste address at the
433
432
* window virtual address.
434
433
*/
435
- if (txwin -> status == VAS_WIN_ACTIVE ) {
436
- paste_addr = cp_inst -> coproc -> vops -> paste_addr (txwin );
437
- if (paste_addr ) {
438
- fault = vmf_insert_pfn (vma , vma -> vm_start ,
439
- (paste_addr >> PAGE_SHIFT ));
440
- mutex_unlock (& txwin -> task_ref .mmap_mutex );
441
- return fault ;
434
+ scoped_guard (mutex , & txwin -> task_ref .mmap_mutex ) {
435
+ if (txwin -> status == VAS_WIN_ACTIVE ) {
436
+ paste_addr = cp_inst -> coproc -> vops -> paste_addr (txwin );
437
+ if (paste_addr ) {
438
+ fault = vmf_insert_pfn (vma , vma -> vm_start ,
439
+ (paste_addr >> PAGE_SHIFT ));
440
+ return fault ;
441
+ }
442
442
}
443
443
}
444
- mutex_unlock (& txwin -> task_ref .mmap_mutex );
445
444
446
445
/*
447
446
* Received this fault due to closing the actual window.
@@ -494,9 +493,8 @@ static void vas_mmap_close(struct vm_area_struct *vma)
494
493
return ;
495
494
}
496
495
497
- mutex_lock (& txwin -> task_ref .mmap_mutex );
498
- txwin -> task_ref .vma = NULL ;
499
- mutex_unlock (& txwin -> task_ref .mmap_mutex );
496
+ scoped_guard (mutex , & txwin -> task_ref .mmap_mutex )
497
+ txwin -> task_ref .vma = NULL ;
500
498
}
501
499
502
500
static const struct vm_operations_struct vas_vm_ops = {
@@ -552,18 +550,16 @@ static int coproc_mmap(struct file *fp, struct vm_area_struct *vma)
552
550
* close/open event and allows mmap() only when the window is
553
551
* active.
554
552
*/
555
- mutex_lock (& txwin -> task_ref .mmap_mutex );
553
+ guard ( mutex ) (& txwin -> task_ref .mmap_mutex );
556
554
if (txwin -> status != VAS_WIN_ACTIVE ) {
557
555
pr_err ("Window is not active\n" );
558
- rc = - EACCES ;
559
- goto out ;
556
+ return - EACCES ;
560
557
}
561
558
562
559
paste_addr = cp_inst -> coproc -> vops -> paste_addr (txwin );
563
560
if (!paste_addr ) {
564
561
pr_err ("Window paste address failed\n" );
565
- rc = - EINVAL ;
566
- goto out ;
562
+ return - EINVAL ;
567
563
}
568
564
569
565
pfn = paste_addr >> PAGE_SHIFT ;
@@ -583,8 +579,6 @@ static int coproc_mmap(struct file *fp, struct vm_area_struct *vma)
583
579
txwin -> task_ref .vma = vma ;
584
580
vma -> vm_ops = & vas_vm_ops ;
585
581
586
- out :
587
- mutex_unlock (& txwin -> task_ref .mmap_mutex );
588
582
return rc ;
589
583
}
590
584
0 commit comments