linux-amlogic.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: "Nuno Sá" <noname.nuno@gmail.com>
To: "Andy Shevchenko" <andy.shevchenko@gmail.com>,
	"Nuno Sá" <nuno.sa@analog.com>
Cc: linux-amlogic@lists.infradead.org, linux-imx@nxp.com,
	 linux-iio@vger.kernel.org, linux-arm-kernel@lists.infradead.org,
	 linux-rockchip@lists.infradead.org,
	Heiko Stuebner <heiko@sntech.de>,
	Martin Blumenstingl <martin.blumenstingl@googlemail.com>,
	Neil Armstrong <narmstrong@baylibre.com>,
	Shawn Guo <shawnguo@kernel.org>,
	Lars-Peter Clausen <lars@metafoo.de>,
	Jyoti Bhayana <jbhayana@google.com>,
	Hans de Goede <hdegoede@redhat.com>,
	Andriy Tryshnivskyy <andriy.tryshnivskyy@opensynergy.com>,
	Pengutronix Kernel Team <kernel@pengutronix.de>,
	Miquel Raynal <miquel.raynal@bootlin.com>,
	Cixi Geng <cixi.geng1@unisoc.com>,
	Baolin Wang <baolin.wang@linux.alibaba.com>,
	 Ciprian Regus <ciprian.regus@analog.com>,
	Fabio Estevam <festevam@gmail.com>,
	Sascha Hauer <s.hauer@pengutronix.de>,
	Alexandru Ardelean <aardelean@deviqon.com>,
	 Florian Boor <florian.boor@kernelconcepts.de>,
	Michael Hennerich <Michael.Hennerich@analog.com>,
	Orson Zhai <orsonzhai@gmail.com>, Chen-Yu Tsai <wens@csie.org>,
	Chunyan Zhang <zhang.lyra@gmail.com>,
	Vladimir Zapolskiy <vz@mleia.com>,
	Jerome Brunet <jbrunet@baylibre.com>,
	Haibo Chen <haibo.chen@nxp.com>,
	Kevin Hilman <khilman@baylibre.com>,
	Jonathan Cameron <jic23@kernel.org>
Subject: Re: [PATCH v2 15/16] iio: health: max30102: do not use internal iio_dev lock
Date: Wed, 05 Oct 2022 10:17:00 +0200	[thread overview]
Message-ID: <428661431e54744064946ced681cc0351d51d698.camel@gmail.com> (raw)
In-Reply-To: <CAHp75VdiAzOUNMB3wD5og-uZi1W_7UWkqV6+s7jCxpaBs1VWRQ@mail.gmail.com>

On Tue, 2022-10-04 at 17:15 +0300, Andy Shevchenko wrote:
> On Tue, Oct 4, 2022 at 4:49 PM Nuno Sá <nuno.sa@analog.com> wrote:
> > 
> > The pattern used in this device does not quite fit in the
> > iio_device_claim_direct_mode() typical usage. In this case, we want
> > to
> > know if we are in buffered mode or not to know if the device is
> > powered
> > (buffer mode) or not. And depending on that max30102_get_temp()
> > will
> > power on the device if needed. Hence, in order to keep the same
> > functionality, we try to:
> > 
> > 1. Claim Buffered mode;
> > 2: If 1) succeeds call max30102_get_temp() without powering on the
> >    device;
> > 3: Release Buffered mode;
> > 4: If 1) fails, Claim Direct mode;
> > 5: If 4) succeeds call max30102_get_temp() with powering on the
> > device;
> > 6: Release Direct mode;
> > 7: If 4) fails, goto to 1) and try again.
> > 
> > This dance between buffered and direct mode is not particularly
> > pretty
> > (as well as the loop introduced by the goto statement) but it does
> > allow
> > us to get rid of the mlock usage while keeping the same behavior.
> 
> ...
> 
> > +               if (iio_device_claim_buffer_mode(indio_dev)) {
> 
> Why is ret not used here?
> 
> > +                       /*
> > +                        * This one is a *bit* hacky. If we cannot
> > claim buffer
> > +                        * mode, then try direct mode so that we
> > make sure
> > +                        * things cannot concurrently change. And
> > we just keep
> > +                        * trying until we get one of the modes...
> > +                        */
> > +                       if
> > (iio_device_claim_direct_mode(indio_dev))
> 
> ...and here?
> 
> > +                               goto any_mode_retry;
> 
> > +               } else {
> 
> > +               }
> 
> I.o.w. what error code will be visible to the caller and why.
> 

Note that we do not really care about the error code returned by both
iio_device_claim_buffer_mode() and iio_device_claim_direct_mode(). We
just loop until we get one of the modes (thus ret = 0) so that we can
safely call one of the max30102_get_temp() variants. And that will be
the visible error code (if any). That said, you can look at the first
version of the series about this (and the previous patch) and why this
is being done like this (note that I'm also not 100% convinced about
this ping pong between getting one of the IIO modes but it's also not
that bad and if there's no major complains, I'm fine with it).

- Nuno Sá
_______________________________________________
linux-amlogic mailing list
linux-amlogic@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-amlogic

  reply	other threads:[~2022-10-05  8:16 UTC|newest]

Thread overview: 50+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-04 13:48 [PATCH v2 00/16] Make 'mlock' really private Nuno Sá
2022-10-04 13:48 ` [PATCH v2 01/16] iio: adc: ad799x: do not use internal iio_dev lock Nuno Sá
2022-10-09 11:53   ` Jonathan Cameron
2022-10-04 13:48 ` [PATCH v2 02/16] iio: adc: axp288_adc: " Nuno Sá
2022-10-09 11:55   ` Jonathan Cameron
2022-10-04 13:48 ` [PATCH v2 03/16] iio: adc: imx7d_adc: " Nuno Sá
2022-10-09  2:00   ` Bough Chen
2022-10-09 11:56     ` Jonathan Cameron
2022-10-04 13:48 ` [PATCH v2 04/16] iio: adc: lpc32xx_adc: " Nuno Sá
2022-10-09 11:57   ` Jonathan Cameron
2022-10-04 13:48 ` [PATCH v2 05/16] iio: adc: ltc2947-core: " Nuno Sá
2022-10-09 11:58   ` Jonathan Cameron
2022-10-04 13:48 ` [PATCH v2 06/16] iio: adc: meson_saradc: " Nuno Sá
2022-10-09 12:01   ` Jonathan Cameron
2022-10-04 13:49 ` [PATCH v2 07/16] iio: adc: rockchip_saradc: " Nuno Sá
2022-10-05  7:44   ` Heiko Stübner
2022-10-09 12:03     ` Jonathan Cameron
2022-10-04 13:49 ` [PATCH v2 08/16] iio: adc: sc27xx_adc: " Nuno Sá
2022-10-09 12:05   ` Jonathan Cameron
2022-10-04 13:49 ` [PATCH v2 09/16] iio: adc: vf610_adc: add helper function to read samples Nuno Sá
2022-10-09  2:10   ` Bough Chen
2022-10-04 13:49 ` [PATCH v2 10/16] iio: adc: vf610_adc: vf610_adc: do not use internal iio_dev lock Nuno Sá
2022-10-09  2:10   ` Bough Chen
2022-10-04 13:49 ` [PATCH v2 11/16] iio: common: scmi_iio: " Nuno Sá
2022-10-09 12:09   ` Jonathan Cameron
2022-10-04 13:49 ` [PATCH v2 12/16] iio: gyro: itg3200_core: " Nuno Sá
2022-10-09 12:10   ` Jonathan Cameron
2022-10-04 13:49 ` [PATCH v2 13/16] iio: core: introduce iio_device_{claim|release}_buffer_mode() APIs Nuno Sá
2022-10-04 14:08   ` Andy Shevchenko
2022-10-05  8:37     ` Nuno Sá
2022-10-09 11:41       ` Jonathan Cameron
2022-10-10  7:03         ` Nuno Sá
2022-10-04 13:49 ` [PATCH v2 14/16] iio: health: max30100: do not use internal iio_dev lock Nuno Sá
2022-10-04 14:13   ` Andy Shevchenko
2022-10-05  8:09     ` Nuno Sá
2022-10-09 12:14       ` Jonathan Cameron
2022-10-04 13:49 ` [PATCH v2 15/16] iio: health: max30102: " Nuno Sá
2022-10-04 14:15   ` Andy Shevchenko
2022-10-05  8:17     ` Nuno Sá [this message]
2022-10-09 11:44       ` Jonathan Cameron
2022-10-09 12:16         ` Jonathan Cameron
2022-10-10  7:08         ` Nuno Sá
2022-10-04 13:49 ` [PATCH v2 16/16] iio: core: move 'mlock' to 'struct iio_dev_opaque' Nuno Sá
2022-10-04 14:21   ` Andy Shevchenko
2022-10-05  8:40     ` Nuno Sá
2022-10-09 11:48       ` Jonathan Cameron
2022-10-09 11:52     ` Jonathan Cameron
2022-10-10  8:30       ` Andy Shevchenko
2022-10-09 12:19   ` Jonathan Cameron
2022-10-10  7:11     ` Nuno Sá

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=428661431e54744064946ced681cc0351d51d698.camel@gmail.com \
    --to=noname.nuno@gmail.com \
    --cc=Michael.Hennerich@analog.com \
    --cc=aardelean@deviqon.com \
    --cc=andriy.tryshnivskyy@opensynergy.com \
    --cc=andy.shevchenko@gmail.com \
    --cc=baolin.wang@linux.alibaba.com \
    --cc=ciprian.regus@analog.com \
    --cc=cixi.geng1@unisoc.com \
    --cc=festevam@gmail.com \
    --cc=florian.boor@kernelconcepts.de \
    --cc=haibo.chen@nxp.com \
    --cc=hdegoede@redhat.com \
    --cc=heiko@sntech.de \
    --cc=jbhayana@google.com \
    --cc=jbrunet@baylibre.com \
    --cc=jic23@kernel.org \
    --cc=kernel@pengutronix.de \
    --cc=khilman@baylibre.com \
    --cc=lars@metafoo.de \
    --cc=linux-amlogic@lists.infradead.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-imx@nxp.com \
    --cc=linux-rockchip@lists.infradead.org \
    --cc=martin.blumenstingl@googlemail.com \
    --cc=miquel.raynal@bootlin.com \
    --cc=narmstrong@baylibre.com \
    --cc=nuno.sa@analog.com \
    --cc=orsonzhai@gmail.com \
    --cc=s.hauer@pengutronix.de \
    --cc=shawnguo@kernel.org \
    --cc=vz@mleia.com \
    --cc=wens@csie.org \
    --cc=zhang.lyra@gmail.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;
as well as URLs for NNTP newsgroup(s).