* [PATCH] iio: ad7266: convert probe to full device-managed
@ 2022-04-06 12:29 Maíra Canal
0 siblings, 0 replies; 5+ messages in thread
From: Maíra Canal @ 2022-04-06 12:29 UTC (permalink / raw)
To: lars, Michael.Hennerich, jic23, linux-iio, linux-kernel
Convert probe functions to device-managed variants, with exception of
the regulator, which required a devm_add_action_or_reset() hook
registration.
Signed-off-by: Maíra Canal <maira.canal@usp.br>
---
drivers/iio/adc/ad7266.c | 43 +++++++++++++---------------------------
1 file changed, 14 insertions(+), 29 deletions(-)
diff --git a/drivers/iio/adc/ad7266.c b/drivers/iio/adc/ad7266.c
index c17d9b5fbaf6..4f8f07d5c1a3 100644
--- a/drivers/iio/adc/ad7266.c
+++ b/drivers/iio/adc/ad7266.c
@@ -378,6 +378,11 @@ static const char * const ad7266_gpio_labels[] = {
"ad0", "ad1", "ad2",
};
+static void ad7266_reg_disable(void *reg)
+{
+ regulator_disable(reg);
+}
+
static int ad7266_probe(struct spi_device *spi)
{
struct ad7266_platform_data *pdata = spi->dev.platform_data;
@@ -398,9 +403,13 @@ static int ad7266_probe(struct spi_device *spi)
if (ret)
return ret;
+ ret = devm_add_action_or_reset(&spi->dev, ad7266_reg_disable, st->reg);
+ if (ret)
+ return ret;
+
ret = regulator_get_voltage(st->reg);
if (ret < 0)
- goto error_disable_reg;
+ return ret;
st->vref_mv = ret / 1000;
} else {
@@ -423,7 +432,7 @@ static int ad7266_probe(struct spi_device *spi)
GPIOD_OUT_LOW);
if (IS_ERR(st->gpios[i])) {
ret = PTR_ERR(st->gpios[i]);
- goto error_disable_reg;
+ return ret;
}
}
}
@@ -459,35 +468,12 @@ static int ad7266_probe(struct spi_device *spi)
spi_message_add_tail(&st->single_xfer[1], &st->single_msg);
spi_message_add_tail(&st->single_xfer[2], &st->single_msg);
- ret = iio_triggered_buffer_setup(indio_dev, &iio_pollfunc_store_time,
+ ret = devm_iio_triggered_buffer_setup(&spi->dev, indio_dev, &iio_pollfunc_store_time,
&ad7266_trigger_handler, &iio_triggered_buffer_setup_ops);
if (ret)
- goto error_disable_reg;
-
- ret = iio_device_register(indio_dev);
- if (ret)
- goto error_buffer_cleanup;
-
- return 0;
-
-error_buffer_cleanup:
- iio_triggered_buffer_cleanup(indio_dev);
-error_disable_reg:
- if (!IS_ERR(st->reg))
- regulator_disable(st->reg);
-
- return ret;
-}
-
-static void ad7266_remove(struct spi_device *spi)
-{
- struct iio_dev *indio_dev = spi_get_drvdata(spi);
- struct ad7266_state *st = iio_priv(indio_dev);
+ return ret;
- iio_device_unregister(indio_dev);
- iio_triggered_buffer_cleanup(indio_dev);
- if (!IS_ERR(st->reg))
- regulator_disable(st->reg);
+ return devm_iio_device_register(&spi->dev, indio_dev);
}
static const struct spi_device_id ad7266_id[] = {
@@ -502,7 +488,6 @@ static struct spi_driver ad7266_driver = {
.name = "ad7266",
},
.probe = ad7266_probe,
- .remove = ad7266_remove,
.id_table = ad7266_id,
};
module_spi_driver(ad7266_driver);
--
2.35.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH] iio: ad7266: convert probe to full device-managed
@ 2022-04-06 15:12 Maíra Canal
2022-04-07 3:18 ` Marcelo Schmitt
2022-04-07 9:00 ` Sa, Nuno
0 siblings, 2 replies; 5+ messages in thread
From: Maíra Canal @ 2022-04-06 15:12 UTC (permalink / raw)
To: michael.hennerich, lars, jic23; +Cc: linux-iio, linux-kernel
Convert probe functions to device-managed variants, with exception of
the regulator, which required a devm_add_action_or_reset() hook
registration.
Signed-off-by: Maíra Canal <maira.canal@usp.br>
---
I apologize if you received this email more than once. For some reason, the
patch is not showing up on the linux-iio mailing list. I believe that the
problem was that Michael's Hennerich email on the MAINTAINERS list was
Michael.Hennerich@analog.com instead of michael.hennerich@analog.com. Anyway,
I am truly sorry with you received this email more than once.
---
drivers/iio/adc/ad7266.c | 43 +++++++++++++---------------------------
1 file changed, 14 insertions(+), 29 deletions(-)
diff --git a/drivers/iio/adc/ad7266.c b/drivers/iio/adc/ad7266.c
index c17d9b5fbaf6..4f8f07d5c1a3 100644
--- a/drivers/iio/adc/ad7266.c
+++ b/drivers/iio/adc/ad7266.c
@@ -378,6 +378,11 @@ static const char * const ad7266_gpio_labels[] = {
"ad0", "ad1", "ad2",
};
+static void ad7266_reg_disable(void *reg)
+{
+ regulator_disable(reg);
+}
+
static int ad7266_probe(struct spi_device *spi)
{
struct ad7266_platform_data *pdata = spi->dev.platform_data;
@@ -398,9 +403,13 @@ static int ad7266_probe(struct spi_device *spi)
if (ret)
return ret;
+ ret = devm_add_action_or_reset(&spi->dev, ad7266_reg_disable, st->reg);
+ if (ret)
+ return ret;
+
ret = regulator_get_voltage(st->reg);
if (ret < 0)
- goto error_disable_reg;
+ return ret;
st->vref_mv = ret / 1000;
} else {
@@ -423,7 +432,7 @@ static int ad7266_probe(struct spi_device *spi)
GPIOD_OUT_LOW);
if (IS_ERR(st->gpios[i])) {
ret = PTR_ERR(st->gpios[i]);
- goto error_disable_reg;
+ return ret;
}
}
}
@@ -459,35 +468,12 @@ static int ad7266_probe(struct spi_device *spi)
spi_message_add_tail(&st->single_xfer[1], &st->single_msg);
spi_message_add_tail(&st->single_xfer[2], &st->single_msg);
- ret = iio_triggered_buffer_setup(indio_dev, &iio_pollfunc_store_time,
+ ret = devm_iio_triggered_buffer_setup(&spi->dev, indio_dev, &iio_pollfunc_store_time,
&ad7266_trigger_handler, &iio_triggered_buffer_setup_ops);
if (ret)
- goto error_disable_reg;
-
- ret = iio_device_register(indio_dev);
- if (ret)
- goto error_buffer_cleanup;
-
- return 0;
-
-error_buffer_cleanup:
- iio_triggered_buffer_cleanup(indio_dev);
-error_disable_reg:
- if (!IS_ERR(st->reg))
- regulator_disable(st->reg);
-
- return ret;
-}
-
-static void ad7266_remove(struct spi_device *spi)
-{
- struct iio_dev *indio_dev = spi_get_drvdata(spi);
- struct ad7266_state *st = iio_priv(indio_dev);
+ return ret;
- iio_device_unregister(indio_dev);
- iio_triggered_buffer_cleanup(indio_dev);
- if (!IS_ERR(st->reg))
- regulator_disable(st->reg);
+ return devm_iio_device_register(&spi->dev, indio_dev);
}
static const struct spi_device_id ad7266_id[] = {
@@ -502,7 +488,6 @@ static struct spi_driver ad7266_driver = {
.name = "ad7266",
},
.probe = ad7266_probe,
- .remove = ad7266_remove,
.id_table = ad7266_id,
};
module_spi_driver(ad7266_driver);
--
2.35.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] iio: ad7266: convert probe to full device-managed
2022-04-06 15:12 Maíra Canal
@ 2022-04-07 3:18 ` Marcelo Schmitt
2022-04-07 9:00 ` Sa, Nuno
1 sibling, 0 replies; 5+ messages in thread
From: Marcelo Schmitt @ 2022-04-07 3:18 UTC (permalink / raw)
To: Maíra Canal; +Cc: michael.hennerich, lars, jic23, linux-iio, linux-kernel
Hi Maíra,
On 04/06, Maíra Canal wrote:
> Convert probe functions to device-managed variants, with exception of
> the regulator, which required a devm_add_action_or_reset() hook
> registration.
>
> Signed-off-by: Maíra Canal <maira.canal@usp.br>
Nice patch!
Minor nit inline.
Reviewed-by: Marcelo Schmitt <marcelo.schmitt1@gmail.com>
> ---
> I apologize if you received this email more than once. For some reason, the
> patch is not showing up on the linux-iio mailing list. I believe that the
> problem was that Michael's Hennerich email on the MAINTAINERS list was
> Michael.Hennerich@analog.com instead of michael.hennerich@analog.com. Anyway,
> I am truly sorry with you received this email more than once.
> ---
> drivers/iio/adc/ad7266.c | 43 +++++++++++++---------------------------
> 1 file changed, 14 insertions(+), 29 deletions(-)
>
> diff --git a/drivers/iio/adc/ad7266.c b/drivers/iio/adc/ad7266.c
> index c17d9b5fbaf6..4f8f07d5c1a3 100644
> --- a/drivers/iio/adc/ad7266.c
> +++ b/drivers/iio/adc/ad7266.c
> @@ -378,6 +378,11 @@ static const char * const ad7266_gpio_labels[] = {
> "ad0", "ad1", "ad2",
> };
>
> +static void ad7266_reg_disable(void *reg)
> +{
> + regulator_disable(reg);
> +}
> +
> static int ad7266_probe(struct spi_device *spi)
> {
> struct ad7266_platform_data *pdata = spi->dev.platform_data;
> @@ -398,9 +403,13 @@ static int ad7266_probe(struct spi_device *spi)
> if (ret)
> return ret;
>
> + ret = devm_add_action_or_reset(&spi->dev, ad7266_reg_disable, st->reg);
> + if (ret)
> + return ret;
> +
> ret = regulator_get_voltage(st->reg);
> if (ret < 0)
> - goto error_disable_reg;
> + return ret;
>
> st->vref_mv = ret / 1000;
> } else {
> @@ -423,7 +432,7 @@ static int ad7266_probe(struct spi_device *spi)
> GPIOD_OUT_LOW);
> if (IS_ERR(st->gpios[i])) {
> ret = PTR_ERR(st->gpios[i]);
> - goto error_disable_reg;
> + return ret;
> }
> }
> }
> @@ -459,35 +468,12 @@ static int ad7266_probe(struct spi_device *spi)
> spi_message_add_tail(&st->single_xfer[1], &st->single_msg);
> spi_message_add_tail(&st->single_xfer[2], &st->single_msg);
>
> - ret = iio_triggered_buffer_setup(indio_dev, &iio_pollfunc_store_time,
> + ret = devm_iio_triggered_buffer_setup(&spi->dev, indio_dev, &iio_pollfunc_store_time,
> &ad7266_trigger_handler, &iio_triggered_buffer_setup_ops);
> if (ret)
> - goto error_disable_reg;
> -
> - ret = iio_device_register(indio_dev);
> - if (ret)
> - goto error_buffer_cleanup;
> -
> - return 0;
> -
> -error_buffer_cleanup:
> - iio_triggered_buffer_cleanup(indio_dev);
> -error_disable_reg:
> - if (!IS_ERR(st->reg))
> - regulator_disable(st->reg);
> -
> - return ret;
> -}
> -
> -static void ad7266_remove(struct spi_device *spi)
> -{
> - struct iio_dev *indio_dev = spi_get_drvdata(spi);
With this removal, there is no other usage of driver_data so you may also remove
spi_set_drvdata(spi, indio_dev);
> - struct ad7266_state *st = iio_priv(indio_dev);
> + return ret;
>
> - iio_device_unregister(indio_dev);
> - iio_triggered_buffer_cleanup(indio_dev);
> - if (!IS_ERR(st->reg))
> - regulator_disable(st->reg);
> + return devm_iio_device_register(&spi->dev, indio_dev);
> }
>
> static const struct spi_device_id ad7266_id[] = {
> @@ -502,7 +488,6 @@ static struct spi_driver ad7266_driver = {
> .name = "ad7266",
> },
> .probe = ad7266_probe,
> - .remove = ad7266_remove,
> .id_table = ad7266_id,
> };
> module_spi_driver(ad7266_driver);
> --
> 2.35.1
>
^ permalink raw reply [flat|nested] 5+ messages in thread
* RE: [PATCH] iio: ad7266: convert probe to full device-managed
2022-04-06 15:12 Maíra Canal
2022-04-07 3:18 ` Marcelo Schmitt
@ 2022-04-07 9:00 ` Sa, Nuno
1 sibling, 0 replies; 5+ messages in thread
From: Sa, Nuno @ 2022-04-07 9:00 UTC (permalink / raw)
To: Maíra Canal, Hennerich, Michael, lars, jic23; +Cc: linux-iio, linux-kernel
> -----Original Message-----
> From: Maíra Canal <maira.canal@usp.br>
> Sent: Wednesday, April 6, 2022 5:13 PM
> To: Hennerich, Michael <Michael.Hennerich@analog.com>;
> lars@metafoo.de; jic23@kernel.org
> Cc: linux-iio@vger.kernel.org; linux-kernel@vger.kernel.org
> Subject: [PATCH] iio: ad7266: convert probe to full device-managed
>
> [External]
>
> Convert probe functions to device-managed variants, with exception
> of
> the regulator, which required a devm_add_action_or_reset() hook
> registration.
>
> Signed-off-by: Maíra Canal <maira.canal@usp.br>
> ---
With what Marcelo said,
Reviewed-by: Nuno Sá <nuno.sa@analog.com>
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH] iio: ad7266: convert probe to full device-managed
@ 2022-04-06 12:16 Maíra Canal
0 siblings, 0 replies; 5+ messages in thread
From: Maíra Canal @ 2022-04-06 12:16 UTC (permalink / raw)
To: lars, Michael.Hennerich, jic23; +Cc: linux-iio, linux-kernel, Maíra Canal
Convert probe functions to device-managed variants, with exception of
the regulator, which required a devm_add_action_or_reset() hook
registration.
Signed-off-by: Maíra Canal <maira.canal@usp.br>
---
drivers/iio/adc/ad7266.c | 43 +++++++++++++---------------------------
1 file changed, 14 insertions(+), 29 deletions(-)
diff --git a/drivers/iio/adc/ad7266.c b/drivers/iio/adc/ad7266.c
index c17d9b5fbaf6..4f8f07d5c1a3 100644
--- a/drivers/iio/adc/ad7266.c
+++ b/drivers/iio/adc/ad7266.c
@@ -378,6 +378,11 @@ static const char * const ad7266_gpio_labels[] = {
"ad0", "ad1", "ad2",
};
+static void ad7266_reg_disable(void *reg)
+{
+ regulator_disable(reg);
+}
+
static int ad7266_probe(struct spi_device *spi)
{
struct ad7266_platform_data *pdata = spi->dev.platform_data;
@@ -398,9 +403,13 @@ static int ad7266_probe(struct spi_device *spi)
if (ret)
return ret;
+ ret = devm_add_action_or_reset(&spi->dev, ad7266_reg_disable, st->reg);
+ if (ret)
+ return ret;
+
ret = regulator_get_voltage(st->reg);
if (ret < 0)
- goto error_disable_reg;
+ return ret;
st->vref_mv = ret / 1000;
} else {
@@ -423,7 +432,7 @@ static int ad7266_probe(struct spi_device *spi)
GPIOD_OUT_LOW);
if (IS_ERR(st->gpios[i])) {
ret = PTR_ERR(st->gpios[i]);
- goto error_disable_reg;
+ return ret;
}
}
}
@@ -459,35 +468,12 @@ static int ad7266_probe(struct spi_device *spi)
spi_message_add_tail(&st->single_xfer[1], &st->single_msg);
spi_message_add_tail(&st->single_xfer[2], &st->single_msg);
- ret = iio_triggered_buffer_setup(indio_dev, &iio_pollfunc_store_time,
+ ret = devm_iio_triggered_buffer_setup(&spi->dev, indio_dev, &iio_pollfunc_store_time,
&ad7266_trigger_handler, &iio_triggered_buffer_setup_ops);
if (ret)
- goto error_disable_reg;
-
- ret = iio_device_register(indio_dev);
- if (ret)
- goto error_buffer_cleanup;
-
- return 0;
-
-error_buffer_cleanup:
- iio_triggered_buffer_cleanup(indio_dev);
-error_disable_reg:
- if (!IS_ERR(st->reg))
- regulator_disable(st->reg);
-
- return ret;
-}
-
-static void ad7266_remove(struct spi_device *spi)
-{
- struct iio_dev *indio_dev = spi_get_drvdata(spi);
- struct ad7266_state *st = iio_priv(indio_dev);
+ return ret;
- iio_device_unregister(indio_dev);
- iio_triggered_buffer_cleanup(indio_dev);
- if (!IS_ERR(st->reg))
- regulator_disable(st->reg);
+ return devm_iio_device_register(&spi->dev, indio_dev);
}
static const struct spi_device_id ad7266_id[] = {
@@ -502,7 +488,6 @@ static struct spi_driver ad7266_driver = {
.name = "ad7266",
},
.probe = ad7266_probe,
- .remove = ad7266_remove,
.id_table = ad7266_id,
};
module_spi_driver(ad7266_driver);
--
2.35.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
end of thread, other threads:[~2022-04-07 9:01 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-06 12:29 [PATCH] iio: ad7266: convert probe to full device-managed Maíra Canal
-- strict thread matches above, loose matches on Subject: below --
2022-04-06 15:12 Maíra Canal
2022-04-07 3:18 ` Marcelo Schmitt
2022-04-07 9:00 ` Sa, Nuno
2022-04-06 12:16 Maíra Canal
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).