Re: [PATCH] staging: nvec: use guard(mutex) in nvec_write_sync()

From: Julia Lawall

Date: Mon Oct 12 2026 - 16:46:05 EST




On Mon, 12 Oct 2026, Jeremy Dean Clifton wrote:

> Use guard(mutex) for sync_write_mutex. The lock is released
> automatically on every return path.

The second sentence seems ambiguous to me. Is this the motivation for
doing the patch or the result of the patch.

> This removes the three
> mutex_unlock() calls and simplifies the -ENOMEM error path.
>
> No functional change.
>
> Assisted-by: LLM

For Outreachy, I would encourage you to do the work by hand. You are
welcome to check the work with an LLM. The goal in the application period
is to learn how the patch submission process works, not necessarily to do
it as fast as possible.

Feel free to introduce yourself on the list as well.

julia

> Signed-off-by: Jeremy Dean Clifton <deaner92@xxxxxxxxx>
> ---
> drivers/staging/nvec/nvec.c | 9 ++-------
> 1 file changed, 2 insertions(+), 7 deletions(-)
>
> diff --git a/drivers/staging/nvec/nvec.c b/drivers/staging/nvec/nvec.c
> index 41cbdfdc1da6..716b1b482568 100644
> --- a/drivers/staging/nvec/nvec.c
> +++ b/drivers/staging/nvec/nvec.c
> @@ -298,17 +298,15 @@ int nvec_write_sync(struct nvec_chip *nvec,
> const unsigned char *data, short size,
> struct nvec_msg **msg)
> {
> - mutex_lock(&nvec->sync_write_mutex);
> + guard(mutex)(&nvec->sync_write_mutex);
>
> if (msg)
> *msg = NULL;
>
> nvec->sync_write_pending = (data[1] << 8) + data[0];
>
> - if (nvec_write_async(nvec, data, size) < 0) {
> - mutex_unlock(&nvec->sync_write_mutex);
> + if (nvec_write_async(nvec, data, size) < 0)
> return -ENOMEM;
> - }
>
> dev_dbg(nvec->dev, "nvec_sync_write: 0x%04x\n",
> nvec->sync_write_pending);
> @@ -316,7 +314,6 @@ int nvec_write_sync(struct nvec_chip *nvec,
> msecs_to_jiffies(2000)))) {
> dev_warn(nvec->dev,
> "Timeout waiting for sync write to complete\n");
> - mutex_unlock(&nvec->sync_write_mutex);
> return -ETIMEDOUT;
> }
>
> @@ -327,8 +324,6 @@ int nvec_write_sync(struct nvec_chip *nvec,
> else
> nvec_msg_free(nvec, nvec->last_sync_msg);
>
> - mutex_unlock(&nvec->sync_write_mutex);
> -
> return 0;
> }
> EXPORT_SYMBOL(nvec_write_sync);
> --
> 2.43.0
>
>
>