From: Andy Shevchenko <andriy.shevchenko@intel.com>
To: Melih Emik <melihemik@noirlang.tr>
Cc: jic23@kernel.org, gregkh@linuxfoundation.org, nuno.sa@analog.com,
Michael.Hennerich@analog.com, dlechner@baylibre.com,
andy@kernel.org, linux-iio@vger.kernel.org,
linux-staging@lists.linux.dev, linux-kernel@vger.kernel.org,
linux@analog.com
Subject: Re: [PATCH v2] staging: iio: frequency: ad9832: use guard(mutex)
Date: Mon, 19 Oct 2026 12:27:56 +0300 [thread overview]
Message-ID: <atXinPbnApcQLekk@ashevche-desk.local> (raw)
In-Reply-To: <20261018110107.297906-1-melihemik@noirlang.tr>
On Sun, Oct 18, 2026 at 02:01:07PM +0300, Melih Emik wrote:
> In ad9832_write(), manual mutex handling via mutex_lock() and
> mutex_unlock() necessitates error-exit trampolines (goto error_ret),
> intermediate variables, and deferred returns. This pattern is prone
> to unlock-omission bugs during refactoring and clutters the control
> flow.
>
> Modernize the locking by using guard(mutex) from <linux/cleanup.h>.
> Scope-based resource management automatically releases the lock upon
> exiting the lexical scope, which enables immediate error propagation
> at call sites, removes the error_ret label, and simplifies the control
> flow across all switch cases.
...
> case AD9832_FREQ_SYM:
> if (val == 1 || val == 0) {
> st->ctrl_fp &= ~AD9832_FREQ;
> st->ctrl_fp |= FIELD_PREP(AD9832_FREQ, val ? 1 : 0);
> } else {
> - ret = -EINVAL;
> - break;
> + return -EINVAL;
> }
'else' is now redundant:
if (val != 1 && val != 0)
return -EINVAL;
> st->data = cpu_to_be16(FIELD_PREP(AD9832_CMD_MSK, AD9832_CMD_FPSELECT) |
> st->ctrl_fp);
> ret = spi_sync(st->spi, &st->msg);
> + if (ret)
> + return ret;
> +
> break;
--
With Best Regards,
Andy Shevchenko
prev parent reply other threads:[~2026-10-19 9:28 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-18 11:01 Melih Emik
2026-10-19 9:27 ` Andy Shevchenko [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=atXinPbnApcQLekk@ashevche-desk.local \
--to=andriy.shevchenko@intel.com \
--cc=Michael.Hennerich@analog.com \
--cc=andy@kernel.org \
--cc=dlechner@baylibre.com \
--cc=gregkh@linuxfoundation.org \
--cc=jic23@kernel.org \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-staging@lists.linux.dev \
--cc=linux@analog.com \
--cc=melihemik@noirlang.tr \
--cc=nuno.sa@analog.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®