From: Andy Shevchenko <andriy.shevchenko@intel.com>
To: Zhu Jun <zhujun2@cmss.chinamobile.com>
Cc: jic23@kernel.org, dlechner@baylibre.com, nuno.sa@analog.com,
andy@kernel.org, linux-iio@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH] iio: potentiostat: lmp91000: Handle configuration write errors
Date: Thu, 12 Nov 2026 18:03:36 +0200 [thread overview]
Message-ID: <avXjWG56o9_O7x9o@ashevche-desk.local> (raw)
In-Reply-To: <20261112071747.154626-1-zhujun2@cmss.chinamobile.com>
On Thu, Nov 12, 2026 at 03:17:47PM +0800, Zhu Jun wrote:
> lmp91000_read_config() ignores errors when unlocking and programming
> the TIA and reference registers. Probe can then succeed even though
> the hardware configuration does not match the parameters used to
> interpret measurements.
>
> Check the configuration writes and return the first error. After a
> successful unlock, attempt to restore write protection even if a
> configuration write fails, and report a relock failure as well.
...
> static int lmp91000_read_config(struct lmp91000_data *data)
> {
> struct device *dev = data->dev;
> unsigned int reg, val;
> - int i, ret;
> + int i, ret, lock_ret;
While at it, it's better to split semantically different variables:
int ret, lock_ret;
int i;
> + ret = regmap_write(data->regmap, LMP91000_REG_TIACN, reg);
> + if (!ret)
> + ret = regmap_write(data->regmap, LMP91000_REG_REFCN,
> + LMP91000_REG_REFCN_EXT_REF | LMP91000_REG_REFCN_50_ZERO);
> +
> + /* Restore write protection even if programming the registers failed. */
> + lock_ret = regmap_write(data->regmap, LMP91000_REG_LOCK, 1);
> +
> + return ret ? ret : lock_ret;
It doesn't use any guard()() or so, hence just make a goto instead
(and use Elvis):
ret = regmap_write(data->regmap, LMP91000_REG_TIACN, reg);
if (ret)
goto restore_lock;
ret = regmap_write(data->regmap, LMP91000_REG_REFCN,
LMP91000_REG_REFCN_EXT_REF | LMP91000_REG_REFCN_50_ZERO);
restore_lock:
/* Restore write protection even if programming the registers failed. */
lock_ret = regmap_write(data->regmap, LMP91000_REG_LOCK, 1);
return ret ?: lock_ret;
> }
Alternatively, wrap the existing function (this will make code cleaner in some
maintainer's opinion).
...
In any case there is a question how may the caller distinguish the error from
register write and from the lock restoration? And what will it do in either of
the cases?
--
With Best Regards,
Andy Shevchenko
next prev parent reply other threads:[~2026-11-12 16:03 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-12 7:17 Zhu Jun
2026-11-12 16:03 ` Andy Shevchenko [this message]
2026-11-13 1:23 ` Jonathan Cameron
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=avXjWG56o9_O7x9o@ashevche-desk.local \
--to=andriy.shevchenko@intel.com \
--cc=andy@kernel.org \
--cc=dlechner@baylibre.com \
--cc=jic23@kernel.org \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=nuno.sa@analog.com \
--cc=zhujun2@cmss.chinamobile.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®