linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] iio: accel: da280: convert probe to device-managed functions
@ 2021-06-28 14:17 Alexandru Ardelean
  2021-07-17 17:58 ` Jonathan Cameron
  0 siblings, 1 reply; 2+ messages in thread
From: Alexandru Ardelean @ 2021-06-28 14:17 UTC (permalink / raw)
  To: linux-iio, linux-kernel; +Cc: jic23, Alexandru Ardelean

This is another simple conversion to device-managed functions, requiring
the use of devm_iio_device_register() and moving the disabling of the
device on a devm_add_action_or_reset() hook.

The i2c_set_clientdata() can be removed, as the PM functions can work with
just the device object, to obtain the i2c_client object.

Signed-off-by: Alexandru Ardelean <aardelean@deviqon.com>
---
 drivers/iio/accel/da280.c | 26 +++++++++-----------------
 1 file changed, 9 insertions(+), 17 deletions(-)

diff --git a/drivers/iio/accel/da280.c b/drivers/iio/accel/da280.c
index 5edff9ba72da..9633bdae5fd4 100644
--- a/drivers/iio/accel/da280.c
+++ b/drivers/iio/accel/da280.c
@@ -100,6 +100,11 @@ static enum da280_chipset da280_match_acpi_device(struct device *dev)
 	return (enum da280_chipset) id->driver_data;
 }
 
+static void da280_disable(void *client)
+{
+	da280_enable(client, false);
+}
+
 static int da280_probe(struct i2c_client *client,
 			const struct i2c_device_id *id)
 {
@@ -118,7 +123,6 @@ static int da280_probe(struct i2c_client *client,
 
 	data = iio_priv(indio_dev);
 	data->client = client;
-	i2c_set_clientdata(client, indio_dev);
 
 	indio_dev->info = &da280_info;
 	indio_dev->modes = INDIO_DIRECT_MODE;
@@ -142,22 +146,11 @@ static int da280_probe(struct i2c_client *client,
 	if (ret < 0)
 		return ret;
 
-	ret = iio_device_register(indio_dev);
-	if (ret < 0) {
-		dev_err(&client->dev, "device_register failed\n");
-		da280_enable(client, false);
-	}
-
-	return ret;
-}
-
-static int da280_remove(struct i2c_client *client)
-{
-	struct iio_dev *indio_dev = i2c_get_clientdata(client);
-
-	iio_device_unregister(indio_dev);
+	ret = devm_add_action_or_reset(&client->dev, da280_disable, client);
+	if (ret)
+		return ret;
 
-	return da280_enable(client, false);
+	return devm_iio_device_register(&client->dev, indio_dev);
 }
 
 #ifdef CONFIG_PM_SLEEP
@@ -194,7 +187,6 @@ static struct i2c_driver da280_driver = {
 		.pm = &da280_pm_ops,
 	},
 	.probe		= da280_probe,
-	.remove		= da280_remove,
 	.id_table	= da280_i2c_id,
 };
 
-- 
2.31.1


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

* Re: [PATCH] iio: accel: da280: convert probe to device-managed functions
  2021-06-28 14:17 [PATCH] iio: accel: da280: convert probe to device-managed functions Alexandru Ardelean
@ 2021-07-17 17:58 ` Jonathan Cameron
  0 siblings, 0 replies; 2+ messages in thread
From: Jonathan Cameron @ 2021-07-17 17:58 UTC (permalink / raw)
  To: Alexandru Ardelean; +Cc: linux-iio, linux-kernel

On Mon, 28 Jun 2021 17:17:09 +0300
Alexandru Ardelean <aardelean@deviqon.com> wrote:

> This is another simple conversion to device-managed functions, requiring
> the use of devm_iio_device_register() and moving the disabling of the
> device on a devm_add_action_or_reset() hook.
> 
> The i2c_set_clientdata() can be removed, as the PM functions can work with
> just the device object, to obtain the i2c_client object.
> 
> Signed-off-by: Alexandru Ardelean <aardelean@deviqon.com>
Applied,

Thanks,

Jonathan

> ---
>  drivers/iio/accel/da280.c | 26 +++++++++-----------------
>  1 file changed, 9 insertions(+), 17 deletions(-)
> 
> diff --git a/drivers/iio/accel/da280.c b/drivers/iio/accel/da280.c
> index 5edff9ba72da..9633bdae5fd4 100644
> --- a/drivers/iio/accel/da280.c
> +++ b/drivers/iio/accel/da280.c
> @@ -100,6 +100,11 @@ static enum da280_chipset da280_match_acpi_device(struct device *dev)
>  	return (enum da280_chipset) id->driver_data;
>  }
>  
> +static void da280_disable(void *client)
> +{
> +	da280_enable(client, false);
> +}
> +
>  static int da280_probe(struct i2c_client *client,
>  			const struct i2c_device_id *id)
>  {
> @@ -118,7 +123,6 @@ static int da280_probe(struct i2c_client *client,
>  
>  	data = iio_priv(indio_dev);
>  	data->client = client;
> -	i2c_set_clientdata(client, indio_dev);
>  
>  	indio_dev->info = &da280_info;
>  	indio_dev->modes = INDIO_DIRECT_MODE;
> @@ -142,22 +146,11 @@ static int da280_probe(struct i2c_client *client,
>  	if (ret < 0)
>  		return ret;
>  
> -	ret = iio_device_register(indio_dev);
> -	if (ret < 0) {
> -		dev_err(&client->dev, "device_register failed\n");
> -		da280_enable(client, false);
> -	}
> -
> -	return ret;
> -}
> -
> -static int da280_remove(struct i2c_client *client)
> -{
> -	struct iio_dev *indio_dev = i2c_get_clientdata(client);
> -
> -	iio_device_unregister(indio_dev);
> +	ret = devm_add_action_or_reset(&client->dev, da280_disable, client);
> +	if (ret)
> +		return ret;
>  
> -	return da280_enable(client, false);
> +	return devm_iio_device_register(&client->dev, indio_dev);
>  }
>  
>  #ifdef CONFIG_PM_SLEEP
> @@ -194,7 +187,6 @@ static struct i2c_driver da280_driver = {
>  		.pm = &da280_pm_ops,
>  	},
>  	.probe		= da280_probe,
> -	.remove		= da280_remove,
>  	.id_table	= da280_i2c_id,
>  };
>  


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

end of thread, other threads:[~2021-07-17 17:55 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-28 14:17 [PATCH] iio: accel: da280: convert probe to device-managed functions Alexandru Ardelean
2021-07-17 17:58 ` Jonathan Cameron

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).