From: Andy Shevchenko <andriy.shevchenko@intel.com>
To: Jonathan Cameron <jic23@kernel.org>
Cc: Andy Shevchenko <andy.shevchenko@gmail.com>,
Zhu Jun <zhujun2@cmss.chinamobile.com>,
dlechner@baylibre.com, nuno.sa@analog.com, andy@kernel.org,
linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v3] iio: potentiostat: lmp91000: Handle configuration write errors
Date: Mon, 16 Nov 2026 11:53:56 +0200 [thread overview]
Message-ID: <avrStKkcvUApPMDb@ashevche-desk.local> (raw)
In-Reply-To: <20261114014149.21dbc4d2@jic23-hlaptop>
On Sat, Nov 14, 2026 at 01:41:49AM +0000, Jonathan Cameron wrote:
> On Fri, 13 Nov 2026 10:47:32 +0200
> Andy Shevchenko <andy.shevchenko@gmail.com> wrote:
> > On Fri, Nov 13, 2026 at 10:41 AM Andy Shevchenko
> > <andy.shevchenko@gmail.com> wrote:
> > > On Fri, Nov 13, 2026 at 10:25 AM Zhu Jun <zhujun2@cmss.chinamobile.com> wrote:
...
> > > > Check the configuration writes and return the first error. After a
> > > > successful unlock, attempt to restore write protection even if a
> > > > configuration write fails. Return a relock error when both configuration
> > > > writes succeeded.
> > > >
> > > > lmp91000_probe() returns either error before registering the IIO device,
> > > > so the caller does not need to distinguish their source. Preserve the
> > > > configuration error if restoring write protection also fails.
> >
> > Btw, this is still unclear. See below.
...
> > > > - regmap_write(data->regmap, LMP91000_REG_LOCK, 0);
> > > > - regmap_write(data->regmap, LMP91000_REG_TIACN, reg);
> > > > - regmap_write(data->regmap, LMP91000_REG_REFCN,
> > > > - LMP91000_REG_REFCN_EXT_REF | LMP91000_REG_REFCN_50_ZERO);
> > > > + ret = regmap_write(data->regmap, LMP91000_REG_LOCK, 0);
> > > > + if (ret)
> > > > + return ret;
> > > > +
> > > > + ret = regmap_write(data->regmap, LMP91000_REG_TIACN, reg);
> > > > + if (ret)
> > > > + goto relock;
> > > > +
> > > > + ret = regmap_write(data->regmap, LMP91000_REG_REFCN,
> > > > + LMP91000_REG_REFCN_EXT_REF | LMP91000_REG_REFCN_50_ZERO);
> > > > + if (ret)
> > > > + goto relock;
> > > > +
> > > > + return regmap_write(data->regmap, LMP91000_REG_LOCK, 1);
> > > > +
> > > > +relock:
> > > > regmap_write(data->regmap, LMP91000_REG_LOCK, 1);
> > >
> > > What's the point of duplicating this?
> > > Before label you can easily do
> > >
> > > ret = 0;
> > >
> > > relock:
> > > ...
> >
> > Ah, okay, I see that the relock error is returned only on success of
> > the configuration update. Why is this inconsistency? Really, you need
> > to elaborate first on what the caller is suppose to do when
> > 1) unlock failed;
> > 2) unlock was successful, but configuration was failed;
> > 3) unlock and configuration was successful, but relock failed.
> >
> > In all of these cases the user gets an error, but it doesn't know
> > which stage was failed. What is the caller supposed to do?
> >
> > No need to send a new patch, let's keep discussion here to understand
> > the code flow better.
>
> I think I requested this flow. I didn't like v1 doing some dance
> with ret2 and only return that if ret wasn't set. Argument of the patch is
> that we must make sure to unlock even on error.
Right, but I think this is a slippery slope to leave device in the inconsistent
state and caller will not know if the locking failed or actual configuration.
How is HW being recovered from the inconsistent state(s)? That's basically my
main concern.
Note, I haven't checked with datasheet, so I have no clue how critical those
erroneous states are. If it's natural flow on the next iteration that clears
this problem, then we may relax on the error checking to begin with.
> > > > - return 0;
> > > > + return ret;
> > > > }
--
With Best Regards,
Andy Shevchenko
prev parent reply other threads:[~2026-11-16 9:54 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-13 8:25 Zhu Jun
2026-11-13 8:41 ` Andy Shevchenko
2026-11-13 8:47 ` Andy Shevchenko
2026-11-14 1:41 ` Jonathan Cameron
2026-11-16 9:53 ` 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=avrStKkcvUApPMDb@ashevche-desk.local \
--to=andriy.shevchenko@intel.com \
--cc=andy.shevchenko@gmail.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®