Linux-IIO Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH v2] iio: light: cm3323: Use device-managed APIs
@ 2019-07-28 14:36 Chuhong Yuan
  2019-08-05 13:55 ` Jonathan Cameron
  0 siblings, 1 reply; 2+ messages in thread
From: Chuhong Yuan @ 2019-07-28 14:36 UTC (permalink / raw)
  To: unlisted-recipients:; (no To-header on input)
  Cc: Kevin Tsai, 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.
  - Drop the failed to register message and just
    return devm_iio_register.

 drivers/iio/light/cm3323.c | 33 +++++++++------------------------
 1 file changed, 9 insertions(+), 24 deletions(-)

diff --git a/drivers/iio/light/cm3323.c b/drivers/iio/light/cm3323.c
index 50f3438c2b49..0443861ba1ec 100644
--- a/drivers/iio/light/cm3323.c
+++ b/drivers/iio/light/cm3323.c
@@ -101,15 +101,16 @@ static int cm3323_init(struct iio_dev *indio_dev)
 	return 0;
 }
 
-static void cm3323_disable(struct iio_dev *indio_dev)
+static void cm3323_disable(void *data)
 {
 	int ret;
-	struct cm3323_data *data = iio_priv(indio_dev);
+	struct iio_dev *indio_dev = data;
+	struct cm3323_data *cm_data = iio_priv(indio_dev);
 
-	ret = i2c_smbus_write_word_data(data->client, CM3323_CMD_CONF,
+	ret = i2c_smbus_write_word_data(cm_data->client, CM3323_CMD_CONF,
 					CM3323_CONF_SD_BIT);
 	if (ret < 0)
-		dev_err(&data->client->dev, "Error writing reg_conf\n");
+		dev_err(&cm_data->client->dev, "Error writing reg_conf\n");
 }
 
 static int cm3323_set_it_bits(struct cm3323_data *data, int val, int val2)
@@ -243,26 +244,11 @@ static int cm3323_probe(struct i2c_client *client,
 		return ret;
 	}
 
-	ret = iio_device_register(indio_dev);
-	if (ret < 0) {
-		dev_err(&client->dev, "failed to register iio dev\n");
-		goto err_init;
-	}
-
-	return 0;
-err_init:
-	cm3323_disable(indio_dev);
-	return ret;
-}
-
-static int cm3323_remove(struct i2c_client *client)
-{
-	struct iio_dev *indio_dev = i2c_get_clientdata(client);
-
-	iio_device_unregister(indio_dev);
-	cm3323_disable(indio_dev);
+	ret = devm_add_action_or_reset(&client->dev, cm3323_disable, indio_dev);
+	if (ret < 0)
+		return ret;
 
-	return 0;
+	return devm_iio_device_register(&client->dev, indio_dev);
 }
 
 static const struct i2c_device_id cm3323_id[] = {
@@ -276,7 +262,6 @@ static struct i2c_driver cm3323_driver = {
 		.name = CM3323_DRV_NAME,
 	},
 	.probe		= cm3323_probe,
-	.remove		= cm3323_remove,
 	.id_table	= cm3323_id,
 };
 
-- 
2.20.1


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

* Re: [PATCH v2] iio: light: cm3323: Use device-managed APIs
  2019-07-28 14:36 [PATCH v2] iio: light: cm3323: Use device-managed APIs Chuhong Yuan
@ 2019-08-05 13:55 ` Jonathan Cameron
  0 siblings, 0 replies; 2+ messages in thread
From: Jonathan Cameron @ 2019-08-05 13:55 UTC (permalink / raw)
  To: Chuhong Yuan
  Cc: Kevin Tsai, Hartmut Knaack, Lars-Peter Clausen,
	Peter Meerwald-Stadler, linux-iio, linux-kernel, Daniel Baluta


+CC Daniel as this is one of his I think.

On Sun, 28 Jul 2019 22:36:30 +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>
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.
>   - Drop the failed to register message and just
>     return devm_iio_register.
> 
>  drivers/iio/light/cm3323.c | 33 +++++++++------------------------
>  1 file changed, 9 insertions(+), 24 deletions(-)
> 
> diff --git a/drivers/iio/light/cm3323.c b/drivers/iio/light/cm3323.c
> index 50f3438c2b49..0443861ba1ec 100644
> --- a/drivers/iio/light/cm3323.c
> +++ b/drivers/iio/light/cm3323.c
> @@ -101,15 +101,16 @@ static int cm3323_init(struct iio_dev *indio_dev)
>  	return 0;
>  }
>  
> -static void cm3323_disable(struct iio_dev *indio_dev)
> +static void cm3323_disable(void *data)
>  {
>  	int ret;
> -	struct cm3323_data *data = iio_priv(indio_dev);
> +	struct iio_dev *indio_dev = data;
> +	struct cm3323_data *cm_data = iio_priv(indio_dev);
>  
> -	ret = i2c_smbus_write_word_data(data->client, CM3323_CMD_CONF,
> +	ret = i2c_smbus_write_word_data(cm_data->client, CM3323_CMD_CONF,
>  					CM3323_CONF_SD_BIT);
>  	if (ret < 0)
> -		dev_err(&data->client->dev, "Error writing reg_conf\n");
> +		dev_err(&cm_data->client->dev, "Error writing reg_conf\n");
>  }
>  
>  static int cm3323_set_it_bits(struct cm3323_data *data, int val, int val2)
> @@ -243,26 +244,11 @@ static int cm3323_probe(struct i2c_client *client,
>  		return ret;
>  	}
>  
> -	ret = iio_device_register(indio_dev);
> -	if (ret < 0) {
> -		dev_err(&client->dev, "failed to register iio dev\n");
> -		goto err_init;
> -	}
> -
> -	return 0;
> -err_init:
> -	cm3323_disable(indio_dev);
> -	return ret;
> -}
> -
> -static int cm3323_remove(struct i2c_client *client)
> -{
> -	struct iio_dev *indio_dev = i2c_get_clientdata(client);
> -
> -	iio_device_unregister(indio_dev);
> -	cm3323_disable(indio_dev);
> +	ret = devm_add_action_or_reset(&client->dev, cm3323_disable, indio_dev);
> +	if (ret < 0)
> +		return ret;
>  
> -	return 0;
> +	return devm_iio_device_register(&client->dev, indio_dev);
>  }
>  
>  static const struct i2c_device_id cm3323_id[] = {
> @@ -276,7 +262,6 @@ static struct i2c_driver cm3323_driver = {
>  		.name = CM3323_DRV_NAME,
>  	},
>  	.probe		= cm3323_probe,
> -	.remove		= cm3323_remove,
>  	.id_table	= cm3323_id,
>  };
>  


^ 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-28 14:36 [PATCH v2] iio: light: cm3323: Use device-managed APIs Chuhong Yuan
2019-08-05 13:55 ` 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