* [PATCH v2 2/3] iio: adc: ad7266: Use iio_device_claim_direct_scoped()
2024-06-03 18:07 ` [PATCH v2 1/3] iio: adc: ad7266: Fix variable checking bug Fernando Yang
@ 2024-06-03 18:07 ` Fernando Yang
2024-06-08 5:21 ` Marcelo Schmitt
2024-06-03 18:07 ` [PATCH v2 3/3] iio: adc: ad7266: Fix codestyle error Fernando Yang
` (2 subsequent siblings)
3 siblings, 1 reply; 11+ messages in thread
From: Fernando Yang @ 2024-06-03 18:07 UTC (permalink / raw)
To: hagisf, linux-iio; +Cc: Michael.Hennerich, jic23, lars
Switching to the _scoped() version can make the error handling more
natural instead of delayed until direct mode was released.
Signed-off-by: Fernando Yang <hagisf@usp.br>
---
drivers/iio/adc/ad7266.c | 27 +++++++++++++--------------
1 file changed, 13 insertions(+), 14 deletions(-)
diff --git a/drivers/iio/adc/ad7266.c b/drivers/iio/adc/ad7266.c
index 13ea8a107..356c2fe07 100644
--- a/drivers/iio/adc/ad7266.c
+++ b/drivers/iio/adc/ad7266.c
@@ -151,20 +151,19 @@ static int ad7266_read_raw(struct iio_dev *indio_dev,
switch (m) {
case IIO_CHAN_INFO_RAW:
- ret = iio_device_claim_direct_mode(indio_dev);
- if (ret)
- return ret;
- ret = ad7266_read_single(st, val, chan->address);
- iio_device_release_direct_mode(indio_dev);
-
- if (ret < 0)
- return ret;
- *val = (*val >> 2) & 0xfff;
- if (chan->scan_type.sign == 's')
- *val = sign_extend32(*val,
- chan->scan_type.realbits - 1);
-
- return IIO_VAL_INT;
+ iio_device_claim_direct_scoped(return -EBUSY, indio_dev) {
+ ret = ad7266_read_single(st, val, chan->address);
+
+ if (ret < 0)
+ return ret;
+ *val = (*val >> 2) & 0xfff;
+ if (chan->scan_type.sign == 's')
+ *val = sign_extend32(*val,
+ chan->scan_type.realbits - 1);
+
+ return IIO_VAL_INT;
+ }
+ unreachable();
case IIO_CHAN_INFO_SCALE:
scale_mv = st->vref_mv;
if (st->mode == AD7266_MODE_DIFF)
--
2.34.1
^ permalink raw reply related [flat|nested] 11+ messages in thread* Re: [PATCH v2 2/3] iio: adc: ad7266: Use iio_device_claim_direct_scoped()
2024-06-03 18:07 ` [PATCH v2 2/3] iio: adc: ad7266: Use iio_device_claim_direct_scoped() Fernando Yang
@ 2024-06-08 5:21 ` Marcelo Schmitt
0 siblings, 0 replies; 11+ messages in thread
From: Marcelo Schmitt @ 2024-06-08 5:21 UTC (permalink / raw)
To: Fernando Yang; +Cc: linux-iio, Michael.Hennerich, jic23, lars
Looks good overall, but a couple of untidy bits slipped through into the patch.
On 06/03, Fernando Yang wrote:
> Switching to the _scoped() version can make the error handling more
> natural instead of delayed until direct mode was released.
>
> Signed-off-by: Fernando Yang <hagisf@usp.br>
> ---
> drivers/iio/adc/ad7266.c | 27 +++++++++++++--------------
> 1 file changed, 13 insertions(+), 14 deletions(-)
>
> diff --git a/drivers/iio/adc/ad7266.c b/drivers/iio/adc/ad7266.c
> index 13ea8a107..356c2fe07 100644
> --- a/drivers/iio/adc/ad7266.c
> +++ b/drivers/iio/adc/ad7266.c
> @@ -151,20 +151,19 @@ static int ad7266_read_raw(struct iio_dev *indio_dev,
>
> switch (m) {
> case IIO_CHAN_INFO_RAW:
> - ret = iio_device_claim_direct_mode(indio_dev);
> - if (ret)
> - return ret;
> - ret = ad7266_read_single(st, val, chan->address);
> - iio_device_release_direct_mode(indio_dev);
> -
> - if (ret < 0)
> - return ret;
> - *val = (*val >> 2) & 0xfff;
> - if (chan->scan_type.sign == 's')
> - *val = sign_extend32(*val,
> - chan->scan_type.realbits - 1);
> -
> - return IIO_VAL_INT;
> + iio_device_claim_direct_scoped(return -EBUSY, indio_dev) {
> + ret = ad7266_read_single(st, val, chan->address);
The line right bellow adds 3 tabs. Don't add them so no need to remove them in patch 3. ;)
> +
> + if (ret < 0)
> + return ret;
> + *val = (*val >> 2) & 0xfff;
> + if (chan->scan_type.sign == 's')
Keep chan aligned to *val
> + *val = sign_extend32(*val,
> + chan->scan_type.realbits - 1);
*val = sign_extend32(*val,
chan->scan_type.realbits - 1);
> +
> + return IIO_VAL_INT;
> + }
> + unreachable();
> case IIO_CHAN_INFO_SCALE:
> scale_mv = st->vref_mv;
> if (st->mode == AD7266_MODE_DIFF)
> --
> 2.34.1
>
>
^ permalink raw reply [flat|nested] 11+ messages in thread
* [PATCH v2 3/3] iio: adc: ad7266: Fix codestyle error
2024-06-03 18:07 ` [PATCH v2 1/3] iio: adc: ad7266: Fix variable checking bug Fernando Yang
2024-06-03 18:07 ` [PATCH v2 2/3] iio: adc: ad7266: Use iio_device_claim_direct_scoped() Fernando Yang
@ 2024-06-03 18:07 ` Fernando Yang
2024-06-08 5:29 ` Marcelo Schmitt
2024-06-08 5:06 ` [PATCH v2 1/3] iio: adc: ad7266: Fix variable checking bug Marcelo Schmitt
2024-06-08 14:41 ` Jonathan Cameron
3 siblings, 1 reply; 11+ messages in thread
From: Fernando Yang @ 2024-06-03 18:07 UTC (permalink / raw)
To: hagisf, linux-iio; +Cc: Michael.Hennerich, jic23, lars
Fix some codestyle errors indicated by checkpatch.pl
Signed-off-by: Fernando Yang <hagisf@usp.br>
---
drivers/iio/adc/ad7266.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/drivers/iio/adc/ad7266.c b/drivers/iio/adc/ad7266.c
index 356c2fe07..5a2f1bb27 100644
--- a/drivers/iio/adc/ad7266.c
+++ b/drivers/iio/adc/ad7266.c
@@ -63,12 +63,14 @@ static int ad7266_powerdown(struct ad7266_state *st)
static int ad7266_preenable(struct iio_dev *indio_dev)
{
struct ad7266_state *st = iio_priv(indio_dev);
+
return ad7266_wakeup(st);
}
static int ad7266_postdisable(struct iio_dev *indio_dev)
{
struct ad7266_state *st = iio_priv(indio_dev);
+
return ad7266_powerdown(st);
}
@@ -153,7 +155,7 @@ static int ad7266_read_raw(struct iio_dev *indio_dev,
case IIO_CHAN_INFO_RAW:
iio_device_claim_direct_scoped(return -EBUSY, indio_dev) {
ret = ad7266_read_single(st, val, chan->address);
-
+
if (ret < 0)
return ret;
*val = (*val >> 2) & 0xfff;
--
2.34.1
^ permalink raw reply related [flat|nested] 11+ messages in thread* Re: [PATCH v2 3/3] iio: adc: ad7266: Fix codestyle error
2024-06-03 18:07 ` [PATCH v2 3/3] iio: adc: ad7266: Fix codestyle error Fernando Yang
@ 2024-06-08 5:29 ` Marcelo Schmitt
0 siblings, 0 replies; 11+ messages in thread
From: Marcelo Schmitt @ 2024-06-08 5:29 UTC (permalink / raw)
To: Fernando Yang; +Cc: linux-iio, Michael.Hennerich, jic23, lars
Looks good.
One minor neat being the last change won't be needed after patch 2 is updated.
Also, I think it will help visualize the patch series if a cover letter is added.
If running format-patch, the --cover-letter should help with it. e.g.
git format-patch -v3 --thread=shallow --cover-letter --to="..." --cc="..." -3
On 06/03, Fernando Yang wrote:
> Fix some codestyle errors indicated by checkpatch.pl
>
> Signed-off-by: Fernando Yang <hagisf@usp.br>
> ---
> drivers/iio/adc/ad7266.c | 4 +++-
> 1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/iio/adc/ad7266.c b/drivers/iio/adc/ad7266.c
> index 356c2fe07..5a2f1bb27 100644
> --- a/drivers/iio/adc/ad7266.c
> +++ b/drivers/iio/adc/ad7266.c
> @@ -63,12 +63,14 @@ static int ad7266_powerdown(struct ad7266_state *st)
> static int ad7266_preenable(struct iio_dev *indio_dev)
> {
> struct ad7266_state *st = iio_priv(indio_dev);
> +
> return ad7266_wakeup(st);
> }
>
> static int ad7266_postdisable(struct iio_dev *indio_dev)
> {
> struct ad7266_state *st = iio_priv(indio_dev);
> +
> return ad7266_powerdown(st);
> }
>
> @@ -153,7 +155,7 @@ static int ad7266_read_raw(struct iio_dev *indio_dev,
> case IIO_CHAN_INFO_RAW:
> iio_device_claim_direct_scoped(return -EBUSY, indio_dev) {
> ret = ad7266_read_single(st, val, chan->address);
This is not needed as comment on patch 2.
> -
> +
> if (ret < 0)
> return ret;
> *val = (*val >> 2) & 0xfff;
> --
> 2.34.1
>
>
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH v2 1/3] iio: adc: ad7266: Fix variable checking bug
2024-06-03 18:07 ` [PATCH v2 1/3] iio: adc: ad7266: Fix variable checking bug Fernando Yang
2024-06-03 18:07 ` [PATCH v2 2/3] iio: adc: ad7266: Use iio_device_claim_direct_scoped() Fernando Yang
2024-06-03 18:07 ` [PATCH v2 3/3] iio: adc: ad7266: Fix codestyle error Fernando Yang
@ 2024-06-08 5:06 ` Marcelo Schmitt
2024-06-08 14:11 ` Jonathan Cameron
2024-06-08 14:41 ` Jonathan Cameron
3 siblings, 1 reply; 11+ messages in thread
From: Marcelo Schmitt @ 2024-06-08 5:06 UTC (permalink / raw)
To: Fernando Yang; +Cc: linux-iio, Michael.Hennerich, jic23, lars
Hi Fernando,
This patch looks good.
I think a fixes tag would also be appropriate for this one.
Fixes: c70df20e3159 ("iio: adc: ad7266: claim direct mode during sensor read")
On 06/03, Fernando Yang wrote:
> The ret variable was not checked after iio_device_release_direct_mode(),
> which could possibly cause errors
>
> Signed-off-by: Fernando Yang <hagisf@usp.br>
> ---
> drivers/iio/adc/ad7266.c | 2 ++
> 1 file changed, 2 insertions(+)
>
> diff --git a/drivers/iio/adc/ad7266.c b/drivers/iio/adc/ad7266.c
> index 353a97f9c..13ea8a107 100644
> --- a/drivers/iio/adc/ad7266.c
> +++ b/drivers/iio/adc/ad7266.c
> @@ -157,6 +157,8 @@ static int ad7266_read_raw(struct iio_dev *indio_dev,
> ret = ad7266_read_single(st, val, chan->address);
> iio_device_release_direct_mode(indio_dev);
>
> + if (ret < 0)
> + return ret;
> *val = (*val >> 2) & 0xfff;
> if (chan->scan_type.sign == 's')
> *val = sign_extend32(*val,
> --
> 2.34.1
>
>
^ permalink raw reply [flat|nested] 11+ messages in thread* Re: [PATCH v2 1/3] iio: adc: ad7266: Fix variable checking bug
2024-06-08 5:06 ` [PATCH v2 1/3] iio: adc: ad7266: Fix variable checking bug Marcelo Schmitt
@ 2024-06-08 14:11 ` Jonathan Cameron
0 siblings, 0 replies; 11+ messages in thread
From: Jonathan Cameron @ 2024-06-08 14:11 UTC (permalink / raw)
To: Marcelo Schmitt; +Cc: Fernando Yang, linux-iio, Michael.Hennerich, lars
On Sat, 8 Jun 2024 02:06:21 -0300
Marcelo Schmitt <marcelo.schmitt1@gmail.com> wrote:
> Hi Fernando,
>
> This patch looks good.
> I think a fixes tag would also be appropriate for this one.
>
> Fixes: c70df20e3159 ("iio: adc: ad7266: claim direct mode during sensor read")
Agreed.
I've picked this one for the fixes-togreg branch of iio.git and marked it
for inclusion in linux-stable.
Note this will delay when I can pick up v3 of the other two patches, but
good to get this fix upstream in the meantime.
Thanks,
Jonathan
>
> On 06/03, Fernando Yang wrote:
> > The ret variable was not checked after iio_device_release_direct_mode(),
> > which could possibly cause errors
> >
> > Signed-off-by: Fernando Yang <hagisf@usp.br>
> > ---
> > drivers/iio/adc/ad7266.c | 2 ++
> > 1 file changed, 2 insertions(+)
> >
> > diff --git a/drivers/iio/adc/ad7266.c b/drivers/iio/adc/ad7266.c
> > index 353a97f9c..13ea8a107 100644
> > --- a/drivers/iio/adc/ad7266.c
> > +++ b/drivers/iio/adc/ad7266.c
> > @@ -157,6 +157,8 @@ static int ad7266_read_raw(struct iio_dev *indio_dev,
> > ret = ad7266_read_single(st, val, chan->address);
> > iio_device_release_direct_mode(indio_dev);
> >
> > + if (ret < 0)
> > + return ret;
> > *val = (*val >> 2) & 0xfff;
> > if (chan->scan_type.sign == 's')
> > *val = sign_extend32(*val,
> > --
> > 2.34.1
> >
> >
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH v2 1/3] iio: adc: ad7266: Fix variable checking bug
2024-06-03 18:07 ` [PATCH v2 1/3] iio: adc: ad7266: Fix variable checking bug Fernando Yang
` (2 preceding siblings ...)
2024-06-08 5:06 ` [PATCH v2 1/3] iio: adc: ad7266: Fix variable checking bug Marcelo Schmitt
@ 2024-06-08 14:41 ` Jonathan Cameron
3 siblings, 0 replies; 11+ messages in thread
From: Jonathan Cameron @ 2024-06-08 14:41 UTC (permalink / raw)
To: Fernando Yang; +Cc: linux-iio, Michael.Hennerich, lars
On Mon, 3 Jun 2024 15:07:54 -0300
Fernando Yang <hagisf@usp.br> wrote:
> The ret variable was not checked after iio_device_release_direct_mode(),
> which could possibly cause errors
>
> Signed-off-by: Fernando Yang <hagisf@usp.br>
For future reference, in IIO at least (and 'most' of the rest of the kernel)
don't send a patch set in reply to a previous one.
I can't remember who once gave a good explanation of why, but key to
limited time management when reviewing kernel patches is we start with
latest info and maybe never get back to the beginning.
Given everyone uses threading email clients, your email is a lot of
pages up from where I'd start if I wasn't aiming to clear the whole IIO
backlog this weekend...
> ---
> drivers/iio/adc/ad7266.c | 2 ++
> 1 file changed, 2 insertions(+)
>
> diff --git a/drivers/iio/adc/ad7266.c b/drivers/iio/adc/ad7266.c
> index 353a97f9c..13ea8a107 100644
> --- a/drivers/iio/adc/ad7266.c
> +++ b/drivers/iio/adc/ad7266.c
> @@ -157,6 +157,8 @@ static int ad7266_read_raw(struct iio_dev *indio_dev,
> ret = ad7266_read_single(st, val, chan->address);
> iio_device_release_direct_mode(indio_dev);
>
> + if (ret < 0)
> + return ret;
> *val = (*val >> 2) & 0xfff;
> if (chan->scan_type.sign == 's')
> *val = sign_extend32(*val,
^ permalink raw reply [flat|nested] 11+ messages in thread