iio: adc: adc7266: Use iio_device_claim_direct_scoped()
Subsystems (2)
PATCH 1/1 iio: adc: adc7266: Use iio_device_claim_direct_scoped()
Switching to the _scoped() version can make the error handling more natural instead of delayed until direct mode was released.
--- drivers/iio/adc/ad7266.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-)
drivers/iio/adc/ad7266.c +9 -6
@@ -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); }
@@ -151,15 +153,16 @@ static int ad7266_read_raw(struct iio_dev *indio_dev,switch (m) {case IIO_CHAN_INFO_RAW : -iio_device_claim_direct_scoped (return -EBUSY , indio_dev) + iio_device_claim_direct_scoped(return -EBUSY, indio_dev) { ret =ad7266_read_single (st, val, chan->address); - *val = (*val >>2 ) &0xfff ; -if (chan->scan_type.sign =='s' ) - *val =sign_extend32 (*val, - chan->scan_type.realbits -1 ); + *val = (*val >>2 ) &0xfff ; +if (chan->scan_type.sign =='s' ) + *val =sign_extend32 (*val, + chan->scan_type.realbits -1 ); -return IIO_VAL_INT ; +return IIO_VAL_INT ; + }unreachable ();case IIO_CHAN_INFO_SCALE : scale_mv = st->vref_mv;
Signature · 1 line
2.34.1
Hi Fernando, Eduardo,
The patch idea looks good. Though, there are some aspects to improve. First thing is this patch doesn't really apply to IIO testing branch [1]. Please, check the commits you have in your local branch.
Most often, each commit generates one patch. Looks like the commit from this patch should be squashed with some other commit.
Then, certify that the patches you generate apply cleanly to IIO testing branch. e.g.
git am 0001-my-awesome-patch.patch
More comments inline.
[1]: https://git.kernel.org/pub/scm/linux/kernel/git/jic23/iio.git/log/?h=testing
Quoted 16 lines · Fernando Yang
Switching to the
_scoped()version can make the error handling more natural instead of delayed until direct mode was released.Co-developed-by Eduardo Figueredo <[email protected]>Signed-off-by Eduardo Figueredo <[email protected]>Signed-off-by Fernando Yang <[email protected]>--- drivers/iio/adc/ad7266.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-)drivers/iio/adc/ad7266.c +0
-0
drivers/iio/adc/ad7266.c static int ad7266_powerdown(struct ad7266_state *st) · line 66
Quoted 4 lines
drivers/iio/adc/ad7266.c +1
-0@@ -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); +
This should belong to a separate patch. Conceptually, this is a different type of change compared to the update to use claim direct mode scoped advertised in patch message and body. The blank line additions would make up a code style patch.
drivers/iio/adc/ad7266.c static int ad7266_powerdown(struct ad7266_state *st) · line 73
Quoted 7 lines
drivers/iio/adc/ad7266.c +1
-0return ad7266_wakeup (st); }static int ad7266_postdisable (struct iio_dev *indio_dev) {struct ad7266_state *st =iio_priv (indio_dev); +
This also goes into the code style patch.
drivers/iio/adc/ad7266.c static int ad7266_read_raw(struct iio_dev *indio_dev,
Quoted 4 lines
drivers/iio/adc/ad7266.c +0
-0return ad7266_powerdown (st); }@@ -151,15 +153,16 @@ static int ad7266_read_raw(struct iio_dev *indio_dev,
I think after updating to call claim direct mode scoped the ret variable that is nearby can be removed. You may have removed the variable in your local branch but it would be nice to also have the removal in this patch.
Quoted 5 lines
drivers/iio/adc/ad7266.c +1
-1switch (m) {case IIO_CHAN_INFO_RAW : -iio_device_claim_direct_scoped (return -EBUSY , indio_dev) + iio_device_claim_direct_scoped(return -EBUSY, indio_dev) {
drivers/iio/adc/ad7266.c static int ad7266_read_raw(struct iio_dev *indio_dev, · line 162
Quoted 10 lines
drivers/iio/adc/ad7266.c +4
-4ret =ad7266_read_single (st, val, chan->address); - *val = (*val >>2 ) &0xfff ; -if (chan->scan_type.sign =='s' ) - *val =sign_extend32 (*val, - chan->scan_type.realbits -1 ); + *val = (*val >>2 ) &0xfff ; +if (chan->scan_type.sign =='s' ) + *val =sign_extend32 (*val, + chan->scan_type.realbits -1 );
This change actually introduces another code style issue for checkpatch to nitpick on. Please, consider also running checkpatch on generated patch files. e.g. ./scripts/checkpatch.pl --terse --codespell --color=always -strict 0001-use-claim-scoped.patch
Quoted 11 lines
drivers/iio/adc/ad7266.c +2
-1-return IIO_VAL_INT ; +return IIO_VAL_INT ; + }unreachable ();case IIO_CHAN_INFO_SCALE : scale_mv = st->vref_mv;Signature · 1 line
2.34.1
Jonathan Cameron
maintainerQuoted 31 lines · On Wed, 8 May 2024 12:54:35 -0300 Fernando Yang <[email protected]> wrote:
Switching to the
_scoped()version can make the error handling more natural instead of delayed until direct mode was released.Co-developed-by Eduardo Figueredo <[email protected]>Signed-off-by Eduardo Figueredo <[email protected]>Signed-off-by Fernando Yang <[email protected]>--- drivers/iio/adc/ad7266.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-)drivers/iio/adc/ad7266.c +2
-0@@ -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); }
drivers/iio/adc/ad7266.c static int ad7266_read_raw(struct iio_dev *indio_dev, · line 154
Quoted 4 lines
drivers/iio/adc/ad7266.c +0
-1@@ -151,15 +153,16 @@ static int ad7266_read_raw(struct iio_dev *indio_dev,switch (m) {case IIO_CHAN_INFO_RAW : -iio_device_claim_direct_scoped (return -EBUSY , indio_dev)
This isn't the existing code. I'm guessing you have another commit ahead of this one on your branch?
drivers/iio/adc/ad7266.c static int ad7266_read_raw(struct iio_dev *indio_dev, · line 157
Quoted 2 lines
drivers/iio/adc/ad7266.c +1
-0+ iio_device_claim_direct_scoped(return -EBUSY, indio_dev) { ret =ad7266_read_single (st, val, chan->address);
Not checking ret here is a bug in the existing code. Please fix that as a precursor patch before making the _scoped change.
The check will have to be immediately after iio_device_release_direct_mode() in the existing code.
Quoted 16 lines
drivers/iio/adc/ad7266.c +6
-5- *val = (*val >>2 ) &0xfff ; -if (chan->scan_type.sign =='s' ) - *val =sign_extend32 (*val, - chan->scan_type.realbits -1 ); + *val = (*val >>2 ) &0xfff ; +if (chan->scan_type.sign =='s' ) + *val =sign_extend32 (*val, + chan->scan_type.realbits -1 ); -return IIO_VAL_INT ; +return IIO_VAL_INT ; + }unreachable ();case IIO_CHAN_INFO_SCALE : scale_mv = st->vref_mv;
PATCH v2 1/3 iio: adc: ad7266: Fix variable checking bug
In reply to Fernando YangThe ret variable was not checked after iio_device_release_direct_mode(), which could possibly cause errors
--- drivers/iio/adc/ad7266.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/iio/adc/ad7266.c +2 -0
@@ -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,
Signature · 1 line
2.34.1
PATCH v2 2/3 iio: adc: ad7266: Use iio_device_claim_direct_scoped()
Switching to the _scoped() version can make the error handling more natural instead of delayed until direct mode was released.
--- drivers/iio/adc/ad7266.c | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-)
drivers/iio/adc/ad7266.c +13 -14
@@ -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 )
Signature · 1 line
2.34.1
Re: [PATCH v2 2/3] iio: adc: ad7266: Use iio_device_claim_direct_scoped()
Looks good overall, but a couple of untidy bits slipped through into the patch.
Quoted 22 lines · Fernando Yang
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 <[email protected]>--- drivers/iio/adc/ad7266.c | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-)drivers/iio/adc/ad7266.c +0
-6@@ -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); -
drivers/iio/adc/ad7266.c static int ad7266_read_raw(struct iio_dev *indio_dev, · line 155
Quoted 10 lines
drivers/iio/adc/ad7266.c +2
-8-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. ;)
drivers/iio/adc/ad7266.c static int ad7266_read_raw(struct iio_dev *indio_dev, · line 160
Quoted 5 lines
drivers/iio/adc/ad7266.c +5
-0+ +if (ret <0 ) +return ret; + *val = (*val >>2 ) &0xfff ; +if (chan->scan_type.sign =='s' )
Keep chan aligned to *val
drivers/iio/adc/ad7266.c static int ad7266_read_raw(struct iio_dev *indio_dev, · line 162
Quoted 2 lines
drivers/iio/adc/ad7266.c +2
-0+ *val =sign_extend32 (*val, + chan->scan_type.realbits -1 );
*val = sign_extend32(*val, chan->scan_type.realbits - 1);
Quoted 11 lines
drivers/iio/adc/ad7266.c +4
-0+ +return IIO_VAL_INT ; + } +unreachable ();case IIO_CHAN_INFO_SCALE : scale_mv = st->vref_mv;if (st->mode ==AD7266_MODE_DIFF )Signature · 1 line
2.34.1
PATCH v2 3/3 iio: adc: ad7266: Fix codestyle error
In reply to Fernando YangFix some codestyle errors indicated by checkpatch.pl
--- drivers/iio/adc/ad7266.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/iio/adc/ad7266.c +3 -1
@@ -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 ;
Signature · 1 line
2.34.1
Re: [PATCH v2 3/3] iio: adc: ad7266: Fix codestyle error
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
Quoted 27 lines · Fernando Yang
Fix some codestyle errors indicated by checkpatch.pl
Signed-off-by Fernando Yang <[email protected]>--- drivers/iio/adc/ad7266.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)drivers/iio/adc/ad7266.c +2
-0@@ -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); }
drivers/iio/adc/ad7266.c static int ad7266_read_raw(struct iio_dev *indio_dev, · line 157
Quoted 3 lines
drivers/iio/adc/ad7266.c +0
-0@@ -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.
Quoted 9 lines
drivers/iio/adc/ad7266.c +1
-1- +if (ret <0 )return ret; *val = (*val >>2 ) &0xfff ;Signature · 1 line
2.34.1
Re: [PATCH v2 1/3] iio: adc: ad7266: Fix variable checking bug
In reply to Fernando YangHi Fernando,
This patch looks good.
I think a fixes tag would also be appropriate for this one.
Quoted 25 lines · Fernando Yang
The ret variable was not checked after
iio_device_release_direct_mode(), which could possibly cause errorsSigned-off-by Fernando Yang <[email protected]>--- drivers/iio/adc/ad7266.c | 2 ++ 1 file changed, 2 insertions(+)drivers/iio/adc/ad7266.c +2
-0@@ -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,Signature · 1 line
2.34.1
Jonathan Cameron
maintainerRe: [PATCH v2 1/3] iio: adc: ad7266: Fix variable checking bug
Quoted 6 lines · On Sat, 8 Jun 2024 02:06:21 -0300 Marcelo Schmitt <[email protected]>…
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
Quoted 27 lines · Fernando Yang
Quoted 25 lines
The ret variable was not checked after
iio_device_release_direct_mode(), which could possibly cause errorsSigned-off-by Fernando Yang <[email protected]>--- drivers/iio/adc/ad7266.c | 2 ++ 1 file changed, 2 insertions(+)drivers/iio/adc/ad7266.c +2
-0@@ -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,Signature · 1 line
2.34.1
Jonathan Cameron
maintainerRe: [PATCH v2 1/3] iio: adc: ad7266: Fix variable checking bug
In reply to Fernando YangQuoted 4 lines · On Mon, 3 Jun 2024 15:07:54 -0300 Fernando Yang <[email protected]> wrote:
The ret variable was not checked after
iio_device_release_direct_mode(), which could possibly cause errorsSigned-off-by Fernando Yang <[email protected]>
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...
Quoted 17 lines
--- drivers/iio/adc/ad7266.c | 2 ++ 1 file changed, 2 insertions(+)drivers/iio/adc/ad7266.c +2
-0@@ -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,