Linux-IIO Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH v2] iio: light: si1145: Use device-managed APIs
@ 2019-07-29  1:43 Chuhong Yuan
  2019-08-05 14:54 ` Jonathan Cameron
  0 siblings, 1 reply; 2+ messages in thread
From: Chuhong Yuan @ 2019-07-29  1:43 UTC (permalink / raw)
  To: unlisted-recipients:; (no To-header on input)
  Cc: Jonathan Cameron, Hartmut Knaack, Lars-Peter Clausen,
	Peter Meerwald-Stadler, linux-iio, linux-kernel, Chuhong Yuan

Use device-managed APIs to simplify the code.
The remove functions are redundant now and can
be deleted.

Signed-off-by: Chuhong Yuan <hslester96@gmail.com>
---
Changes in v2:
  - Split v1 into two patches.
  - Use devm_iio_trigger_register in probe_trigger,
    delete redundant remove_trigger.
  - Return devm_iio_device_register directly as a
    minor optimization.

 drivers/iio/light/si1145.c | 42 +++++---------------------------------
 1 file changed, 5 insertions(+), 37 deletions(-)

diff --git a/drivers/iio/light/si1145.c b/drivers/iio/light/si1145.c
index 6579d2418814..982bba0c54e7 100644
--- a/drivers/iio/light/si1145.c
+++ b/drivers/iio/light/si1145.c
@@ -1261,7 +1261,7 @@ static int si1145_probe_trigger(struct iio_dev *indio_dev)
 		return ret;
 	}
 
-	ret = iio_trigger_register(trig);
+	ret = devm_iio_trigger_register(&client->dev, trig);
 	if (ret)
 		return ret;
 
@@ -1271,16 +1271,6 @@ static int si1145_probe_trigger(struct iio_dev *indio_dev)
 	return 0;
 }
 
-static void si1145_remove_trigger(struct iio_dev *indio_dev)
-{
-	struct si1145_data *data = iio_priv(indio_dev);
-
-	if (data->trig) {
-		iio_trigger_unregister(data->trig);
-		data->trig = NULL;
-	}
-}
-
 static int si1145_probe(struct i2c_client *client,
 			const struct i2c_device_id *id)
 {
@@ -1332,7 +1322,8 @@ static int si1145_probe(struct i2c_client *client,
 	if (ret < 0)
 		return ret;
 
-	ret = iio_triggered_buffer_setup(indio_dev, NULL,
+	ret = devm_iio_triggered_buffer_setup(&client->dev,
+		indio_dev, NULL,
 		si1145_trigger_handler, &si1145_buffer_setup_ops);
 	if (ret < 0)
 		return ret;
@@ -1340,23 +1331,12 @@ static int si1145_probe(struct i2c_client *client,
 	if (client->irq) {
 		ret = si1145_probe_trigger(indio_dev);
 		if (ret < 0)
-			goto error_free_buffer;
+			return ret;
 	} else {
 		dev_info(&client->dev, "no irq, using polling\n");
 	}
 
-	ret = iio_device_register(indio_dev);
-	if (ret < 0)
-		goto error_free_trigger;
-
-	return 0;
-
-error_free_trigger:
-	si1145_remove_trigger(indio_dev);
-error_free_buffer:
-	iio_triggered_buffer_cleanup(indio_dev);
-
-	return ret;
+	return devm_iio_device_register(&client->dev, indio_dev);
 }
 
 static const struct i2c_device_id si1145_ids[] = {
@@ -1371,23 +1351,11 @@ static const struct i2c_device_id si1145_ids[] = {
 };
 MODULE_DEVICE_TABLE(i2c, si1145_ids);
 
-static int si1145_remove(struct i2c_client *client)
-{
-	struct iio_dev *indio_dev = i2c_get_clientdata(client);
-
-	iio_device_unregister(indio_dev);
-	si1145_remove_trigger(indio_dev);
-	iio_triggered_buffer_cleanup(indio_dev);
-
-	return 0;
-}
-
 static struct i2c_driver si1145_driver = {
 	.driver = {
 		.name   = "si1145",
 	},
 	.probe  = si1145_probe,
-	.remove = si1145_remove,
 	.id_table = si1145_ids,
 };
 
-- 
2.20.1


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

* Re: [PATCH v2] iio: light: si1145: Use device-managed APIs
  2019-07-29  1:43 [PATCH v2] iio: light: si1145: Use device-managed APIs Chuhong Yuan
@ 2019-08-05 14:54 ` Jonathan Cameron
  0 siblings, 0 replies; 2+ messages in thread
From: Jonathan Cameron @ 2019-08-05 14:54 UTC (permalink / raw)
  To: Chuhong Yuan
  Cc: Hartmut Knaack, Lars-Peter Clausen, Peter Meerwald-Stadler,
	linux-iio, linux-kernel

On Mon, 29 Jul 2019 09:43:01 +0800
Chuhong Yuan <hslester96@gmail.com> wrote:

> Use device-managed APIs to simplify the code.
> The remove functions are redundant now and can
> be deleted.
> 
> Signed-off-by: Chuhong Yuan <hslester96@gmail.com>

Nice little patch, thanks!

Applied to the togreg branch of iio.git and pushed out as testing for
the autobuilders to play with it.

Thanks,

Jonathan

> ---
> Changes in v2:
>   - Split v1 into two patches.
>   - Use devm_iio_trigger_register in probe_trigger,
>     delete redundant remove_trigger.
>   - Return devm_iio_device_register directly as a
>     minor optimization.
> 
>  drivers/iio/light/si1145.c | 42 +++++---------------------------------
>  1 file changed, 5 insertions(+), 37 deletions(-)
> 
> diff --git a/drivers/iio/light/si1145.c b/drivers/iio/light/si1145.c
> index 6579d2418814..982bba0c54e7 100644
> --- a/drivers/iio/light/si1145.c
> +++ b/drivers/iio/light/si1145.c
> @@ -1261,7 +1261,7 @@ static int si1145_probe_trigger(struct iio_dev *indio_dev)
>  		return ret;
>  	}
>  
> -	ret = iio_trigger_register(trig);
> +	ret = devm_iio_trigger_register(&client->dev, trig);
>  	if (ret)
>  		return ret;
>  
> @@ -1271,16 +1271,6 @@ static int si1145_probe_trigger(struct iio_dev *indio_dev)
>  	return 0;
>  }
>  
> -static void si1145_remove_trigger(struct iio_dev *indio_dev)
> -{
> -	struct si1145_data *data = iio_priv(indio_dev);
> -
> -	if (data->trig) {
> -		iio_trigger_unregister(data->trig);
> -		data->trig = NULL;
> -	}
> -}
> -
>  static int si1145_probe(struct i2c_client *client,
>  			const struct i2c_device_id *id)
>  {
> @@ -1332,7 +1322,8 @@ static int si1145_probe(struct i2c_client *client,
>  	if (ret < 0)
>  		return ret;
>  
> -	ret = iio_triggered_buffer_setup(indio_dev, NULL,
> +	ret = devm_iio_triggered_buffer_setup(&client->dev,
> +		indio_dev, NULL,
>  		si1145_trigger_handler, &si1145_buffer_setup_ops);
>  	if (ret < 0)
>  		return ret;
> @@ -1340,23 +1331,12 @@ static int si1145_probe(struct i2c_client *client,
>  	if (client->irq) {
>  		ret = si1145_probe_trigger(indio_dev);
>  		if (ret < 0)
> -			goto error_free_buffer;
> +			return ret;
>  	} else {
>  		dev_info(&client->dev, "no irq, using polling\n");
>  	}
>  
> -	ret = iio_device_register(indio_dev);
> -	if (ret < 0)
> -		goto error_free_trigger;
> -
> -	return 0;
> -
> -error_free_trigger:
> -	si1145_remove_trigger(indio_dev);
> -error_free_buffer:
> -	iio_triggered_buffer_cleanup(indio_dev);
> -
> -	return ret;
> +	return devm_iio_device_register(&client->dev, indio_dev);
>  }
>  
>  static const struct i2c_device_id si1145_ids[] = {
> @@ -1371,23 +1351,11 @@ static const struct i2c_device_id si1145_ids[] = {
>  };
>  MODULE_DEVICE_TABLE(i2c, si1145_ids);
>  
> -static int si1145_remove(struct i2c_client *client)
> -{
> -	struct iio_dev *indio_dev = i2c_get_clientdata(client);
> -
> -	iio_device_unregister(indio_dev);
> -	si1145_remove_trigger(indio_dev);
> -	iio_triggered_buffer_cleanup(indio_dev);
> -
> -	return 0;
> -}
> -
>  static struct i2c_driver si1145_driver = {
>  	.driver = {
>  		.name   = "si1145",
>  	},
>  	.probe  = si1145_probe,
> -	.remove = si1145_remove,
>  	.id_table = si1145_ids,
>  };
>  


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

end of thread, back to index

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-07-29  1:43 [PATCH v2] iio: light: si1145: Use device-managed APIs Chuhong Yuan
2019-08-05 14:54 ` Jonathan Cameron

Linux-IIO Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-iio/0 linux-iio/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-iio linux-iio/ https://lore.kernel.org/linux-iio \
		linux-iio@vger.kernel.org linux-iio@archiver.kernel.org
	public-inbox-index linux-iio


Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-iio


AGPL code for this site: git clone https://public-inbox.org/ public-inbox