diff mbox

[v4,2/4] iio: imu: inv_mpu6050: use devm_* at init and delete remove

Message ID 1524479613-23954-2-git-send-email-jmaneyrol@invensense.com (mailing list archive)
State New, archived
Headers show

Commit Message

Jean-Baptiste Maneyrol April 23, 2018, 10:33 a.m. UTC
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.

Signed-off-by: Jean-Baptiste Maneyrol <jmaneyrol@invensense.com>
---
 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(-)

Comments

Jonathan Cameron April 28, 2018, 3:53 p.m. UTC | #1
On Mon, 23 Apr 2018 12:33:31 +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.
> 
> 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    | 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 5062fbe..45f57f7 100644
> --- a/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c
> +++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c
> @@ -984,10 +984,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;
> @@ -995,39 +995,21 @@ int inv_mpu_core_probe(struct regmap *regmap, int irq, const char *name,
>  	result = inv_mpu6050_probe_trigger(indio_dev, irq_type);
>  	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 27e777c..90fdc5e 100644
> --- a/drivers/iio/imu/inv_mpu6050/inv_mpu_i2c.c
> +++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_i2c.c
> @@ -129,14 +129,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)
> @@ -146,8 +144,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;
>  }
>  
> @@ -159,7 +155,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 c8aad13..142a835 100644
> --- a/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h
> +++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h
> @@ -301,7 +301,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, int irq_type);
> -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);
> @@ -310,5 +309,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 fc8843c..8a9f869 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, int irq_type)
>  	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, int irq_type)
>  
>  	return 0;
>  }
> -
> -void inv_mpu6050_remove_trigger(struct inv_mpu6050_state *st)
> -{
> -	iio_trigger_unregister(st->trig);
> -}

--
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
diff mbox

Patch

diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c b/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c
index 5062fbe..45f57f7 100644
--- a/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c
+++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c
@@ -984,10 +984,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;
@@ -995,39 +995,21 @@  int inv_mpu_core_probe(struct regmap *regmap, int irq, const char *name,
 	result = inv_mpu6050_probe_trigger(indio_dev, irq_type);
 	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 27e777c..90fdc5e 100644
--- a/drivers/iio/imu/inv_mpu6050/inv_mpu_i2c.c
+++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_i2c.c
@@ -129,14 +129,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)
@@ -146,8 +144,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;
 }
 
@@ -159,7 +155,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 c8aad13..142a835 100644
--- a/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h
+++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h
@@ -301,7 +301,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, int irq_type);
-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);
@@ -310,5 +309,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 fc8843c..8a9f869 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, int irq_type)
 	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, int irq_type)
 
 	return 0;
 }
-
-void inv_mpu6050_remove_trigger(struct inv_mpu6050_state *st)
-{
-	iio_trigger_unregister(st->trig);
-}