From: Jonathan Cameron <jic23@jic23.retrosnub.co.uk>
To: Jean-Baptiste Maneyrol <jmaneyrol@invensense.com>
Cc: linux-iio@vger.kernel.org
Subject: Re: [PATCH v4 1/4] iio: imu: inv_mpu6050: fix error path not turning chip back off
Date: Sat, 28 Apr 2018 16:48:54 +0100 [thread overview]
Message-ID: <20180428164854.3b94c53f@archlinux> (raw)
In-Reply-To: <1524479613-23954-1-git-send-email-jmaneyrol@invensense.com>
On Mon, 23 Apr 2018 12:33:30 +0200
Jean-Baptiste Maneyrol <jmaneyrol@invensense.com> wrote:
> Some functions are turning the chip on and not back off in error
> path. With set_power function using a reference counter that
> would keep the chip on forever.
>
> Signed-off-by: Jean-Baptiste Maneyrol <jmaneyrol@invensense.com>
Applied to the togreg branch of iio.git and pushed out as testing
for the autobuilders to play with it.
Thanks,
Jonathan
> ---
> drivers/iio/imu/inv_mpu6050/inv_mpu_core.c | 13 ++++++----
> drivers/iio/imu/inv_mpu6050/inv_mpu_trigger.c | 35 ++++++++++++++++++---------
> 2 files changed, 32 insertions(+), 16 deletions(-)
>
> diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c b/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c
> index e73c88c..5062fbe 100644
> --- a/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c
> +++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c
> @@ -273,21 +273,21 @@ static int inv_mpu6050_init_config(struct iio_dev *indio_dev)
> d = (INV_MPU6050_FSR_2000DPS << INV_MPU6050_GYRO_CONFIG_FSR_SHIFT);
> result = regmap_write(st->map, st->reg->gyro_config, d);
> if (result)
> - return result;
> + goto error_power_off;
>
> result = inv_mpu6050_set_lpf_regs(st, INV_MPU6050_FILTER_20HZ);
> if (result)
> - return result;
> + goto error_power_off;
>
> d = INV_MPU6050_ONE_K_HZ / INV_MPU6050_INIT_FIFO_RATE - 1;
> result = regmap_write(st->map, st->reg->sample_rate_div, d);
> if (result)
> - return result;
> + goto error_power_off;
>
> d = (INV_MPU6050_FS_02G << INV_MPU6050_ACCL_CONFIG_FSR_SHIFT);
> result = regmap_write(st->map, st->reg->accl_config, d);
> if (result)
> - return result;
> + goto error_power_off;
>
> result = regmap_write(st->map, st->reg->int_pin_cfg, st->irq_mask);
> if (result)
> @@ -295,8 +295,11 @@ static int inv_mpu6050_init_config(struct iio_dev *indio_dev)
>
> memcpy(&st->chip_config, hw_info[st->chip_type].config,
> sizeof(struct inv_mpu6050_chip_config));
> - result = inv_mpu6050_set_power_itg(st, false);
>
> + return inv_mpu6050_set_power_itg(st, false);
> +
> +error_power_off:
> + inv_mpu6050_set_power_itg(st, false);
> return result;
> }
>
> diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_trigger.c b/drivers/iio/imu/inv_mpu6050/inv_mpu_trigger.c
> index b8c5584..fc8843c 100644
> --- a/drivers/iio/imu/inv_mpu6050/inv_mpu_trigger.c
> +++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_trigger.c
> @@ -53,45 +53,58 @@ static int inv_mpu6050_set_enable(struct iio_dev *indio_dev, bool enable)
> result = inv_mpu6050_switch_engine(st, true,
> INV_MPU6050_BIT_PWR_GYRO_STBY);
> if (result)
> - return result;
> + goto error_power_off;
> }
> if (st->chip_config.accl_fifo_enable) {
> result = inv_mpu6050_switch_engine(st, true,
> INV_MPU6050_BIT_PWR_ACCL_STBY);
> if (result)
> - return result;
> + goto error_gyro_off;
> }
> result = inv_reset_fifo(indio_dev);
> if (result)
> - return result;
> + goto error_accl_off;
> } else {
> result = regmap_write(st->map, st->reg->fifo_en, 0);
> if (result)
> - return result;
> + goto error_accl_off;
>
> result = regmap_write(st->map, st->reg->int_enable, 0);
> if (result)
> - return result;
> + goto error_accl_off;
>
> result = regmap_write(st->map, st->reg->user_ctrl, 0);
> if (result)
> - return result;
> + goto error_accl_off;
>
> result = inv_mpu6050_switch_engine(st, false,
> - INV_MPU6050_BIT_PWR_GYRO_STBY);
> + INV_MPU6050_BIT_PWR_ACCL_STBY);
> if (result)
> - return result;
> + goto error_accl_off;
>
> result = inv_mpu6050_switch_engine(st, false,
> - INV_MPU6050_BIT_PWR_ACCL_STBY);
> + INV_MPU6050_BIT_PWR_GYRO_STBY);
> if (result)
> - return result;
> + goto error_gyro_off;
> +
> result = inv_mpu6050_set_power_itg(st, false);
> if (result)
> - return result;
> + goto error_power_off;
> }
>
> return 0;
> +
> +error_accl_off:
> + if (st->chip_config.accl_fifo_enable)
> + inv_mpu6050_switch_engine(st, false,
> + INV_MPU6050_BIT_PWR_ACCL_STBY);
> +error_gyro_off:
> + if (st->chip_config.gyro_fifo_enable)
> + inv_mpu6050_switch_engine(st, false,
> + INV_MPU6050_BIT_PWR_GYRO_STBY);
> +error_power_off:
> + inv_mpu6050_set_power_itg(st, false);
> + return result;
> }
>
> /**
prev parent reply other threads:[~2018-04-28 15:48 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-04-23 10:33 [PATCH v4 1/4] iio: imu: inv_mpu6050: fix error path not turning chip back off Jean-Baptiste Maneyrol
2018-04-23 10:33 ` [PATCH v4 2/4] iio: imu: inv_mpu6050: use devm_* at init and delete remove Jean-Baptiste Maneyrol
2018-04-28 15:53 ` Jonathan Cameron
2018-04-23 10:33 ` [PATCH v4 3/4] iio: imu: inv_mpu6050: clean read raw by factorizing out raw data Jean-Baptiste Maneyrol
2018-04-28 15:54 ` Jonathan Cameron
2018-04-23 10:33 ` [PATCH v4 4/4] iio: imu: inv_mpu6050: clean read channel data error path Jean-Baptiste Maneyrol
2018-04-28 15:57 ` Jonathan Cameron
2018-04-28 15:48 ` Jonathan Cameron [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=20180428164854.3b94c53f@archlinux \
--to=jic23@jic23.retrosnub.co.uk \
--cc=jmaneyrol@invensense.com \
--cc=linux-iio@vger.kernel.org \
/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).