* [PATCH] iio:imu:bmi160: disable regulator in error path
@ 2022-03-18 7:09 Tong Zhang
2022-03-18 14:11 ` Andy Shevchenko
2022-03-27 15:40 ` [PATCH v3] " Tong Zhang
0 siblings, 2 replies; 13+ messages in thread
From: Tong Zhang @ 2022-03-18 7:09 UTC (permalink / raw)
To: Jonathan Cameron, Lars-Peter Clausen, Tong Zhang, Linus Walleij,
Alexandru Ardelean, Andy Shevchenko, Jonathan Albrieux,
linux-iio, linux-kernel
regulator should be disabled in error path as mentioned in _regulator_put()
[ 16.233604] WARNING: CPU: 0 PID: 2177 at drivers/regulator/core.c:2257 _regulator_put
[ 16.240453] Call Trace:
[ 16.240572] <TASK>
[ 16.240676] regulator_put+0x26/0x40
[ 16.240853] regulator_bulk_free+0x26/0x50
[ 16.241050] release_nodes+0x3f/0x70
[ 16.241225] devres_release_group+0x147/0x1c0
[ 16.241441] ? bmi160_core_probe+0x175/0x3a0 [bmi160_core]
Fixes: 5dea3fb066f0 ("iio: imu: bmi160: added regulator support")
Signed-off-by: Tong Zhang <ztong0001@gmail.com>
---
drivers/iio/imu/bmi160/bmi160_core.c | 17 +++++++++++------
1 file changed, 11 insertions(+), 6 deletions(-)
diff --git a/drivers/iio/imu/bmi160/bmi160_core.c b/drivers/iio/imu/bmi160/bmi160_core.c
index 824b5124a5f5..f12446edb5ce 100644
--- a/drivers/iio/imu/bmi160/bmi160_core.c
+++ b/drivers/iio/imu/bmi160/bmi160_core.c
@@ -730,7 +730,7 @@ static int bmi160_chip_init(struct bmi160_data *data, bool use_spi)
ret = regmap_write(data->regmap, BMI160_REG_CMD, BMI160_CMD_SOFTRESET);
if (ret)
- return ret;
+ goto disable_regulator;
usleep_range(BMI160_SOFTRESET_USLEEP, BMI160_SOFTRESET_USLEEP + 1);
@@ -741,29 +741,34 @@ static int bmi160_chip_init(struct bmi160_data *data, bool use_spi)
if (use_spi) {
ret = regmap_read(data->regmap, BMI160_REG_DUMMY, &val);
if (ret)
- return ret;
+ goto disable_regulator;
}
ret = regmap_read(data->regmap, BMI160_REG_CHIP_ID, &val);
if (ret) {
dev_err(dev, "Error reading chip id\n");
- return ret;
+ goto disable_regulator;
}
if (val != BMI160_CHIP_ID_VAL) {
dev_err(dev, "Wrong chip id, got %x expected %x\n",
val, BMI160_CHIP_ID_VAL);
- return -ENODEV;
+ ret = -ENODEV;
+ goto disable_regulator;
}
ret = bmi160_set_mode(data, BMI160_ACCEL, true);
if (ret)
- return ret;
+ goto disable_regulator;
ret = bmi160_set_mode(data, BMI160_GYRO, true);
if (ret)
- return ret;
+ goto disable_regulator;
return 0;
+
+disable_regulator:
+ regulator_bulk_disable(ARRAY_SIZE(data->supplies), data->supplies);
+ return ret;
}
static int bmi160_data_rdy_trigger_set_state(struct iio_trigger *trig,
--
2.25.1
^ permalink raw reply related [flat|nested] 13+ messages in thread
* Re: [PATCH] iio:imu:bmi160: disable regulator in error path
2022-03-18 7:09 [PATCH] iio:imu:bmi160: disable regulator in error path Tong Zhang
@ 2022-03-18 14:11 ` Andy Shevchenko
2022-03-19 16:20 ` Jonathan Cameron
2022-03-27 15:40 ` [PATCH v3] " Tong Zhang
1 sibling, 1 reply; 13+ messages in thread
From: Andy Shevchenko @ 2022-03-18 14:11 UTC (permalink / raw)
To: Tong Zhang
Cc: Jonathan Cameron, Lars-Peter Clausen, Linus Walleij,
Alexandru Ardelean, Jonathan Albrieux, linux-iio, linux-kernel
On Fri, Mar 18, 2022 at 12:09:00AM -0700, Tong Zhang wrote:
> regulator should be disabled in error path as mentioned in _regulator_put()
>
> [ 16.233604] WARNING: CPU: 0 PID: 2177 at drivers/regulator/core.c:2257 _regulator_put
> [ 16.240453] Call Trace:
> [ 16.240572] <TASK>
> [ 16.240676] regulator_put+0x26/0x40
> [ 16.240853] regulator_bulk_free+0x26/0x50
> [ 16.241050] release_nodes+0x3f/0x70
> [ 16.241225] devres_release_group+0x147/0x1c0
> [ 16.241441] ? bmi160_core_probe+0x175/0x3a0 [bmi160_core]
Seems legit. Currently we call it only when something else is failed afterwards.
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> Fixes: 5dea3fb066f0 ("iio: imu: bmi160: added regulator support")
> Signed-off-by: Tong Zhang <ztong0001@gmail.com>
> ---
> drivers/iio/imu/bmi160/bmi160_core.c | 17 +++++++++++------
> 1 file changed, 11 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/iio/imu/bmi160/bmi160_core.c b/drivers/iio/imu/bmi160/bmi160_core.c
> index 824b5124a5f5..f12446edb5ce 100644
> --- a/drivers/iio/imu/bmi160/bmi160_core.c
> +++ b/drivers/iio/imu/bmi160/bmi160_core.c
> @@ -730,7 +730,7 @@ static int bmi160_chip_init(struct bmi160_data *data, bool use_spi)
>
> ret = regmap_write(data->regmap, BMI160_REG_CMD, BMI160_CMD_SOFTRESET);
> if (ret)
> - return ret;
> + goto disable_regulator;
>
> usleep_range(BMI160_SOFTRESET_USLEEP, BMI160_SOFTRESET_USLEEP + 1);
>
> @@ -741,29 +741,34 @@ static int bmi160_chip_init(struct bmi160_data *data, bool use_spi)
> if (use_spi) {
> ret = regmap_read(data->regmap, BMI160_REG_DUMMY, &val);
> if (ret)
> - return ret;
> + goto disable_regulator;
> }
>
> ret = regmap_read(data->regmap, BMI160_REG_CHIP_ID, &val);
> if (ret) {
> dev_err(dev, "Error reading chip id\n");
> - return ret;
> + goto disable_regulator;
> }
> if (val != BMI160_CHIP_ID_VAL) {
> dev_err(dev, "Wrong chip id, got %x expected %x\n",
> val, BMI160_CHIP_ID_VAL);
> - return -ENODEV;
> + ret = -ENODEV;
> + goto disable_regulator;
> }
>
> ret = bmi160_set_mode(data, BMI160_ACCEL, true);
> if (ret)
> - return ret;
> + goto disable_regulator;
>
> ret = bmi160_set_mode(data, BMI160_GYRO, true);
> if (ret)
> - return ret;
> + goto disable_regulator;
>
> return 0;
> +
> +disable_regulator:
> + regulator_bulk_disable(ARRAY_SIZE(data->supplies), data->supplies);
> + return ret;
> }
>
> static int bmi160_data_rdy_trigger_set_state(struct iio_trigger *trig,
> --
> 2.25.1
>
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH] iio:imu:bmi160: disable regulator in error path
2022-03-18 14:11 ` Andy Shevchenko
@ 2022-03-19 16:20 ` Jonathan Cameron
2022-03-19 19:33 ` Tong Zhang
2022-03-19 19:34 ` [PATCH v2] " Tong Zhang
0 siblings, 2 replies; 13+ messages in thread
From: Jonathan Cameron @ 2022-03-19 16:20 UTC (permalink / raw)
To: Andy Shevchenko
Cc: Tong Zhang, Lars-Peter Clausen, Linus Walleij,
Alexandru Ardelean, Jonathan Albrieux, linux-iio, linux-kernel
On Fri, 18 Mar 2022 16:11:55 +0200
Andy Shevchenko <andriy.shevchenko@linux.intel.com> wrote:
> On Fri, Mar 18, 2022 at 12:09:00AM -0700, Tong Zhang wrote:
> > regulator should be disabled in error path as mentioned in _regulator_put()
> >
> > [ 16.233604] WARNING: CPU: 0 PID: 2177 at drivers/regulator/core.c:2257 _regulator_put
> > [ 16.240453] Call Trace:
> > [ 16.240572] <TASK>
> > [ 16.240676] regulator_put+0x26/0x40
> > [ 16.240853] regulator_bulk_free+0x26/0x50
> > [ 16.241050] release_nodes+0x3f/0x70
> > [ 16.241225] devres_release_group+0x147/0x1c0
> > [ 16.241441] ? bmi160_core_probe+0x175/0x3a0 [bmi160_core]
>
> Seems legit. Currently we call it only when something else is failed afterwards.
> Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Indeed this is fixing a real issue, but only one of two similar issues.
(I'd never have looked closely at this code without you spotting the first one :)
If I were writing this driver from scratch I would register
multiple devm_add_action_or_reset() callbacks and I note that even though
we might have turned the power off we haven't handled the other state
set in this init function.
1) Regulator disable.
2) bmi160_set_mode(bmi_data, BMI160_GYRO, false);
3) bmi160_set_mode(bmi_data, BMI160_ACCEL, false);
An alternative is to add handling for the first set_mode() in here being
unwound if the second fails. See below.
>
> > Fixes: 5dea3fb066f0 ("iio: imu: bmi160: added regulator support")
> > Signed-off-by: Tong Zhang <ztong0001@gmail.com>
> > ---
> > drivers/iio/imu/bmi160/bmi160_core.c | 17 +++++++++++------
> > 1 file changed, 11 insertions(+), 6 deletions(-)
> >
> > diff --git a/drivers/iio/imu/bmi160/bmi160_core.c b/drivers/iio/imu/bmi160/bmi160_core.c
> > index 824b5124a5f5..f12446edb5ce 100644
> > --- a/drivers/iio/imu/bmi160/bmi160_core.c
> > +++ b/drivers/iio/imu/bmi160/bmi160_core.c
> > @@ -730,7 +730,7 @@ static int bmi160_chip_init(struct bmi160_data *data, bool use_spi)
> >
> > ret = regmap_write(data->regmap, BMI160_REG_CMD, BMI160_CMD_SOFTRESET);
> > if (ret)
> > - return ret;
> > + goto disable_regulator;
> >
> > usleep_range(BMI160_SOFTRESET_USLEEP, BMI160_SOFTRESET_USLEEP + 1);
> >
> > @@ -741,29 +741,34 @@ static int bmi160_chip_init(struct bmi160_data *data, bool use_spi)
> > if (use_spi) {
> > ret = regmap_read(data->regmap, BMI160_REG_DUMMY, &val);
> > if (ret)
> > - return ret;
> > + goto disable_regulator;
> > }
> >
> > ret = regmap_read(data->regmap, BMI160_REG_CHIP_ID, &val);
> > if (ret) {
> > dev_err(dev, "Error reading chip id\n");
> > - return ret;
> > + goto disable_regulator;
> > }
> > if (val != BMI160_CHIP_ID_VAL) {
> > dev_err(dev, "Wrong chip id, got %x expected %x\n",
> > val, BMI160_CHIP_ID_VAL);
> > - return -ENODEV;
> > + ret = -ENODEV;
> > + goto disable_regulator;
> > }
> >
> > ret = bmi160_set_mode(data, BMI160_ACCEL, true);
> > if (ret)
> > - return ret;
> > + goto disable_regulator;
> >
> > ret = bmi160_set_mode(data, BMI160_GYRO, true);
> > if (ret)
If this fails, we should also undo the previous call as well. For readability
use goto disable_accel; then fix it under that new label.
> > - return ret;
> > + goto disable_regulator;
> >
> > return 0;
> > +
> > +disable_regulator:
> > + regulator_bulk_disable(ARRAY_SIZE(data->supplies), data->supplies);
> > + return ret;
> > }
> >
> > static int bmi160_data_rdy_trigger_set_state(struct iio_trigger *trig,
> > --
> > 2.25.1
> >
>
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH] iio:imu:bmi160: disable regulator in error path
2022-03-19 16:20 ` Jonathan Cameron
@ 2022-03-19 19:33 ` Tong Zhang
2022-03-19 19:34 ` [PATCH v2] " Tong Zhang
1 sibling, 0 replies; 13+ messages in thread
From: Tong Zhang @ 2022-03-19 19:33 UTC (permalink / raw)
To: Jonathan Cameron
Cc: Andy Shevchenko, Lars-Peter Clausen, Linus Walleij,
Alexandru Ardelean, Jonathan Albrieux, linux-iio, open list
Thank you, Jonathan and Andy. I will send v2 adding suggested fixes.
^ permalink raw reply [flat|nested] 13+ messages in thread
* [PATCH v2] iio:imu:bmi160: disable regulator in error path
2022-03-19 16:20 ` Jonathan Cameron
2022-03-19 19:33 ` Tong Zhang
@ 2022-03-19 19:34 ` Tong Zhang
2022-03-21 8:27 ` Andy Shevchenko
1 sibling, 1 reply; 13+ messages in thread
From: Tong Zhang @ 2022-03-19 19:34 UTC (permalink / raw)
To: Jonathan Cameron, Lars-Peter Clausen, Sean Nyekjaer,
Alexandru Ardelean, Tong Zhang, Linus Walleij, Andy Shevchenko,
Jonathan Albrieux, linux-iio, linux-kernel
Regulator should be disabled in error path as mentioned in _regulator_put().
Also disable accel if gyro cannot be enabled.
[ 16.233604] WARNING: CPU: 0 PID: 2177 at drivers/regulator/core.c:2257 _regulator_put
[ 16.240453] Call Trace:
[ 16.240572] <TASK>
[ 16.240676] regulator_put+0x26/0x40
[ 16.240853] regulator_bulk_free+0x26/0x50
[ 16.241050] release_nodes+0x3f/0x70
[ 16.241225] devres_release_group+0x147/0x1c0
[ 16.241441] ? bmi160_core_probe+0x175/0x3a0 [bmi160_core]
Fixes: 5dea3fb066f0 ("iio: imu: bmi160: added regulator support")
Signed-off-by: Tong Zhang <ztong0001@gmail.com>
---
v2: also disable accel when gyro fail to enable
drivers/iio/imu/bmi160/bmi160_core.c | 20 ++++++++++++++------
1 file changed, 14 insertions(+), 6 deletions(-)
diff --git a/drivers/iio/imu/bmi160/bmi160_core.c b/drivers/iio/imu/bmi160/bmi160_core.c
index 824b5124a5f5..01336105792e 100644
--- a/drivers/iio/imu/bmi160/bmi160_core.c
+++ b/drivers/iio/imu/bmi160/bmi160_core.c
@@ -730,7 +730,7 @@ static int bmi160_chip_init(struct bmi160_data *data, bool use_spi)
ret = regmap_write(data->regmap, BMI160_REG_CMD, BMI160_CMD_SOFTRESET);
if (ret)
- return ret;
+ goto disable_regulator;
usleep_range(BMI160_SOFTRESET_USLEEP, BMI160_SOFTRESET_USLEEP + 1);
@@ -741,29 +741,37 @@ static int bmi160_chip_init(struct bmi160_data *data, bool use_spi)
if (use_spi) {
ret = regmap_read(data->regmap, BMI160_REG_DUMMY, &val);
if (ret)
- return ret;
+ goto disable_regulator;
}
ret = regmap_read(data->regmap, BMI160_REG_CHIP_ID, &val);
if (ret) {
dev_err(dev, "Error reading chip id\n");
- return ret;
+ goto disable_regulator;
}
if (val != BMI160_CHIP_ID_VAL) {
dev_err(dev, "Wrong chip id, got %x expected %x\n",
val, BMI160_CHIP_ID_VAL);
- return -ENODEV;
+ ret = -ENODEV;
+ goto disable_regulator;
}
ret = bmi160_set_mode(data, BMI160_ACCEL, true);
if (ret)
- return ret;
+ goto disable_regulator;
ret = bmi160_set_mode(data, BMI160_GYRO, true);
if (ret)
- return ret;
+ goto disable_accel;
return 0;
+
+disable_accel:
+ bmi160_set_mode(data, BMI160_ACCEL, false);
+
+disable_regulator:
+ regulator_bulk_disable(ARRAY_SIZE(data->supplies), data->supplies);
+ return ret;
}
static int bmi160_data_rdy_trigger_set_state(struct iio_trigger *trig,
--
2.25.1
^ permalink raw reply related [flat|nested] 13+ messages in thread
* Re: [PATCH v2] iio:imu:bmi160: disable regulator in error path
2022-03-19 19:34 ` [PATCH v2] " Tong Zhang
@ 2022-03-21 8:27 ` Andy Shevchenko
2022-03-21 15:53 ` Tong Zhang
0 siblings, 1 reply; 13+ messages in thread
From: Andy Shevchenko @ 2022-03-21 8:27 UTC (permalink / raw)
To: Tong Zhang
Cc: Jonathan Cameron, Lars-Peter Clausen, Sean Nyekjaer,
Alexandru Ardelean, Linus Walleij, Andy Shevchenko,
Jonathan Albrieux, linux-iio, Linux Kernel Mailing List
On Sun, Mar 20, 2022 at 8:44 AM Tong Zhang <ztong0001@gmail.com> wrote:
>
> Regulator should be disabled in error path as mentioned in _regulator_put().
> Also disable accel if gyro cannot be enabled.
>
> [ 16.233604] WARNING: CPU: 0 PID: 2177 at drivers/regulator/core.c:2257 _regulator_put
> [ 16.240453] Call Trace:
> [ 16.240572] <TASK>
> [ 16.240676] regulator_put+0x26/0x40
> [ 16.240853] regulator_bulk_free+0x26/0x50
> [ 16.241050] release_nodes+0x3f/0x70
> [ 16.241225] devres_release_group+0x147/0x1c0
> [ 16.241441] ? bmi160_core_probe+0x175/0x3a0 [bmi160_core]
Haven't I given you a tag?
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH v2] iio:imu:bmi160: disable regulator in error path
2022-03-21 8:27 ` Andy Shevchenko
@ 2022-03-21 15:53 ` Tong Zhang
2022-03-21 16:22 ` Andy Shevchenko
0 siblings, 1 reply; 13+ messages in thread
From: Tong Zhang @ 2022-03-21 15:53 UTC (permalink / raw)
To: Andy Shevchenko
Cc: Jonathan Cameron, Lars-Peter Clausen, Sean Nyekjaer,
Alexandru Ardelean, Linus Walleij, Andy Shevchenko,
Jonathan Albrieux, linux-iio, Linux Kernel Mailing List
On Mon, Mar 21, 2022 at 1:28 AM Andy Shevchenko
<andy.shevchenko@gmail.com> wrote:
>
> On Sun, Mar 20, 2022 at 8:44 AM Tong Zhang <ztong0001@gmail.com> wrote:
> >
> > Regulator should be disabled in error path as mentioned in _regulator_put().
> > Also disable accel if gyro cannot be enabled.
> >
> > [ 16.233604] WARNING: CPU: 0 PID: 2177 at drivers/regulator/core.c:2257 _regulator_put
> > [ 16.240453] Call Trace:
> > [ 16.240572] <TASK>
> > [ 16.240676] regulator_put+0x26/0x40
> > [ 16.240853] regulator_bulk_free+0x26/0x50
> > [ 16.241050] release_nodes+0x3f/0x70
> > [ 16.241225] devres_release_group+0x147/0x1c0
> > [ 16.241441] ? bmi160_core_probe+0x175/0x3a0 [bmi160_core]
>
> Haven't I given you a tag?
>
> --
> With Best Regards,
> Andy Shevchenko
Hi Any, Thank you for reviewing the patch. I appreciate it.
I thought I would need another tag since this patch is a v2.
Sorry for this back and forth. Have a great one.
Thanks,
- Tong
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH v2] iio:imu:bmi160: disable regulator in error path
2022-03-21 15:53 ` Tong Zhang
@ 2022-03-21 16:22 ` Andy Shevchenko
2022-03-27 15:51 ` Jonathan Cameron
0 siblings, 1 reply; 13+ messages in thread
From: Andy Shevchenko @ 2022-03-21 16:22 UTC (permalink / raw)
To: Tong Zhang
Cc: Jonathan Cameron, Lars-Peter Clausen, Sean Nyekjaer,
Alexandru Ardelean, Linus Walleij, Andy Shevchenko,
Jonathan Albrieux, linux-iio, Linux Kernel Mailing List
On Mon, Mar 21, 2022 at 5:53 PM Tong Zhang <ztong0001@gmail.com> wrote:
> On Mon, Mar 21, 2022 at 1:28 AM Andy Shevchenko
> <andy.shevchenko@gmail.com> wrote:
> > On Sun, Mar 20, 2022 at 8:44 AM Tong Zhang <ztong0001@gmail.com> wrote:
...
> > Haven't I given you a tag?
> Hi Any, Thank you for reviewing the patch. I appreciate it.
> I thought I would need another tag since this patch is a v2.
It depends on the nature of the changes you made. As far as I read the
code the changes you made are in addition to what I have tagged and I
see nothing that prevents you from keeping the tag.
> Sorry for this back and forth. Have a great one.
NP.
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 13+ messages in thread
* [PATCH v3] iio:imu:bmi160: disable regulator in error path
2022-03-18 7:09 [PATCH] iio:imu:bmi160: disable regulator in error path Tong Zhang
2022-03-18 14:11 ` Andy Shevchenko
@ 2022-03-27 15:40 ` Tong Zhang
2022-03-27 15:53 ` Jonathan Cameron
1 sibling, 1 reply; 13+ messages in thread
From: Tong Zhang @ 2022-03-27 15:40 UTC (permalink / raw)
To: Jonathan Cameron, Lars-Peter Clausen, Tong Zhang,
Andy Shevchenko, Sean Nyekjaer, Alexandru Ardelean,
Jonathan Albrieux, linux-iio, linux-kernel
Regulator should be disabled in error path as mentioned in _regulator_put().
Also disable accel if gyro cannot be enabled.
[ 16.233604] WARNING: CPU: 0 PID: 2177 at drivers/regulator/core.c:2257 _regulator_put
[ 16.240453] Call Trace:
[ 16.240572] <TASK>
[ 16.240676] regulator_put+0x26/0x40
[ 16.240853] regulator_bulk_free+0x26/0x50
[ 16.241050] release_nodes+0x3f/0x70
[ 16.241225] devres_release_group+0x147/0x1c0
[ 16.241441] ? bmi160_core_probe+0x175/0x3a0 [bmi160_core]
Fixes: 5dea3fb066f0 ("iio: imu: bmi160: added regulator support")
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Tong Zhang <ztong0001@gmail.com>
---
v2: also disable accel when gyro fail to enable
v3: add tag
drivers/iio/imu/bmi160/bmi160_core.c | 20 ++++++++++++++------
1 file changed, 14 insertions(+), 6 deletions(-)
diff --git a/drivers/iio/imu/bmi160/bmi160_core.c b/drivers/iio/imu/bmi160/bmi160_core.c
index 824b5124a5f5..01336105792e 100644
--- a/drivers/iio/imu/bmi160/bmi160_core.c
+++ b/drivers/iio/imu/bmi160/bmi160_core.c
@@ -730,7 +730,7 @@ static int bmi160_chip_init(struct bmi160_data *data, bool use_spi)
ret = regmap_write(data->regmap, BMI160_REG_CMD, BMI160_CMD_SOFTRESET);
if (ret)
- return ret;
+ goto disable_regulator;
usleep_range(BMI160_SOFTRESET_USLEEP, BMI160_SOFTRESET_USLEEP + 1);
@@ -741,29 +741,37 @@ static int bmi160_chip_init(struct bmi160_data *data, bool use_spi)
if (use_spi) {
ret = regmap_read(data->regmap, BMI160_REG_DUMMY, &val);
if (ret)
- return ret;
+ goto disable_regulator;
}
ret = regmap_read(data->regmap, BMI160_REG_CHIP_ID, &val);
if (ret) {
dev_err(dev, "Error reading chip id\n");
- return ret;
+ goto disable_regulator;
}
if (val != BMI160_CHIP_ID_VAL) {
dev_err(dev, "Wrong chip id, got %x expected %x\n",
val, BMI160_CHIP_ID_VAL);
- return -ENODEV;
+ ret = -ENODEV;
+ goto disable_regulator;
}
ret = bmi160_set_mode(data, BMI160_ACCEL, true);
if (ret)
- return ret;
+ goto disable_regulator;
ret = bmi160_set_mode(data, BMI160_GYRO, true);
if (ret)
- return ret;
+ goto disable_accel;
return 0;
+
+disable_accel:
+ bmi160_set_mode(data, BMI160_ACCEL, false);
+
+disable_regulator:
+ regulator_bulk_disable(ARRAY_SIZE(data->supplies), data->supplies);
+ return ret;
}
static int bmi160_data_rdy_trigger_set_state(struct iio_trigger *trig,
--
2.25.1
^ permalink raw reply related [flat|nested] 13+ messages in thread
* Re: [PATCH v2] iio:imu:bmi160: disable regulator in error path
2022-03-21 16:22 ` Andy Shevchenko
@ 2022-03-27 15:51 ` Jonathan Cameron
0 siblings, 0 replies; 13+ messages in thread
From: Jonathan Cameron @ 2022-03-27 15:51 UTC (permalink / raw)
To: Andy Shevchenko
Cc: Tong Zhang, Lars-Peter Clausen, Sean Nyekjaer,
Alexandru Ardelean, Linus Walleij, Andy Shevchenko,
Jonathan Albrieux, linux-iio, Linux Kernel Mailing List
On Mon, 21 Mar 2022 18:22:10 +0200
Andy Shevchenko <andy.shevchenko@gmail.com> wrote:
> On Mon, Mar 21, 2022 at 5:53 PM Tong Zhang <ztong0001@gmail.com> wrote:
> > On Mon, Mar 21, 2022 at 1:28 AM Andy Shevchenko
> > <andy.shevchenko@gmail.com> wrote:
> > > On Sun, Mar 20, 2022 at 8:44 AM Tong Zhang <ztong0001@gmail.com> wrote:
>
> ...
>
> > > Haven't I given you a tag?
>
> > Hi Any, Thank you for reviewing the patch. I appreciate it.
> > I thought I would need another tag since this patch is a v2.
>
> It depends on the nature of the changes you made. As far as I read the
> code the changes you made are in addition to what I have tagged and I
> see nothing that prevents you from keeping the tag.
>
> > Sorry for this back and forth. Have a great one.
>
> NP.
>
Applied to the fixes-togreg branch of iio.git but I won't push
it out until I've rebased that on rc1 once available.
Thanks,
Jonathan
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH v3] iio:imu:bmi160: disable regulator in error path
2022-03-27 15:40 ` [PATCH v3] " Tong Zhang
@ 2022-03-27 15:53 ` Jonathan Cameron
2022-03-27 15:58 ` Tong Zhang
2022-03-27 16:02 ` Jonathan Cameron
0 siblings, 2 replies; 13+ messages in thread
From: Jonathan Cameron @ 2022-03-27 15:53 UTC (permalink / raw)
To: Tong Zhang
Cc: Lars-Peter Clausen, Andy Shevchenko, Sean Nyekjaer,
Alexandru Ardelean, Jonathan Albrieux, linux-iio, linux-kernel
On Sun, 27 Mar 2022 08:40:05 -0700
Tong Zhang <ztong0001@gmail.com> wrote:
> Regulator should be disabled in error path as mentioned in _regulator_put().
> Also disable accel if gyro cannot be enabled.
>
> [ 16.233604] WARNING: CPU: 0 PID: 2177 at drivers/regulator/core.c:2257 _regulator_put
> [ 16.240453] Call Trace:
> [ 16.240572] <TASK>
> [ 16.240676] regulator_put+0x26/0x40
> [ 16.240853] regulator_bulk_free+0x26/0x50
> [ 16.241050] release_nodes+0x3f/0x70
> [ 16.241225] devres_release_group+0x147/0x1c0
> [ 16.241441] ? bmi160_core_probe+0x175/0x3a0 [bmi160_core]
>
> Fixes: 5dea3fb066f0 ("iio: imu: bmi160: added regulator support")
> Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> Signed-off-by: Tong Zhang <ztong0001@gmail.com>
oops. Raced with you ;)
Anyhow, I added the tag, so no problem.
Jonathan
> ---
> v2: also disable accel when gyro fail to enable
> v3: add tag
> drivers/iio/imu/bmi160/bmi160_core.c | 20 ++++++++++++++------
> 1 file changed, 14 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/iio/imu/bmi160/bmi160_core.c b/drivers/iio/imu/bmi160/bmi160_core.c
> index 824b5124a5f5..01336105792e 100644
> --- a/drivers/iio/imu/bmi160/bmi160_core.c
> +++ b/drivers/iio/imu/bmi160/bmi160_core.c
> @@ -730,7 +730,7 @@ static int bmi160_chip_init(struct bmi160_data *data, bool use_spi)
>
> ret = regmap_write(data->regmap, BMI160_REG_CMD, BMI160_CMD_SOFTRESET);
> if (ret)
> - return ret;
> + goto disable_regulator;
>
> usleep_range(BMI160_SOFTRESET_USLEEP, BMI160_SOFTRESET_USLEEP + 1);
>
> @@ -741,29 +741,37 @@ static int bmi160_chip_init(struct bmi160_data *data, bool use_spi)
> if (use_spi) {
> ret = regmap_read(data->regmap, BMI160_REG_DUMMY, &val);
> if (ret)
> - return ret;
> + goto disable_regulator;
> }
>
> ret = regmap_read(data->regmap, BMI160_REG_CHIP_ID, &val);
> if (ret) {
> dev_err(dev, "Error reading chip id\n");
> - return ret;
> + goto disable_regulator;
> }
> if (val != BMI160_CHIP_ID_VAL) {
> dev_err(dev, "Wrong chip id, got %x expected %x\n",
> val, BMI160_CHIP_ID_VAL);
> - return -ENODEV;
> + ret = -ENODEV;
> + goto disable_regulator;
> }
>
> ret = bmi160_set_mode(data, BMI160_ACCEL, true);
> if (ret)
> - return ret;
> + goto disable_regulator;
>
> ret = bmi160_set_mode(data, BMI160_GYRO, true);
> if (ret)
> - return ret;
> + goto disable_accel;
>
> return 0;
> +
> +disable_accel:
> + bmi160_set_mode(data, BMI160_ACCEL, false);
> +
> +disable_regulator:
> + regulator_bulk_disable(ARRAY_SIZE(data->supplies), data->supplies);
> + return ret;
> }
>
> static int bmi160_data_rdy_trigger_set_state(struct iio_trigger *trig,
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH v3] iio:imu:bmi160: disable regulator in error path
2022-03-27 15:53 ` Jonathan Cameron
@ 2022-03-27 15:58 ` Tong Zhang
2022-03-27 16:02 ` Jonathan Cameron
1 sibling, 0 replies; 13+ messages in thread
From: Tong Zhang @ 2022-03-27 15:58 UTC (permalink / raw)
To: Jonathan Cameron
Cc: Lars-Peter Clausen, Andy Shevchenko, Sean Nyekjaer,
Alexandru Ardelean, Jonathan Albrieux, linux-iio, open list
On Sun, Mar 27, 2022 at 8:46 AM Jonathan Cameron <jic23@kernel.org> wrote:
>
> On Sun, 27 Mar 2022 08:40:05 -0700
> Tong Zhang <ztong0001@gmail.com> wrote:
>
> > Regulator should be disabled in error path as mentioned in _regulator_put().
> > Also disable accel if gyro cannot be enabled.
> >
> > [ 16.233604] WARNING: CPU: 0 PID: 2177 at drivers/regulator/core.c:2257 _regulator_put
> > [ 16.240453] Call Trace:
> > [ 16.240572] <TASK>
> > [ 16.240676] regulator_put+0x26/0x40
> > [ 16.240853] regulator_bulk_free+0x26/0x50
> > [ 16.241050] release_nodes+0x3f/0x70
> > [ 16.241225] devres_release_group+0x147/0x1c0
> > [ 16.241441] ? bmi160_core_probe+0x175/0x3a0 [bmi160_core]
> >
> > Fixes: 5dea3fb066f0 ("iio: imu: bmi160: added regulator support")
> > Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> > Signed-off-by: Tong Zhang <ztong0001@gmail.com>
> oops. Raced with you ;)
>
> Anyhow, I added the tag, so no problem.
>
> Jonathan
No problem. Have a nice weekend!:-)
- Tong
>
> > ---
> > v2: also disable accel when gyro fail to enable
> > v3: add tag
> > drivers/iio/imu/bmi160/bmi160_core.c | 20 ++++++++++++++------
> > 1 file changed, 14 insertions(+), 6 deletions(-)
> >
> > diff --git a/drivers/iio/imu/bmi160/bmi160_core.c b/drivers/iio/imu/bmi160/bmi160_core.c
> > index 824b5124a5f5..01336105792e 100644
> > --- a/drivers/iio/imu/bmi160/bmi160_core.c
> > +++ b/drivers/iio/imu/bmi160/bmi160_core.c
> > @@ -730,7 +730,7 @@ static int bmi160_chip_init(struct bmi160_data *data, bool use_spi)
> >
> > ret = regmap_write(data->regmap, BMI160_REG_CMD, BMI160_CMD_SOFTRESET);
> > if (ret)
> > - return ret;
> > + goto disable_regulator;
> >
> > usleep_range(BMI160_SOFTRESET_USLEEP, BMI160_SOFTRESET_USLEEP + 1);
> >
> > @@ -741,29 +741,37 @@ static int bmi160_chip_init(struct bmi160_data *data, bool use_spi)
> > if (use_spi) {
> > ret = regmap_read(data->regmap, BMI160_REG_DUMMY, &val);
> > if (ret)
> > - return ret;
> > + goto disable_regulator;
> > }
> >
> > ret = regmap_read(data->regmap, BMI160_REG_CHIP_ID, &val);
> > if (ret) {
> > dev_err(dev, "Error reading chip id\n");
> > - return ret;
> > + goto disable_regulator;
> > }
> > if (val != BMI160_CHIP_ID_VAL) {
> > dev_err(dev, "Wrong chip id, got %x expected %x\n",
> > val, BMI160_CHIP_ID_VAL);
> > - return -ENODEV;
> > + ret = -ENODEV;
> > + goto disable_regulator;
> > }
> >
> > ret = bmi160_set_mode(data, BMI160_ACCEL, true);
> > if (ret)
> > - return ret;
> > + goto disable_regulator;
> >
> > ret = bmi160_set_mode(data, BMI160_GYRO, true);
> > if (ret)
> > - return ret;
> > + goto disable_accel;
> >
> > return 0;
> > +
> > +disable_accel:
> > + bmi160_set_mode(data, BMI160_ACCEL, false);
> > +
> > +disable_regulator:
> > + regulator_bulk_disable(ARRAY_SIZE(data->supplies), data->supplies);
> > + return ret;
> > }
> >
> > static int bmi160_data_rdy_trigger_set_state(struct iio_trigger *trig,
>
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH v3] iio:imu:bmi160: disable regulator in error path
2022-03-27 15:53 ` Jonathan Cameron
2022-03-27 15:58 ` Tong Zhang
@ 2022-03-27 16:02 ` Jonathan Cameron
1 sibling, 0 replies; 13+ messages in thread
From: Jonathan Cameron @ 2022-03-27 16:02 UTC (permalink / raw)
To: Tong Zhang
Cc: Lars-Peter Clausen, Andy Shevchenko, Sean Nyekjaer,
Alexandru Ardelean, Jonathan Albrieux, linux-iio, linux-kernel
On Sun, 27 Mar 2022 16:53:36 +0100
Jonathan Cameron <jic23@kernel.org> wrote:
> On Sun, 27 Mar 2022 08:40:05 -0700
> Tong Zhang <ztong0001@gmail.com> wrote:
>
> > Regulator should be disabled in error path as mentioned in _regulator_put().
> > Also disable accel if gyro cannot be enabled.
> >
> > [ 16.233604] WARNING: CPU: 0 PID: 2177 at drivers/regulator/core.c:2257 _regulator_put
> > [ 16.240453] Call Trace:
> > [ 16.240572] <TASK>
> > [ 16.240676] regulator_put+0x26/0x40
> > [ 16.240853] regulator_bulk_free+0x26/0x50
> > [ 16.241050] release_nodes+0x3f/0x70
> > [ 16.241225] devres_release_group+0x147/0x1c0
> > [ 16.241441] ? bmi160_core_probe+0x175/0x3a0 [bmi160_core]
> >
> > Fixes: 5dea3fb066f0 ("iio: imu: bmi160: added regulator support")
> > Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> > Signed-off-by: Tong Zhang <ztong0001@gmail.com>
> oops. Raced with you ;)
>
> Anyhow, I added the tag, so no problem.
on closer inspection b4 was clever and picked v3 up anyway.
J
>
> Jonathan
>
> > ---
> > v2: also disable accel when gyro fail to enable
> > v3: add tag
> > drivers/iio/imu/bmi160/bmi160_core.c | 20 ++++++++++++++------
> > 1 file changed, 14 insertions(+), 6 deletions(-)
> >
> > diff --git a/drivers/iio/imu/bmi160/bmi160_core.c b/drivers/iio/imu/bmi160/bmi160_core.c
> > index 824b5124a5f5..01336105792e 100644
> > --- a/drivers/iio/imu/bmi160/bmi160_core.c
> > +++ b/drivers/iio/imu/bmi160/bmi160_core.c
> > @@ -730,7 +730,7 @@ static int bmi160_chip_init(struct bmi160_data *data, bool use_spi)
> >
> > ret = regmap_write(data->regmap, BMI160_REG_CMD, BMI160_CMD_SOFTRESET);
> > if (ret)
> > - return ret;
> > + goto disable_regulator;
> >
> > usleep_range(BMI160_SOFTRESET_USLEEP, BMI160_SOFTRESET_USLEEP + 1);
> >
> > @@ -741,29 +741,37 @@ static int bmi160_chip_init(struct bmi160_data *data, bool use_spi)
> > if (use_spi) {
> > ret = regmap_read(data->regmap, BMI160_REG_DUMMY, &val);
> > if (ret)
> > - return ret;
> > + goto disable_regulator;
> > }
> >
> > ret = regmap_read(data->regmap, BMI160_REG_CHIP_ID, &val);
> > if (ret) {
> > dev_err(dev, "Error reading chip id\n");
> > - return ret;
> > + goto disable_regulator;
> > }
> > if (val != BMI160_CHIP_ID_VAL) {
> > dev_err(dev, "Wrong chip id, got %x expected %x\n",
> > val, BMI160_CHIP_ID_VAL);
> > - return -ENODEV;
> > + ret = -ENODEV;
> > + goto disable_regulator;
> > }
> >
> > ret = bmi160_set_mode(data, BMI160_ACCEL, true);
> > if (ret)
> > - return ret;
> > + goto disable_regulator;
> >
> > ret = bmi160_set_mode(data, BMI160_GYRO, true);
> > if (ret)
> > - return ret;
> > + goto disable_accel;
> >
> > return 0;
> > +
> > +disable_accel:
> > + bmi160_set_mode(data, BMI160_ACCEL, false);
> > +
> > +disable_regulator:
> > + regulator_bulk_disable(ARRAY_SIZE(data->supplies), data->supplies);
> > + return ret;
> > }
> >
> > static int bmi160_data_rdy_trigger_set_state(struct iio_trigger *trig,
>
^ permalink raw reply [flat|nested] 13+ messages in thread
end of thread, other threads:[~2022-03-27 15:58 UTC | newest]
Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-18 7:09 [PATCH] iio:imu:bmi160: disable regulator in error path Tong Zhang
2022-03-18 14:11 ` Andy Shevchenko
2022-03-19 16:20 ` Jonathan Cameron
2022-03-19 19:33 ` Tong Zhang
2022-03-19 19:34 ` [PATCH v2] " Tong Zhang
2022-03-21 8:27 ` Andy Shevchenko
2022-03-21 15:53 ` Tong Zhang
2022-03-21 16:22 ` Andy Shevchenko
2022-03-27 15:51 ` Jonathan Cameron
2022-03-27 15:40 ` [PATCH v3] " Tong Zhang
2022-03-27 15:53 ` Jonathan Cameron
2022-03-27 15:58 ` Tong Zhang
2022-03-27 16:02 ` Jonathan Cameron
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).