linux-iio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] iio: potentiometer: max5481: convert probe to device-managed
@ 2021-06-24  8:06 Alexandru Ardelean
  2021-07-18 14:29 ` Jonathan Cameron
  0 siblings, 1 reply; 3+ messages in thread
From: Alexandru Ardelean @ 2021-06-24  8:06 UTC (permalink / raw)
  To: linux-iio, linux-kernel; +Cc: jic23, Alexandru Ardelean

The change converts the probe function to use the
devm_iio_device_register() function.

Before calling that, we need to register an action to store the wiper back
to non-volatile memory when the device is de-registered.

We don't need to do this if the probe fails, because the only place where
the probe can fail now is devm_iio_device_register() and that shouldn't
create an IIO device (for userspace to poke at) if it fails.

Signed-off-by: Alexandru Ardelean <aardelean@deviqon.com>
---
 drivers/iio/potentiometer/max5481.c | 22 +++++++++-------------
 1 file changed, 9 insertions(+), 13 deletions(-)

diff --git a/drivers/iio/potentiometer/max5481.c b/drivers/iio/potentiometer/max5481.c
index 6e22b538091f..098d144a8fdd 100644
--- a/drivers/iio/potentiometer/max5481.c
+++ b/drivers/iio/potentiometer/max5481.c
@@ -125,6 +125,11 @@ static const struct of_device_id max5481_match[] = {
 };
 MODULE_DEVICE_TABLE(of, max5481_match);
 
+static void max5481_wiper_save(void *data)
+{
+	max5481_write_cmd(data, MAX5481_COPY_AB_TO_NV, 0);
+}
+
 static int max5481_probe(struct spi_device *spi)
 {
 	struct iio_dev *indio_dev;
@@ -136,7 +141,6 @@ static int max5481_probe(struct spi_device *spi)
 	if (!indio_dev)
 		return -ENOMEM;
 
-	spi_set_drvdata(spi, indio_dev);
 	data = iio_priv(indio_dev);
 
 	data->spi = spi;
@@ -158,18 +162,11 @@ static int max5481_probe(struct spi_device *spi)
 	if (ret < 0)
 		return ret;
 
-	return iio_device_register(indio_dev);
-}
-
-static int max5481_remove(struct spi_device *spi)
-{
-	struct iio_dev *indio_dev = spi_get_drvdata(spi);
-	struct max5481_data *data = iio_priv(indio_dev);
-
-	iio_device_unregister(indio_dev);
+	ret = devm_add_action(&spi->dev, max5481_wiper_save, data);
+	if (ret < 0)
+		return ret;
 
-	/* save wiper reg to NV reg */
-	return max5481_write_cmd(data, MAX5481_COPY_AB_TO_NV, 0);
+	return devm_iio_device_register(&spi->dev, indio_dev);
 }
 
 static const struct spi_device_id max5481_id_table[] = {
@@ -187,7 +184,6 @@ static struct spi_driver max5481_driver = {
 		.of_match_table = max5481_match,
 	},
 	.probe = max5481_probe,
-	.remove = max5481_remove,
 	.id_table = max5481_id_table,
 };
 
-- 
2.31.1


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

* Re: [PATCH] iio: potentiometer: max5481: convert probe to device-managed
  2021-06-24  8:06 [PATCH] iio: potentiometer: max5481: convert probe to device-managed Alexandru Ardelean
@ 2021-07-18 14:29 ` Jonathan Cameron
  2021-07-19 11:34   ` Anderson, Maury J Collins
  0 siblings, 1 reply; 3+ messages in thread
From: Jonathan Cameron @ 2021-07-18 14:29 UTC (permalink / raw)
  To: Alexandru Ardelean; +Cc: linux-iio, linux-kernel, Maury Anderson

On Thu, 24 Jun 2021 11:06:41 +0300
Alexandru Ardelean <aardelean@deviqon.com> wrote:

> The change converts the probe function to use the
> devm_iio_device_register() function.
> 
> Before calling that, we need to register an action to store the wiper back
> to non-volatile memory when the device is de-registered.
> 
> We don't need to do this if the probe fails, because the only place where
> the probe can fail now is devm_iio_device_register() and that shouldn't
> create an IIO device (for userspace to poke at) if it fails.
> 
> Signed-off-by: Alexandru Ardelean <aardelean@deviqon.com>
Hi Alex,

This one took a little bit of thought because it's a bit unusual in that
that wiper write back isn't technically unwinding anything so doesn't
have an obvious match in probe.  However, as it logically wants to happen
just after we've removed the userspace interfaces, I agree with your
logic that it makes sense to do it with a devm triggered call.

So, on that basis applied. 

+CC Maury on basis might still be about on that address and want to
express a view on whether this makes sense.

Jonathan

> ---
>  drivers/iio/potentiometer/max5481.c | 22 +++++++++-------------
>  1 file changed, 9 insertions(+), 13 deletions(-)
> 
> diff --git a/drivers/iio/potentiometer/max5481.c b/drivers/iio/potentiometer/max5481.c
> index 6e22b538091f..098d144a8fdd 100644
> --- a/drivers/iio/potentiometer/max5481.c
> +++ b/drivers/iio/potentiometer/max5481.c
> @@ -125,6 +125,11 @@ static const struct of_device_id max5481_match[] = {
>  };
>  MODULE_DEVICE_TABLE(of, max5481_match);
>  
> +static void max5481_wiper_save(void *data)
> +{
> +	max5481_write_cmd(data, MAX5481_COPY_AB_TO_NV, 0);
> +}
> +
>  static int max5481_probe(struct spi_device *spi)
>  {
>  	struct iio_dev *indio_dev;
> @@ -136,7 +141,6 @@ static int max5481_probe(struct spi_device *spi)
>  	if (!indio_dev)
>  		return -ENOMEM;
>  
> -	spi_set_drvdata(spi, indio_dev);
>  	data = iio_priv(indio_dev);
>  
>  	data->spi = spi;
> @@ -158,18 +162,11 @@ static int max5481_probe(struct spi_device *spi)
>  	if (ret < 0)
>  		return ret;
>  
> -	return iio_device_register(indio_dev);
> -}
> -
> -static int max5481_remove(struct spi_device *spi)
> -{
> -	struct iio_dev *indio_dev = spi_get_drvdata(spi);
> -	struct max5481_data *data = iio_priv(indio_dev);
> -
> -	iio_device_unregister(indio_dev);
> +	ret = devm_add_action(&spi->dev, max5481_wiper_save, data);
> +	if (ret < 0)
> +		return ret;
>  
> -	/* save wiper reg to NV reg */
> -	return max5481_write_cmd(data, MAX5481_COPY_AB_TO_NV, 0);
> +	return devm_iio_device_register(&spi->dev, indio_dev);
>  }
>  
>  static const struct spi_device_id max5481_id_table[] = {
> @@ -187,7 +184,6 @@ static struct spi_driver max5481_driver = {
>  		.of_match_table = max5481_match,
>  	},
>  	.probe = max5481_probe,
> -	.remove = max5481_remove,
>  	.id_table = max5481_id_table,
>  };
>  


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

* RE: [PATCH] iio: potentiometer: max5481: convert probe to device-managed
  2021-07-18 14:29 ` Jonathan Cameron
@ 2021-07-19 11:34   ` Anderson, Maury J Collins
  0 siblings, 0 replies; 3+ messages in thread
From: Anderson, Maury J Collins @ 2021-07-19 11:34 UTC (permalink / raw)
  To: Jonathan Cameron, Alexandru Ardelean; +Cc: linux-iio, linux-kernel

Jonathan and Alex,

This change makes sense to me.  Silly comment on my part.  The intent as I recall was that the device would not "jump back to default" when the controlling system went through a reboot phase.

Thank you.

Maury

-----Original Message-----
From: Jonathan Cameron <jic23@kernel.org> 
Sent: Sunday, July 18, 2021 9:30 AM
To: Alexandru Ardelean <aardelean@deviqon.com>
Cc: linux-iio@vger.kernel.org; linux-kernel@vger.kernel.org; Anderson, Maury J Collins <Maury.Anderson@collins.com>
Subject: Re: [PATCH] iio: potentiometer: max5481: convert probe to device-managed

On Thu, 24 Jun 2021 11:06:41 +0300
Alexandru Ardelean <aardelean@deviqon.com> wrote:

> The change converts the probe function to use the
> devm_iio_device_register() function.
> 
> Before calling that, we need to register an action to store the wiper back
> to non-volatile memory when the device is de-registered.
> 
> We don't need to do this if the probe fails, because the only place where
> the probe can fail now is devm_iio_device_register() and that shouldn't
> create an IIO device (for userspace to poke at) if it fails.
> 
> Signed-off-by: Alexandru Ardelean <aardelean@deviqon.com>
Hi Alex,

This one took a little bit of thought because it's a bit unusual in that
that wiper write back isn't technically unwinding anything so doesn't
have an obvious match in probe.  However, as it logically wants to happen
just after we've removed the userspace interfaces, I agree with your
logic that it makes sense to do it with a devm triggered call.

So, on that basis applied. 

+CC Maury on basis might still be about on that address and want to
express a view on whether this makes sense.

Jonathan

> ---
>  drivers/iio/potentiometer/max5481.c | 22 +++++++++-------------
>  1 file changed, 9 insertions(+), 13 deletions(-)
> 
> diff --git a/drivers/iio/potentiometer/max5481.c b/drivers/iio/potentiometer/max5481.c
> index 6e22b538091f..098d144a8fdd 100644
> --- a/drivers/iio/potentiometer/max5481.c
> +++ b/drivers/iio/potentiometer/max5481.c
> @@ -125,6 +125,11 @@ static const struct of_device_id max5481_match[] = {
>  };
>  MODULE_DEVICE_TABLE(of, max5481_match);
>  
> +static void max5481_wiper_save(void *data)
> +{
> +	max5481_write_cmd(data, MAX5481_COPY_AB_TO_NV, 0);
> +}
> +
>  static int max5481_probe(struct spi_device *spi)
>  {
>  	struct iio_dev *indio_dev;
> @@ -136,7 +141,6 @@ static int max5481_probe(struct spi_device *spi)
>  	if (!indio_dev)
>  		return -ENOMEM;
>  
> -	spi_set_drvdata(spi, indio_dev);
>  	data = iio_priv(indio_dev);
>  
>  	data->spi = spi;
> @@ -158,18 +162,11 @@ static int max5481_probe(struct spi_device *spi)
>  	if (ret < 0)
>  		return ret;
>  
> -	return iio_device_register(indio_dev);
> -}
> -
> -static int max5481_remove(struct spi_device *spi)
> -{
> -	struct iio_dev *indio_dev = spi_get_drvdata(spi);
> -	struct max5481_data *data = iio_priv(indio_dev);
> -
> -	iio_device_unregister(indio_dev);
> +	ret = devm_add_action(&spi->dev, max5481_wiper_save, data);
> +	if (ret < 0)
> +		return ret;
>  
> -	/* save wiper reg to NV reg */
> -	return max5481_write_cmd(data, MAX5481_COPY_AB_TO_NV, 0);
> +	return devm_iio_device_register(&spi->dev, indio_dev);
>  }
>  
>  static const struct spi_device_id max5481_id_table[] = {
> @@ -187,7 +184,6 @@ static struct spi_driver max5481_driver = {
>  		.of_match_table = max5481_match,
>  	},
>  	.probe = max5481_probe,
> -	.remove = max5481_remove,
>  	.id_table = max5481_id_table,
>  };
>  


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

end of thread, other threads:[~2021-07-19 12:04 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-24  8:06 [PATCH] iio: potentiometer: max5481: convert probe to device-managed Alexandru Ardelean
2021-07-18 14:29 ` Jonathan Cameron
2021-07-19 11:34   ` Anderson, Maury J Collins

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