All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v3 1/4] iio: imu: inv_mpu6050: fix error path not turning chip back off
@ 2018-04-17  8:07 Jean-Baptiste Maneyrol
  2018-04-17  8:07 ` [PATCH v3 2/4] iio: imu: inv_mpu6050: use devm_* at init and delete remove Jean-Baptiste Maneyrol
                   ` (3 more replies)
  0 siblings, 4 replies; 9+ messages in thread
From: Jean-Baptiste Maneyrol @ 2018-04-17  8:07 UTC (permalink / raw)
  To: linux-iio; +Cc: Jean-Baptiste Maneyrol

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.
---
 drivers/iio/imu/inv_mpu6050/inv_mpu_core.c    | 12 ++++++---
 drivers/iio/imu/inv_mpu6050/inv_mpu_trigger.c | 35 ++++++++++++++++++---------
 2 files changed, 32 insertions(+), 15 deletions(-)

diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c b/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c
index 20b94d9..ba2f08e 100644
--- a/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c
+++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c
@@ -268,27 +268,31 @@ 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;
 
 	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 result;
+
+error_power_off:
+	inv_mpu6050_set_power_itg(st, false);
+	return result;
 }
 
 static int inv_mpu6050_sensor_set(struct inv_mpu6050_state  *st, int reg,
diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_trigger.c b/drivers/iio/imu/inv_mpu6050/inv_mpu_trigger.c
index f963f9f..27aa976 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;
 }
 
 /**
-- 
2.7.4


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH v3 2/4] iio: imu: inv_mpu6050: use devm_* at init and delete remove
  2018-04-17  8:07 [PATCH v3 1/4] iio: imu: inv_mpu6050: fix error path not turning chip back off Jean-Baptiste Maneyrol
@ 2018-04-17  8:07 ` Jean-Baptiste Maneyrol
  2018-04-21 15:08   ` Jonathan Cameron
  2018-04-17  8:07 ` [PATCH v3 3/4] iio: imu: inv_mpu6050: clean read raw by factorizing out raw data Jean-Baptiste Maneyrol
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 9+ messages in thread
From: Jean-Baptiste Maneyrol @ 2018-04-17  8:07 UTC (permalink / raw)
  To: linux-iio; +Cc: Jean-Baptiste Maneyrol

Use devm_* for iio_triggered_buffer_setup, iio_device_register,
iio_trigger_register. Delete unneeded inv_mpu6050_remove_trigger,
inv_mpu_core_remove, and inv_mpu_remove for spi driver.
---
 drivers/iio/imu/inv_mpu6050/inv_mpu_core.c    | 32 ++++++---------------------
 drivers/iio/imu/inv_mpu6050/inv_mpu_i2c.c     | 12 ++++------
 drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h     |  2 --
 drivers/iio/imu/inv_mpu6050/inv_mpu_spi.c     |  6 -----
 drivers/iio/imu/inv_mpu6050/inv_mpu_trigger.c |  7 +-----
 5 files changed, 12 insertions(+), 47 deletions(-)

diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c b/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c
index ba2f08e..996e68e 100644
--- a/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c
+++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c
@@ -950,10 +950,10 @@ int inv_mpu_core_probe(struct regmap *regmap, int irq, const char *name,
 	indio_dev->info = &mpu_info;
 	indio_dev->modes = INDIO_BUFFER_TRIGGERED;
 
-	result = iio_triggered_buffer_setup(indio_dev,
-					    inv_mpu6050_irq_handler,
-					    inv_mpu6050_read_fifo,
-					    NULL);
+	result = devm_iio_triggered_buffer_setup(dev, indio_dev,
+						 inv_mpu6050_irq_handler,
+						 inv_mpu6050_read_fifo,
+						 NULL);
 	if (result) {
 		dev_err(dev, "configure buffer fail %d\n", result);
 		return result;
@@ -961,39 +961,21 @@ int inv_mpu_core_probe(struct regmap *regmap, int irq, const char *name,
 	result = inv_mpu6050_probe_trigger(indio_dev);
 	if (result) {
 		dev_err(dev, "trigger probe fail %d\n", result);
-		goto out_unreg_ring;
+		return result;
 	}
 
 	INIT_KFIFO(st->timestamps);
 	spin_lock_init(&st->time_stamp_lock);
-	result = iio_device_register(indio_dev);
+	result = devm_iio_device_register(dev, indio_dev);
 	if (result) {
 		dev_err(dev, "IIO register fail %d\n", result);
-		goto out_remove_trigger;
+		return result;
 	}
 
 	return 0;
-
-out_remove_trigger:
-	inv_mpu6050_remove_trigger(st);
-out_unreg_ring:
-	iio_triggered_buffer_cleanup(indio_dev);
-	return result;
 }
 EXPORT_SYMBOL_GPL(inv_mpu_core_probe);
 
-int inv_mpu_core_remove(struct device  *dev)
-{
-	struct iio_dev *indio_dev = dev_get_drvdata(dev);
-
-	iio_device_unregister(indio_dev);
-	inv_mpu6050_remove_trigger(iio_priv(indio_dev));
-	iio_triggered_buffer_cleanup(indio_dev);
-
-	return 0;
-}
-EXPORT_SYMBOL_GPL(inv_mpu_core_remove);
-
 #ifdef CONFIG_PM_SLEEP
 
 static int inv_mpu_resume(struct device *dev)
diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_i2c.c b/drivers/iio/imu/inv_mpu6050/inv_mpu_i2c.c
index f70e7b9..89ff3e0 100644
--- a/drivers/iio/imu/inv_mpu6050/inv_mpu_i2c.c
+++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_i2c.c
@@ -137,14 +137,12 @@ static int inv_mpu_probe(struct i2c_client *client,
 				 1, 0, I2C_MUX_LOCKED | I2C_MUX_GATE,
 				 inv_mpu6050_select_bypass,
 				 inv_mpu6050_deselect_bypass);
-	if (!st->muxc) {
-		result = -ENOMEM;
-		goto out_unreg_device;
-	}
+	if (!st->muxc)
+		return -ENOMEM;
 	st->muxc->priv = dev_get_drvdata(&client->dev);
 	result = i2c_mux_add_adapter(st->muxc, 0, 0, 0);
 	if (result)
-		goto out_unreg_device;
+		return result;
 
 	result = inv_mpu_acpi_create_mux_client(client);
 	if (result)
@@ -154,8 +152,6 @@ static int inv_mpu_probe(struct i2c_client *client,
 
 out_del_mux:
 	i2c_mux_del_adapters(st->muxc);
-out_unreg_device:
-	inv_mpu_core_remove(&client->dev);
 	return result;
 }
 
@@ -167,7 +163,7 @@ static int inv_mpu_remove(struct i2c_client *client)
 	inv_mpu_acpi_delete_mux_client(client);
 	i2c_mux_del_adapters(st->muxc);
 
-	return inv_mpu_core_remove(&client->dev);
+	return 0;
 }
 
 /*
diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h b/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h
index d476dc3..3122d3e 100644
--- a/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h
+++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h
@@ -290,7 +290,6 @@ enum inv_mpu6050_clock_sel_e {
 irqreturn_t inv_mpu6050_irq_handler(int irq, void *p);
 irqreturn_t inv_mpu6050_read_fifo(int irq, void *p);
 int inv_mpu6050_probe_trigger(struct iio_dev *indio_dev);
-void inv_mpu6050_remove_trigger(struct inv_mpu6050_state *st);
 int inv_reset_fifo(struct iio_dev *indio_dev);
 int inv_mpu6050_switch_engine(struct inv_mpu6050_state *st, bool en, u32 mask);
 int inv_mpu6050_write_reg(struct inv_mpu6050_state *st, int reg, u8 val);
@@ -299,5 +298,4 @@ int inv_mpu_acpi_create_mux_client(struct i2c_client *client);
 void inv_mpu_acpi_delete_mux_client(struct i2c_client *client);
 int inv_mpu_core_probe(struct regmap *regmap, int irq, const char *name,
 		int (*inv_mpu_bus_setup)(struct iio_dev *), int chip_type);
-int inv_mpu_core_remove(struct device *dev);
 extern const struct dev_pm_ops inv_mpu_pmops;
diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_spi.c b/drivers/iio/imu/inv_mpu6050/inv_mpu_spi.c
index a7b0f15..fe0bf5a 100644
--- a/drivers/iio/imu/inv_mpu6050/inv_mpu_spi.c
+++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_spi.c
@@ -69,11 +69,6 @@ static int inv_mpu_probe(struct spi_device *spi)
 				  inv_mpu_i2c_disable, chip_type);
 }
 
-static int inv_mpu_remove(struct spi_device *spi)
-{
-	return inv_mpu_core_remove(&spi->dev);
-}
-
 /*
  * device id table is used to identify what device can be
  * supported by this driver
@@ -98,7 +93,6 @@ MODULE_DEVICE_TABLE(acpi, inv_acpi_match);
 
 static struct spi_driver inv_mpu_driver = {
 	.probe		=	inv_mpu_probe,
-	.remove		=	inv_mpu_remove,
 	.id_table	=	inv_mpu_id,
 	.driver = {
 		.acpi_match_table = ACPI_PTR(inv_acpi_match),
diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_trigger.c b/drivers/iio/imu/inv_mpu6050/inv_mpu_trigger.c
index 27aa976..fe48292 100644
--- a/drivers/iio/imu/inv_mpu6050/inv_mpu_trigger.c
+++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_trigger.c
@@ -154,7 +154,7 @@ int inv_mpu6050_probe_trigger(struct iio_dev *indio_dev)
 	st->trig->ops = &inv_mpu_trigger_ops;
 	iio_trigger_set_drvdata(st->trig, indio_dev);
 
-	ret = iio_trigger_register(st->trig);
+	ret = devm_iio_trigger_register(&indio_dev->dev, st->trig);
 	if (ret)
 		return ret;
 
@@ -162,8 +162,3 @@ int inv_mpu6050_probe_trigger(struct iio_dev *indio_dev)
 
 	return 0;
 }
-
-void inv_mpu6050_remove_trigger(struct inv_mpu6050_state *st)
-{
-	iio_trigger_unregister(st->trig);
-}
-- 
2.7.4


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH v3 3/4] iio: imu: inv_mpu6050: clean read raw by factorizing out raw data
  2018-04-17  8:07 [PATCH v3 1/4] iio: imu: inv_mpu6050: fix error path not turning chip back off Jean-Baptiste Maneyrol
  2018-04-17  8:07 ` [PATCH v3 2/4] iio: imu: inv_mpu6050: use devm_* at init and delete remove Jean-Baptiste Maneyrol
@ 2018-04-17  8:07 ` Jean-Baptiste Maneyrol
  2018-04-21 15:10   ` Jonathan Cameron
  2018-04-17  8:07 ` [PATCH v3 4/4] iio: imu: inv_mpu6050: clean read channel data error path Jean-Baptiste Maneyrol
  2018-04-21 15:07 ` [PATCH v3 1/4] iio: imu: inv_mpu6050: fix error path not turning chip back off Jonathan Cameron
  3 siblings, 1 reply; 9+ messages in thread
From: Jean-Baptiste Maneyrol @ 2018-04-17  8:07 UTC (permalink / raw)
  To: linux-iio; +Cc: Jean-Baptiste Maneyrol

Factorize reading channel data in its own function.
---
 drivers/iio/imu/inv_mpu6050/inv_mpu_core.c | 116 +++++++++++++++--------------
 1 file changed, 62 insertions(+), 54 deletions(-)

diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c b/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c
index 996e68e..a0cecd9 100644
--- a/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c
+++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c
@@ -324,6 +324,67 @@ static int inv_mpu6050_sensor_show(struct inv_mpu6050_state  *st, int reg,
 	return IIO_VAL_INT;
 }
 
+static int inv_mpu6050_read_channel_data(struct iio_dev *indio_dev,
+					 struct iio_chan_spec const *chan,
+					 int *val)
+{
+	struct inv_mpu6050_state *st = iio_priv(indio_dev);
+	int result;
+	int ret = IIO_VAL_INT;
+
+	result = iio_device_claim_direct_mode(indio_dev);
+	if (result)
+		return result;
+	result = inv_mpu6050_set_power_itg(st, true);
+	if (result)
+		goto error_release;
+
+	switch (chan->type) {
+	case IIO_ANGL_VEL:
+		result = inv_mpu6050_switch_engine(st, true,
+				INV_MPU6050_BIT_PWR_GYRO_STBY);
+		if (result)
+			goto error_power_off;
+		ret = inv_mpu6050_sensor_show(st, st->reg->raw_gyro,
+					      chan->channel2, val);
+		result = inv_mpu6050_switch_engine(st, false,
+				INV_MPU6050_BIT_PWR_GYRO_STBY);
+		if (result)
+			goto error_power_off;
+		break;
+	case IIO_ACCEL:
+		result = inv_mpu6050_switch_engine(st, true,
+				INV_MPU6050_BIT_PWR_ACCL_STBY);
+		if (result)
+			goto error_power_off;
+		ret = inv_mpu6050_sensor_show(st, st->reg->raw_accl,
+					      chan->channel2, val);
+		result = inv_mpu6050_switch_engine(st, false,
+				INV_MPU6050_BIT_PWR_ACCL_STBY);
+		if (result)
+			goto error_power_off;
+		break;
+	case IIO_TEMP:
+		/* wait for stablization */
+		msleep(INV_MPU6050_SENSOR_UP_TIME);
+		ret = inv_mpu6050_sensor_show(st, st->reg->temperature,
+					      IIO_MOD_X, val);
+		break;
+	default:
+		ret = -EINVAL;
+		break;
+	}
+
+error_power_off:
+	result |= inv_mpu6050_set_power_itg(st, false);
+error_release:
+	iio_device_release_direct_mode(indio_dev);
+	if (result)
+		return result;
+
+	return ret;
+}
+
 static int
 inv_mpu6050_read_raw(struct iio_dev *indio_dev,
 		     struct iio_chan_spec const *chan,
@@ -334,63 +395,10 @@ inv_mpu6050_read_raw(struct iio_dev *indio_dev,
 
 	switch (mask) {
 	case IIO_CHAN_INFO_RAW:
-	{
-		int result;
-
-		ret = IIO_VAL_INT;
 		mutex_lock(&st->lock);
-		result = iio_device_claim_direct_mode(indio_dev);
-		if (result)
-			goto error_read_raw_unlock;
-		result = inv_mpu6050_set_power_itg(st, true);
-		if (result)
-			goto error_read_raw_release;
-		switch (chan->type) {
-		case IIO_ANGL_VEL:
-			result = inv_mpu6050_switch_engine(st, true,
-					INV_MPU6050_BIT_PWR_GYRO_STBY);
-			if (result)
-				goto error_read_raw_power_off;
-			ret = inv_mpu6050_sensor_show(st, st->reg->raw_gyro,
-						      chan->channel2, val);
-			result = inv_mpu6050_switch_engine(st, false,
-					INV_MPU6050_BIT_PWR_GYRO_STBY);
-			if (result)
-				goto error_read_raw_power_off;
-			break;
-		case IIO_ACCEL:
-			result = inv_mpu6050_switch_engine(st, true,
-					INV_MPU6050_BIT_PWR_ACCL_STBY);
-			if (result)
-				goto error_read_raw_power_off;
-			ret = inv_mpu6050_sensor_show(st, st->reg->raw_accl,
-						      chan->channel2, val);
-			result = inv_mpu6050_switch_engine(st, false,
-					INV_MPU6050_BIT_PWR_ACCL_STBY);
-			if (result)
-				goto error_read_raw_power_off;
-			break;
-		case IIO_TEMP:
-			/* wait for stablization */
-			msleep(INV_MPU6050_SENSOR_UP_TIME);
-			ret = inv_mpu6050_sensor_show(st, st->reg->temperature,
-						IIO_MOD_X, val);
-			break;
-		default:
-			ret = -EINVAL;
-			break;
-		}
-error_read_raw_power_off:
-		result |= inv_mpu6050_set_power_itg(st, false);
-error_read_raw_release:
-		iio_device_release_direct_mode(indio_dev);
-error_read_raw_unlock:
+		ret = inv_mpu6050_read_channel_data(indio_dev, chan, val);
 		mutex_unlock(&st->lock);
-		if (result)
-			return result;
-
 		return ret;
-	}
 	case IIO_CHAN_INFO_SCALE:
 		switch (chan->type) {
 		case IIO_ANGL_VEL:
-- 
2.7.4


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH v3 4/4] iio: imu: inv_mpu6050: clean read channel data error path
  2018-04-17  8:07 [PATCH v3 1/4] iio: imu: inv_mpu6050: fix error path not turning chip back off Jean-Baptiste Maneyrol
  2018-04-17  8:07 ` [PATCH v3 2/4] iio: imu: inv_mpu6050: use devm_* at init and delete remove Jean-Baptiste Maneyrol
  2018-04-17  8:07 ` [PATCH v3 3/4] iio: imu: inv_mpu6050: clean read raw by factorizing out raw data Jean-Baptiste Maneyrol
@ 2018-04-17  8:07 ` Jean-Baptiste Maneyrol
  2018-04-21 15:11   ` Jonathan Cameron
  2018-04-21 15:07 ` [PATCH v3 1/4] iio: imu: inv_mpu6050: fix error path not turning chip back off Jonathan Cameron
  3 siblings, 1 reply; 9+ messages in thread
From: Jean-Baptiste Maneyrol @ 2018-04-17  8:07 UTC (permalink / raw)
  To: linux-iio; +Cc: Jean-Baptiste Maneyrol

---
 drivers/iio/imu/inv_mpu6050/inv_mpu_core.c | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)

diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c b/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c
index a0cecd9..b842caf 100644
--- a/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c
+++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c
@@ -330,7 +330,7 @@ static int inv_mpu6050_read_channel_data(struct iio_dev *indio_dev,
 {
 	struct inv_mpu6050_state *st = iio_priv(indio_dev);
 	int result;
-	int ret = IIO_VAL_INT;
+	int ret;
 
 	result = iio_device_claim_direct_mode(indio_dev);
 	if (result)
@@ -375,14 +375,18 @@ static int inv_mpu6050_read_channel_data(struct iio_dev *indio_dev,
 		break;
 	}
 
-error_power_off:
-	result |= inv_mpu6050_set_power_itg(st, false);
-error_release:
-	iio_device_release_direct_mode(indio_dev);
+	result = inv_mpu6050_set_power_itg(st, false);
 	if (result)
-		return result;
+		goto error_power_off;
+	iio_device_release_direct_mode(indio_dev);
 
 	return ret;
+
+error_power_off:
+	inv_mpu6050_set_power_itg(st, false);
+error_release:
+	iio_device_release_direct_mode(indio_dev);
+	return result;
 }
 
 static int
-- 
2.7.4


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH v3 1/4] iio: imu: inv_mpu6050: fix error path not turning chip back off
  2018-04-17  8:07 [PATCH v3 1/4] iio: imu: inv_mpu6050: fix error path not turning chip back off Jean-Baptiste Maneyrol
                   ` (2 preceding siblings ...)
  2018-04-17  8:07 ` [PATCH v3 4/4] iio: imu: inv_mpu6050: clean read channel data error path Jean-Baptiste Maneyrol
@ 2018-04-21 15:07 ` Jonathan Cameron
  2018-04-23 10:29   ` Jean-Baptiste Maneyrol
  3 siblings, 1 reply; 9+ messages in thread
From: Jonathan Cameron @ 2018-04-21 15:07 UTC (permalink / raw)
  To: Jean-Baptiste Maneyrol; +Cc: linux-iio

On Tue, 17 Apr 2018 10:07:19 +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.
No sign off so I can't apply.

Also a minor thing I noticed inline (unconnected to the patch)

Thanks,

Jonathan

> ---
>  drivers/iio/imu/inv_mpu6050/inv_mpu_core.c    | 12 ++++++---
>  drivers/iio/imu/inv_mpu6050/inv_mpu_trigger.c | 35 ++++++++++++++++++---------
>  2 files changed, 32 insertions(+), 15 deletions(-)
> 
> diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c b/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c
> index 20b94d9..ba2f08e 100644
> --- a/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c
> +++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c
> @@ -268,27 +268,31 @@ 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;
>  
>  	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 result;

Whilst you are here why not combine the two lines
above and avoid assigning result...

> +
> +error_power_off:
> +	inv_mpu6050_set_power_itg(st, false);
> +	return result;
>  }
>  
>  static int inv_mpu6050_sensor_set(struct inv_mpu6050_state  *st, int reg,
> diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_trigger.c b/drivers/iio/imu/inv_mpu6050/inv_mpu_trigger.c
> index f963f9f..27aa976 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;
>  }
>  
>  /**


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH v3 2/4] iio: imu: inv_mpu6050: use devm_* at init and delete remove
  2018-04-17  8:07 ` [PATCH v3 2/4] iio: imu: inv_mpu6050: use devm_* at init and delete remove Jean-Baptiste Maneyrol
@ 2018-04-21 15:08   ` Jonathan Cameron
  0 siblings, 0 replies; 9+ messages in thread
From: Jonathan Cameron @ 2018-04-21 15:08 UTC (permalink / raw)
  To: Jean-Baptiste Maneyrol; +Cc: linux-iio

On Tue, 17 Apr 2018 10:07:20 +0200
Jean-Baptiste Maneyrol <jmaneyrol@invensense.com> wrote:

> Use devm_* for iio_triggered_buffer_setup, iio_device_register,
> iio_trigger_register. Delete unneeded inv_mpu6050_remove_trigger,
> inv_mpu_core_remove, and inv_mpu_remove for spi driver.
Again, signed-off-by missing...

Otherwise this looks fine

Jonathan

> ---
>  drivers/iio/imu/inv_mpu6050/inv_mpu_core.c    | 32 ++++++---------------------
>  drivers/iio/imu/inv_mpu6050/inv_mpu_i2c.c     | 12 ++++------
>  drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h     |  2 --
>  drivers/iio/imu/inv_mpu6050/inv_mpu_spi.c     |  6 -----
>  drivers/iio/imu/inv_mpu6050/inv_mpu_trigger.c |  7 +-----
>  5 files changed, 12 insertions(+), 47 deletions(-)
> 
> diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c b/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c
> index ba2f08e..996e68e 100644
> --- a/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c
> +++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c
> @@ -950,10 +950,10 @@ int inv_mpu_core_probe(struct regmap *regmap, int irq, const char *name,
>  	indio_dev->info = &mpu_info;
>  	indio_dev->modes = INDIO_BUFFER_TRIGGERED;
>  
> -	result = iio_triggered_buffer_setup(indio_dev,
> -					    inv_mpu6050_irq_handler,
> -					    inv_mpu6050_read_fifo,
> -					    NULL);
> +	result = devm_iio_triggered_buffer_setup(dev, indio_dev,
> +						 inv_mpu6050_irq_handler,
> +						 inv_mpu6050_read_fifo,
> +						 NULL);
>  	if (result) {
>  		dev_err(dev, "configure buffer fail %d\n", result);
>  		return result;
> @@ -961,39 +961,21 @@ int inv_mpu_core_probe(struct regmap *regmap, int irq, const char *name,
>  	result = inv_mpu6050_probe_trigger(indio_dev);
>  	if (result) {
>  		dev_err(dev, "trigger probe fail %d\n", result);
> -		goto out_unreg_ring;
> +		return result;
>  	}
>  
>  	INIT_KFIFO(st->timestamps);
>  	spin_lock_init(&st->time_stamp_lock);
> -	result = iio_device_register(indio_dev);
> +	result = devm_iio_device_register(dev, indio_dev);
>  	if (result) {
>  		dev_err(dev, "IIO register fail %d\n", result);
> -		goto out_remove_trigger;
> +		return result;
>  	}
>  
>  	return 0;
> -
> -out_remove_trigger:
> -	inv_mpu6050_remove_trigger(st);
> -out_unreg_ring:
> -	iio_triggered_buffer_cleanup(indio_dev);
> -	return result;
>  }
>  EXPORT_SYMBOL_GPL(inv_mpu_core_probe);
>  
> -int inv_mpu_core_remove(struct device  *dev)
> -{
> -	struct iio_dev *indio_dev = dev_get_drvdata(dev);
> -
> -	iio_device_unregister(indio_dev);
> -	inv_mpu6050_remove_trigger(iio_priv(indio_dev));
> -	iio_triggered_buffer_cleanup(indio_dev);
> -
> -	return 0;
> -}
> -EXPORT_SYMBOL_GPL(inv_mpu_core_remove);
> -
>  #ifdef CONFIG_PM_SLEEP
>  
>  static int inv_mpu_resume(struct device *dev)
> diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_i2c.c b/drivers/iio/imu/inv_mpu6050/inv_mpu_i2c.c
> index f70e7b9..89ff3e0 100644
> --- a/drivers/iio/imu/inv_mpu6050/inv_mpu_i2c.c
> +++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_i2c.c
> @@ -137,14 +137,12 @@ static int inv_mpu_probe(struct i2c_client *client,
>  				 1, 0, I2C_MUX_LOCKED | I2C_MUX_GATE,
>  				 inv_mpu6050_select_bypass,
>  				 inv_mpu6050_deselect_bypass);
> -	if (!st->muxc) {
> -		result = -ENOMEM;
> -		goto out_unreg_device;
> -	}
> +	if (!st->muxc)
> +		return -ENOMEM;
>  	st->muxc->priv = dev_get_drvdata(&client->dev);
>  	result = i2c_mux_add_adapter(st->muxc, 0, 0, 0);
>  	if (result)
> -		goto out_unreg_device;
> +		return result;
>  
>  	result = inv_mpu_acpi_create_mux_client(client);
>  	if (result)
> @@ -154,8 +152,6 @@ static int inv_mpu_probe(struct i2c_client *client,
>  
>  out_del_mux:
>  	i2c_mux_del_adapters(st->muxc);
> -out_unreg_device:
> -	inv_mpu_core_remove(&client->dev);
>  	return result;
>  }
>  
> @@ -167,7 +163,7 @@ static int inv_mpu_remove(struct i2c_client *client)
>  	inv_mpu_acpi_delete_mux_client(client);
>  	i2c_mux_del_adapters(st->muxc);
>  
> -	return inv_mpu_core_remove(&client->dev);
> +	return 0;
>  }
>  
>  /*
> diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h b/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h
> index d476dc3..3122d3e 100644
> --- a/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h
> +++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h
> @@ -290,7 +290,6 @@ enum inv_mpu6050_clock_sel_e {
>  irqreturn_t inv_mpu6050_irq_handler(int irq, void *p);
>  irqreturn_t inv_mpu6050_read_fifo(int irq, void *p);
>  int inv_mpu6050_probe_trigger(struct iio_dev *indio_dev);
> -void inv_mpu6050_remove_trigger(struct inv_mpu6050_state *st);
>  int inv_reset_fifo(struct iio_dev *indio_dev);
>  int inv_mpu6050_switch_engine(struct inv_mpu6050_state *st, bool en, u32 mask);
>  int inv_mpu6050_write_reg(struct inv_mpu6050_state *st, int reg, u8 val);
> @@ -299,5 +298,4 @@ int inv_mpu_acpi_create_mux_client(struct i2c_client *client);
>  void inv_mpu_acpi_delete_mux_client(struct i2c_client *client);
>  int inv_mpu_core_probe(struct regmap *regmap, int irq, const char *name,
>  		int (*inv_mpu_bus_setup)(struct iio_dev *), int chip_type);
> -int inv_mpu_core_remove(struct device *dev);
>  extern const struct dev_pm_ops inv_mpu_pmops;
> diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_spi.c b/drivers/iio/imu/inv_mpu6050/inv_mpu_spi.c
> index a7b0f15..fe0bf5a 100644
> --- a/drivers/iio/imu/inv_mpu6050/inv_mpu_spi.c
> +++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_spi.c
> @@ -69,11 +69,6 @@ static int inv_mpu_probe(struct spi_device *spi)
>  				  inv_mpu_i2c_disable, chip_type);
>  }
>  
> -static int inv_mpu_remove(struct spi_device *spi)
> -{
> -	return inv_mpu_core_remove(&spi->dev);
> -}
> -
>  /*
>   * device id table is used to identify what device can be
>   * supported by this driver
> @@ -98,7 +93,6 @@ MODULE_DEVICE_TABLE(acpi, inv_acpi_match);
>  
>  static struct spi_driver inv_mpu_driver = {
>  	.probe		=	inv_mpu_probe,
> -	.remove		=	inv_mpu_remove,
>  	.id_table	=	inv_mpu_id,
>  	.driver = {
>  		.acpi_match_table = ACPI_PTR(inv_acpi_match),
> diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_trigger.c b/drivers/iio/imu/inv_mpu6050/inv_mpu_trigger.c
> index 27aa976..fe48292 100644
> --- a/drivers/iio/imu/inv_mpu6050/inv_mpu_trigger.c
> +++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_trigger.c
> @@ -154,7 +154,7 @@ int inv_mpu6050_probe_trigger(struct iio_dev *indio_dev)
>  	st->trig->ops = &inv_mpu_trigger_ops;
>  	iio_trigger_set_drvdata(st->trig, indio_dev);
>  
> -	ret = iio_trigger_register(st->trig);
> +	ret = devm_iio_trigger_register(&indio_dev->dev, st->trig);
>  	if (ret)
>  		return ret;
>  
> @@ -162,8 +162,3 @@ int inv_mpu6050_probe_trigger(struct iio_dev *indio_dev)
>  
>  	return 0;
>  }
> -
> -void inv_mpu6050_remove_trigger(struct inv_mpu6050_state *st)
> -{
> -	iio_trigger_unregister(st->trig);
> -}


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH v3 3/4] iio: imu: inv_mpu6050: clean read raw by factorizing out raw data
  2018-04-17  8:07 ` [PATCH v3 3/4] iio: imu: inv_mpu6050: clean read raw by factorizing out raw data Jean-Baptiste Maneyrol
@ 2018-04-21 15:10   ` Jonathan Cameron
  0 siblings, 0 replies; 9+ messages in thread
From: Jonathan Cameron @ 2018-04-21 15:10 UTC (permalink / raw)
  To: Jean-Baptiste Maneyrol; +Cc: linux-iio

On Tue, 17 Apr 2018 10:07:21 +0200
Jean-Baptiste Maneyrol <jmaneyrol@invensense.com> wrote:

> Factorize reading channel data in its own function.
Good patch, no signed-off-by...

> ---
>  drivers/iio/imu/inv_mpu6050/inv_mpu_core.c | 116 +++++++++++++++--------------
>  1 file changed, 62 insertions(+), 54 deletions(-)
> 
> diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c b/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c
> index 996e68e..a0cecd9 100644
> --- a/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c
> +++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c
> @@ -324,6 +324,67 @@ static int inv_mpu6050_sensor_show(struct inv_mpu6050_state  *st, int reg,
>  	return IIO_VAL_INT;
>  }
>  
> +static int inv_mpu6050_read_channel_data(struct iio_dev *indio_dev,
> +					 struct iio_chan_spec const *chan,
> +					 int *val)
> +{
> +	struct inv_mpu6050_state *st = iio_priv(indio_dev);
> +	int result;
> +	int ret = IIO_VAL_INT;
> +
> +	result = iio_device_claim_direct_mode(indio_dev);
> +	if (result)
> +		return result;
> +	result = inv_mpu6050_set_power_itg(st, true);
> +	if (result)
> +		goto error_release;
> +
> +	switch (chan->type) {
> +	case IIO_ANGL_VEL:
> +		result = inv_mpu6050_switch_engine(st, true,
> +				INV_MPU6050_BIT_PWR_GYRO_STBY);
> +		if (result)
> +			goto error_power_off;
> +		ret = inv_mpu6050_sensor_show(st, st->reg->raw_gyro,
> +					      chan->channel2, val);
> +		result = inv_mpu6050_switch_engine(st, false,
> +				INV_MPU6050_BIT_PWR_GYRO_STBY);
> +		if (result)
> +			goto error_power_off;
> +		break;
> +	case IIO_ACCEL:
> +		result = inv_mpu6050_switch_engine(st, true,
> +				INV_MPU6050_BIT_PWR_ACCL_STBY);
> +		if (result)
> +			goto error_power_off;
> +		ret = inv_mpu6050_sensor_show(st, st->reg->raw_accl,
> +					      chan->channel2, val);
> +		result = inv_mpu6050_switch_engine(st, false,
> +				INV_MPU6050_BIT_PWR_ACCL_STBY);
> +		if (result)
> +			goto error_power_off;
> +		break;
> +	case IIO_TEMP:
> +		/* wait for stablization */
> +		msleep(INV_MPU6050_SENSOR_UP_TIME);
> +		ret = inv_mpu6050_sensor_show(st, st->reg->temperature,
> +					      IIO_MOD_X, val);
> +		break;
> +	default:
> +		ret = -EINVAL;
> +		break;
> +	}
> +
> +error_power_off:
> +	result |= inv_mpu6050_set_power_itg(st, false);
> +error_release:
> +	iio_device_release_direct_mode(indio_dev);
> +	if (result)
> +		return result;
> +
> +	return ret;
> +}
> +
>  static int
>  inv_mpu6050_read_raw(struct iio_dev *indio_dev,
>  		     struct iio_chan_spec const *chan,
> @@ -334,63 +395,10 @@ inv_mpu6050_read_raw(struct iio_dev *indio_dev,
>  
>  	switch (mask) {
>  	case IIO_CHAN_INFO_RAW:
> -	{
> -		int result;
> -
> -		ret = IIO_VAL_INT;
>  		mutex_lock(&st->lock);
> -		result = iio_device_claim_direct_mode(indio_dev);
> -		if (result)
> -			goto error_read_raw_unlock;
> -		result = inv_mpu6050_set_power_itg(st, true);
> -		if (result)
> -			goto error_read_raw_release;
> -		switch (chan->type) {
> -		case IIO_ANGL_VEL:
> -			result = inv_mpu6050_switch_engine(st, true,
> -					INV_MPU6050_BIT_PWR_GYRO_STBY);
> -			if (result)
> -				goto error_read_raw_power_off;
> -			ret = inv_mpu6050_sensor_show(st, st->reg->raw_gyro,
> -						      chan->channel2, val);
> -			result = inv_mpu6050_switch_engine(st, false,
> -					INV_MPU6050_BIT_PWR_GYRO_STBY);
> -			if (result)
> -				goto error_read_raw_power_off;
> -			break;
> -		case IIO_ACCEL:
> -			result = inv_mpu6050_switch_engine(st, true,
> -					INV_MPU6050_BIT_PWR_ACCL_STBY);
> -			if (result)
> -				goto error_read_raw_power_off;
> -			ret = inv_mpu6050_sensor_show(st, st->reg->raw_accl,
> -						      chan->channel2, val);
> -			result = inv_mpu6050_switch_engine(st, false,
> -					INV_MPU6050_BIT_PWR_ACCL_STBY);
> -			if (result)
> -				goto error_read_raw_power_off;
> -			break;
> -		case IIO_TEMP:
> -			/* wait for stablization */
> -			msleep(INV_MPU6050_SENSOR_UP_TIME);
> -			ret = inv_mpu6050_sensor_show(st, st->reg->temperature,
> -						IIO_MOD_X, val);
> -			break;
> -		default:
> -			ret = -EINVAL;
> -			break;
> -		}
> -error_read_raw_power_off:
> -		result |= inv_mpu6050_set_power_itg(st, false);
> -error_read_raw_release:
> -		iio_device_release_direct_mode(indio_dev);
> -error_read_raw_unlock:
> +		ret = inv_mpu6050_read_channel_data(indio_dev, chan, val);
>  		mutex_unlock(&st->lock);
> -		if (result)
> -			return result;
> -
>  		return ret;
> -	}
>  	case IIO_CHAN_INFO_SCALE:
>  		switch (chan->type) {
>  		case IIO_ANGL_VEL:


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH v3 4/4] iio: imu: inv_mpu6050: clean read channel data error path
  2018-04-17  8:07 ` [PATCH v3 4/4] iio: imu: inv_mpu6050: clean read channel data error path Jean-Baptiste Maneyrol
@ 2018-04-21 15:11   ` Jonathan Cameron
  0 siblings, 0 replies; 9+ messages in thread
From: Jonathan Cameron @ 2018-04-21 15:11 UTC (permalink / raw)
  To: Jean-Baptiste Maneyrol; +Cc: linux-iio

On Tue, 17 Apr 2018 10:07:22 +0200
Jean-Baptiste Maneyrol <jmaneyrol@invensense.com> wrote:

Nice to have some description of how it was cleaned + a signed-off-by...

Jonathan

> ---
>  drivers/iio/imu/inv_mpu6050/inv_mpu_core.c | 16 ++++++++++------
>  1 file changed, 10 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c b/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c
> index a0cecd9..b842caf 100644
> --- a/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c
> +++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c
> @@ -330,7 +330,7 @@ static int inv_mpu6050_read_channel_data(struct iio_dev *indio_dev,
>  {
>  	struct inv_mpu6050_state *st = iio_priv(indio_dev);
>  	int result;
> -	int ret = IIO_VAL_INT;
> +	int ret;
>  
>  	result = iio_device_claim_direct_mode(indio_dev);
>  	if (result)
> @@ -375,14 +375,18 @@ static int inv_mpu6050_read_channel_data(struct iio_dev *indio_dev,
>  		break;
>  	}
>  
> -error_power_off:
> -	result |= inv_mpu6050_set_power_itg(st, false);
> -error_release:
> -	iio_device_release_direct_mode(indio_dev);
> +	result = inv_mpu6050_set_power_itg(st, false);
>  	if (result)
> -		return result;
> +		goto error_power_off;
> +	iio_device_release_direct_mode(indio_dev);
>  
>  	return ret;
> +
> +error_power_off:
> +	inv_mpu6050_set_power_itg(st, false);
> +error_release:
> +	iio_device_release_direct_mode(indio_dev);
> +	return result;
>  }
>  
>  static int


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH v3 1/4] iio: imu: inv_mpu6050: fix error path not turning chip back off
  2018-04-21 15:07 ` [PATCH v3 1/4] iio: imu: inv_mpu6050: fix error path not turning chip back off Jonathan Cameron
@ 2018-04-23 10:29   ` Jean-Baptiste Maneyrol
  0 siblings, 0 replies; 9+ messages in thread
From: Jean-Baptiste Maneyrol @ 2018-04-23 10:29 UTC (permalink / raw)
  To: Jonathan Cameron; +Cc: linux-iio



On 21/04/2018 17:07, Jonathan Cameron wrote:
> On Tue, 17 Apr 2018 10:07:19 +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.
> No sign off so I can't apply.
> 
> Also a minor thing I noticed inline (unconnected to the patch)
> 
> Thanks,
> 
> Jonathan

Sorry for the inconvenient, my fault. I am resending the series 
including the fix you mentioned.

JB
> 
>> ---
>>   drivers/iio/imu/inv_mpu6050/inv_mpu_core.c    | 12 ++++++---
>>   drivers/iio/imu/inv_mpu6050/inv_mpu_trigger.c | 35 ++++++++++++++++++---------
>>   2 files changed, 32 insertions(+), 15 deletions(-)
>>
>> diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c b/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c
>> index 20b94d9..ba2f08e 100644
>> --- a/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c
>> +++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c
>> @@ -268,27 +268,31 @@ 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;
>>   
>>   	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 result;
> 
> Whilst you are here why not combine the two lines
> above and avoid assigning result...
> 
>> +
>> +error_power_off:
>> +	inv_mpu6050_set_power_itg(st, false);
>> +	return result;
>>   }
>>   
>>   static int inv_mpu6050_sensor_set(struct inv_mpu6050_state  *st, int reg,
>> diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_trigger.c b/drivers/iio/imu/inv_mpu6050/inv_mpu_trigger.c
>> index f963f9f..27aa976 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;
>>   }
>>   
>>   /**
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-iio" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> 

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2018-04-23 10:29 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-04-17  8:07 [PATCH v3 1/4] iio: imu: inv_mpu6050: fix error path not turning chip back off Jean-Baptiste Maneyrol
2018-04-17  8:07 ` [PATCH v3 2/4] iio: imu: inv_mpu6050: use devm_* at init and delete remove Jean-Baptiste Maneyrol
2018-04-21 15:08   ` Jonathan Cameron
2018-04-17  8:07 ` [PATCH v3 3/4] iio: imu: inv_mpu6050: clean read raw by factorizing out raw data Jean-Baptiste Maneyrol
2018-04-21 15:10   ` Jonathan Cameron
2018-04-17  8:07 ` [PATCH v3 4/4] iio: imu: inv_mpu6050: clean read channel data error path Jean-Baptiste Maneyrol
2018-04-21 15:11   ` Jonathan Cameron
2018-04-21 15:07 ` [PATCH v3 1/4] iio: imu: inv_mpu6050: fix error path not turning chip back off Jonathan Cameron
2018-04-23 10:29   ` Jean-Baptiste Maneyrol

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.