Re: [PATCH 1/6] drm/panthor: Driver-wide xxx_[un]lock -> [scoped_]guard replacement

From: Steven Price

Date: Thu May 14 2026 - 09:18:14 EST


On 13/05/2026 17:58, Boris Brezillon wrote:
> Right now panthor is mixed bag of manual locks and guards. Let's
> make that more consitent and thus encourage new submissions to go
> for guards.

I'm fine with encouraging guards for future code - but I'm a little wary
of a big change like this - it's hard to review it and check that
everything works the same. And it's a little dubious that the mechanical
refactoring produces more readable code in some cases.

That said I asked my friendly AI bot...

[...]

> @@ -3142,48 +3126,44 @@ panthor_mmu_reclaim_priv_bos(struct panthor_device *ptdev,
> LIST_HEAD(remaining_vms);
> LIST_HEAD(vms);
>
> - mutex_lock(&ptdev->reclaim.lock);
> - list_splice_init(&ptdev->reclaim.vms, &vms);
> + scoped_guard(mutex, &ptdev->reclaim.lock)
> + list_splice_init(&ptdev->reclaim.vms, &vms);
>
> while (freed < nr_to_scan) {
> struct panthor_vm *vm;
>
> - vm = list_first_entry_or_null(&vms, typeof(*vm),
> - reclaim.lru_node);
> - if (!vm)
> - break;
> -
> - if (!kref_get_unless_zero(&vm->base.kref)) {
> - list_del_init(&vm->reclaim.lru_node);
> - continue;
> + scoped_guard(mutex, &ptdev->reclaim.lock) {
> + vm = list_first_entry_or_null(&vms, typeof(*vm),
> + reclaim.lru_node);
> + if (vm && !kref_get_unless_zero(&vm->base.kref)) {
> + list_del_init(&vm->reclaim.lru_node);
> + vm = NULL;
> + }
> }
>
> - mutex_unlock(&ptdev->reclaim.lock);
> + if (!vm)
> + break;

... and it said the above has changed behaviour.

In the !kref_get_unless_zero() case you now assign vm = NULL which then
leads to the 'break' case above. Previously we 'continue'd.

Thanks,
Steve