From: Jonathan Cameron <jic23@kernel.org>
To: Jiasheng Jiang <jiashengjiangcool@gmail.com>
Cc: dlechner@baylibre.com, lars@metafoo.de,
mcoquelin.stm32@gmail.com, alexandre.torgue@foss.st.com,
u.kleine-koenig@baylibre.com, tgamblin@baylibre.com,
fabrice.gasnier@st.com, benjamin.gaignard@linaro.org,
lee@kernel.org, linux-iio@vger.kernel.org,
linux-stm32@st-md-mailman.stormreply.com,
linux-arm-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH v4] iio: trigger: stm32-timer-trigger: Add check for clk_enable()
Date: Sat, 23 Nov 2024 15:08:08 +0000 [thread overview]
Message-ID: <20241123150808.1426c6f8@jic23-huawei> (raw)
In-Reply-To: <20241111222310.12339-1-jiashengjiangcool@gmail.com>
On Mon, 11 Nov 2024 22:23:10 +0000
Jiasheng Jiang <jiashengjiangcool@gmail.com> wrote:
> Add check for the return value of clk_enable() in order to catch the
> potential exception.
>
> Signed-off-by: Jiasheng Jiang <jiashengjiangcool@gmail.com>
Hi Jiasheng,
Should definitely mention the changes to use guard() to simplify
the resulting code.
One minor comment on the code inline. Otherwise looks good to me.
Thanks,
Jonathan
> ---
> Changelog:
>
> v3 -> v4:
>
> 1. Place braces around the case body.
>
> v2 -> v3:
>
> 1. Simplify code with cleanup helpers.
>
> v1 -> v2:
>
> 1. Remove unsuitable dev_err_probe().
> @@ -482,6 +484,7 @@ static int stm32_counter_write_raw(struct iio_dev *indio_dev,
> int val, int val2, long mask)
> {
> struct stm32_timer_trigger *priv = iio_priv(indio_dev);
> + int ret;
>
> switch (mask) {
> case IIO_CHAN_INFO_RAW:
> @@ -491,12 +494,14 @@ static int stm32_counter_write_raw(struct iio_dev *indio_dev,
> /* fixed scale */
> return -EINVAL;
>
> - case IIO_CHAN_INFO_ENABLE:
> - mutex_lock(&priv->lock);
> + case IIO_CHAN_INFO_ENABLE: {
> + guard(mutex)(&priv->lock);
> if (val) {
> if (!priv->enabled) {
> priv->enabled = true;
> - clk_enable(priv->clk);
> + ret = clk_enable(priv->clk);
> + if (ret)
> + return ret;
> }
> regmap_set_bits(priv->regmap, TIM_CR1, TIM_CR1_CEN);
> } else {
> @@ -506,9 +511,10 @@ static int stm32_counter_write_raw(struct iio_dev *indio_dev,
> clk_disable(priv->clk);
> }
> }
> - mutex_unlock(&priv->lock);
> +
> return 0;
> }
Add a default for reasons David mentioned and it also makes it visually clear
that we expect to get in here for other cases but they are all errors.
default:
return -EINVAL;
> + }
>
And drop this return as unreachable.
> return -EINVAL;
> }
next prev parent reply other threads:[~2024-11-23 15:08 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-11-11 22:23 [PATCH v4] iio: trigger: stm32-timer-trigger: Add check for clk_enable() Jiasheng Jiang
2024-11-11 22:53 ` David Lechner
2024-11-23 15:08 ` Jonathan Cameron [this message]
2024-11-23 22:04 ` Jiasheng Jiang
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=20241123150808.1426c6f8@jic23-huawei \
--to=jic23@kernel.org \
--cc=alexandre.torgue@foss.st.com \
--cc=benjamin.gaignard@linaro.org \
--cc=dlechner@baylibre.com \
--cc=fabrice.gasnier@st.com \
--cc=jiashengjiangcool@gmail.com \
--cc=lars@metafoo.de \
--cc=lee@kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-stm32@st-md-mailman.stormreply.com \
--cc=mcoquelin.stm32@gmail.com \
--cc=tgamblin@baylibre.com \
--cc=u.kleine-koenig@baylibre.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