RE: [PATCH 1/2] cleanup: Add cond_guard() to conditional guards

From: Dan Williams
Date: Mon Feb 05 2024 - 16:14:09 EST


Fabio M. De Francesco wrote:
> Add cond_guard() macro to conditional guards.
>
> cond_guard() is a guard to be used with the conditional variants of locks,
> like down_read_trylock() or mutex_lock_interruptible().
>
> It takes a statement (or more statements in a block) that is passed to its

s/or more statements in a block/or statement-expression)/

s/to its/as its/

> second argument. That statement (or block) is executed if waiting for a
> lock is interrupted or if a _trylock() fails in case of contention.
>
> Usage example:
>
> cond_guard(rwsem_read_try, { printk(...); return 0; }, &semaphore);

Missed commenting on this in the last posting, but multi-statement fail
cases that print and return 0 are unlikely to ever be the common case. I
think the most simple to understand example is an interruptible lock
that returns -EINTR on failure:

cond_guard(mutex_intr, return -EINTR, &mutex);

..and then maybe mention that _fail can be a statement-expression if
needed.

> Consistenly with the other guards, locks are unlocked at the exit of the

s/Consistenly with the other guards/Consistent with other usage of guard()/