Skip to content

Commit 37989b5

Browse files
Shrikanth Hegdemaddy-kerneldev
authored andcommitted
powerpc: book3s: vas: use lock guard for mutex
use lock guards for scope based resource management of mutex. This would make the code simpler and easier to maintain. More details on lock guards can be found at https://lore.kernel.org/all/[email protected]/T/#u This shows the use of both guard and scoped_guard Reviewed-by: Srikar Dronamraju <[email protected]> Signed-off-by: Shrikanth Hegde <[email protected]> Tested-by: Venkat Rao Bagalkote <[email protected]> Signed-off-by: Madhavan Srinivasan <[email protected]> Link: https://patch.msgid.link/[email protected]
1 parent 5653463 commit 37989b5

File tree

1 file changed

+13
-19
lines changed

1 file changed

+13
-19
lines changed

arch/powerpc/platforms/book3s/vas-api.c

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -425,23 +425,22 @@ static vm_fault_t vas_mmap_fault(struct vm_fault *vmf)
425425
return VM_FAULT_SIGBUS;
426426
}
427427

428-
mutex_lock(&txwin->task_ref.mmap_mutex);
429428
/*
430429
* The window may be inactive due to lost credit (Ex: core
431430
* removal with DLPAR). If the window is active again when
432431
* the credit is available, map the new paste address at the
433432
* window virtual address.
434433
*/
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+
}
442442
}
443443
}
444-
mutex_unlock(&txwin->task_ref.mmap_mutex);
445444

446445
/*
447446
* Received this fault due to closing the actual window.
@@ -494,9 +493,8 @@ static void vas_mmap_close(struct vm_area_struct *vma)
494493
return;
495494
}
496495

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;
500498
}
501499

502500
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)
552550
* close/open event and allows mmap() only when the window is
553551
* active.
554552
*/
555-
mutex_lock(&txwin->task_ref.mmap_mutex);
553+
guard(mutex)(&txwin->task_ref.mmap_mutex);
556554
if (txwin->status != VAS_WIN_ACTIVE) {
557555
pr_err("Window is not active\n");
558-
rc = -EACCES;
559-
goto out;
556+
return -EACCES;
560557
}
561558

562559
paste_addr = cp_inst->coproc->vops->paste_addr(txwin);
563560
if (!paste_addr) {
564561
pr_err("Window paste address failed\n");
565-
rc = -EINVAL;
566-
goto out;
562+
return -EINVAL;
567563
}
568564

569565
pfn = paste_addr >> PAGE_SHIFT;
@@ -583,8 +579,6 @@ static int coproc_mmap(struct file *fp, struct vm_area_struct *vma)
583579
txwin->task_ref.vma = vma;
584580
vma->vm_ops = &vas_vm_ops;
585581

586-
out:
587-
mutex_unlock(&txwin->task_ref.mmap_mutex);
588582
return rc;
589583
}
590584

0 commit comments

Comments
 (0)