public inbox for linux-arm-kernel@lists.infradead.org
 help / color / mirror / Atom feed
* [PATCH -next v3 0/3] iio: adc: at91_adc: Cleanup with the helpers
@ 2023-08-28  6:45 Jinjie Ruan
  2023-08-28  6:45 ` [PATCH -next v3 1/3] iio: adc: at91_adc: Use devm_request_irq() helper function Jinjie Ruan
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Jinjie Ruan @ 2023-08-28  6:45 UTC (permalink / raw)
  To: jic23, lars, nicolas.ferre, alexandre.belloni, claudiu.beznea,
	yangyingliang, robh, heiko, linux-arm-kernel, linux-iio
  Cc: ruanjinjie

Commit 7ef9651e9792 ("clk: Provide new devm_clk helpers for prepared
and enabled clocks") provides a new helper function to prepare and
enable a clock which keeps prepared (or enabled) during the whole
lifetime of the driver.

Use devm_request_irq() to request the interrupt, so we can
avoid having to manually clean this up.

Use the dev_err_probe() helper to simplify error handling during probe.
This also handle scenario, when EDEFER is returned and useless
error is printed.

changes in v3:
- Take the last remove free_irq() and add it to be the first devm managed.
- Not going any longer than 80 chars than is necessary.

Changes in v2:
- Also use devm_request_irq() and dev_err_probe() to clean up the at91_adc.
- Split the at91_adc patch out to be a new patch set.

Jinjie Ruan (3):
  iio: adc: at91_adc: Use devm_request_irq() helper function
  iio: adc: at91_adc: Use devm_clk_get_enabled() helper function
  iio: adc: at91_adc: Simplify with dev_err_probe()

 drivers/iio/adc/at91_adc.c | 108 +++++++++++++------------------------
 1 file changed, 37 insertions(+), 71 deletions(-)

-- 
2.34.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* [PATCH -next v3 1/3] iio: adc: at91_adc: Use devm_request_irq() helper function
  2023-08-28  6:45 [PATCH -next v3 0/3] iio: adc: at91_adc: Cleanup with the helpers Jinjie Ruan
@ 2023-08-28  6:45 ` Jinjie Ruan
  2023-08-28  6:45 ` [PATCH -next v3 2/3] iio: adc: at91_adc: Use devm_clk_get_enabled() " Jinjie Ruan
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Jinjie Ruan @ 2023-08-28  6:45 UTC (permalink / raw)
  To: jic23, lars, nicolas.ferre, alexandre.belloni, claudiu.beznea,
	yangyingliang, robh, heiko, linux-arm-kernel, linux-iio
  Cc: ruanjinjie

Use devm_request_irq() to request the interrupt, so we can avoid
having to manually clean this up.

Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com>
---
v3:
- Take the last remove free_irq() and add it to be the first devm managed.
v2:
- Also use devm_request_irq() helper.
---
 drivers/iio/adc/at91_adc.c | 18 ++++++++----------
 1 file changed, 8 insertions(+), 10 deletions(-)

diff --git a/drivers/iio/adc/at91_adc.c b/drivers/iio/adc/at91_adc.c
index de6650f9c4b1..771ad5c4a131 100644
--- a/drivers/iio/adc/at91_adc.c
+++ b/drivers/iio/adc/at91_adc.c
@@ -1077,11 +1077,13 @@ static int at91_adc_probe(struct platform_device *pdev)
 	at91_adc_writel(st, AT91_ADC_IDR, 0xFFFFFFFF);
 
 	if (st->caps->has_tsmr)
-		ret = request_irq(st->irq, at91_adc_9x5_interrupt, 0,
-				  pdev->dev.driver->name, idev);
+		ret = devm_request_irq(&pdev->dev, st->irq,
+				       at91_adc_9x5_interrupt, 0,
+				       pdev->dev.driver->name, idev);
 	else
-		ret = request_irq(st->irq, at91_adc_rl_interrupt, 0,
-				  pdev->dev.driver->name, idev);
+		ret = devm_request_irq(&pdev->dev, st->irq,
+				       at91_adc_rl_interrupt, 0,
+				       pdev->dev.driver->name, idev);
 	if (ret) {
 		dev_err(&pdev->dev, "Failed to allocate IRQ.\n");
 		return ret;
@@ -1090,15 +1092,14 @@ static int at91_adc_probe(struct platform_device *pdev)
 	st->clk = devm_clk_get(&pdev->dev, "adc_clk");
 	if (IS_ERR(st->clk)) {
 		dev_err(&pdev->dev, "Failed to get the clock.\n");
-		ret = PTR_ERR(st->clk);
-		goto error_free_irq;
+		return PTR_ERR(st->clk);
 	}
 
 	ret = clk_prepare_enable(st->clk);
 	if (ret) {
 		dev_err(&pdev->dev,
 			"Could not prepare or enable the clock.\n");
-		goto error_free_irq;
+		return ret;
 	}
 
 	st->adc_clk = devm_clk_get(&pdev->dev, "adc_op_clk");
@@ -1211,8 +1212,6 @@ static int at91_adc_probe(struct platform_device *pdev)
 	clk_disable_unprepare(st->adc_clk);
 error_disable_clk:
 	clk_disable_unprepare(st->clk);
-error_free_irq:
-	free_irq(st->irq, idev);
 	return ret;
 }
 
@@ -1230,7 +1229,6 @@ static int at91_adc_remove(struct platform_device *pdev)
 	}
 	clk_disable_unprepare(st->adc_clk);
 	clk_disable_unprepare(st->clk);
-	free_irq(st->irq, idev);
 
 	return 0;
 }
-- 
2.34.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* [PATCH -next v3 2/3] iio: adc: at91_adc: Use devm_clk_get_enabled() helper function
  2023-08-28  6:45 [PATCH -next v3 0/3] iio: adc: at91_adc: Cleanup with the helpers Jinjie Ruan
  2023-08-28  6:45 ` [PATCH -next v3 1/3] iio: adc: at91_adc: Use devm_request_irq() helper function Jinjie Ruan
@ 2023-08-28  6:45 ` Jinjie Ruan
  2023-08-28  6:45 ` [PATCH -next v3 3/3] iio: adc: at91_adc: Simplify with dev_err_probe() Jinjie Ruan
  2023-08-28 11:12 ` [PATCH -next v3 0/3] iio: adc: at91_adc: Cleanup with the helpers Jonathan Cameron
  3 siblings, 0 replies; 5+ messages in thread
From: Jinjie Ruan @ 2023-08-28  6:45 UTC (permalink / raw)
  To: jic23, lars, nicolas.ferre, alexandre.belloni, claudiu.beznea,
	yangyingliang, robh, heiko, linux-arm-kernel, linux-iio
  Cc: ruanjinjie

The devm_clk_get_enabled() helper:
    - calls devm_clk_get()
    - calls clk_prepare_enable() and registers what is needed in order to
      call clk_disable_unprepare() when needed, as a managed resource.

This simplifies the code.

Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com>
---
v3:
- Take the last remove free_irq() and add it to be the first devm managed.
v2:
- No change.
---
 drivers/iio/adc/at91_adc.c | 38 +++++++++-----------------------------
 1 file changed, 9 insertions(+), 29 deletions(-)

diff --git a/drivers/iio/adc/at91_adc.c b/drivers/iio/adc/at91_adc.c
index 771ad5c4a131..e5610722ce0b 100644
--- a/drivers/iio/adc/at91_adc.c
+++ b/drivers/iio/adc/at91_adc.c
@@ -1089,31 +1089,18 @@ static int at91_adc_probe(struct platform_device *pdev)
 		return ret;
 	}
 
-	st->clk = devm_clk_get(&pdev->dev, "adc_clk");
+	st->clk = devm_clk_get_enabled(&pdev->dev, "adc_clk");
 	if (IS_ERR(st->clk)) {
-		dev_err(&pdev->dev, "Failed to get the clock.\n");
-		return PTR_ERR(st->clk);
-	}
-
-	ret = clk_prepare_enable(st->clk);
-	if (ret) {
 		dev_err(&pdev->dev,
 			"Could not prepare or enable the clock.\n");
-		return ret;
+		return PTR_ERR(st->clk);
 	}
 
-	st->adc_clk = devm_clk_get(&pdev->dev, "adc_op_clk");
+	st->adc_clk = devm_clk_get_enabled(&pdev->dev, "adc_op_clk");
 	if (IS_ERR(st->adc_clk)) {
-		dev_err(&pdev->dev, "Failed to get the ADC clock.\n");
-		ret = PTR_ERR(st->adc_clk);
-		goto error_disable_clk;
-	}
-
-	ret = clk_prepare_enable(st->adc_clk);
-	if (ret) {
 		dev_err(&pdev->dev,
 			"Could not prepare or enable the ADC clock.\n");
-		goto error_disable_clk;
+		return PTR_ERR(st->adc_clk);
 	}
 
 	/*
@@ -1132,8 +1119,7 @@ static int at91_adc_probe(struct platform_device *pdev)
 
 	if (!st->startup_time) {
 		dev_err(&pdev->dev, "No startup time available.\n");
-		ret = -EINVAL;
-		goto error_disable_adc_clk;
+		return -EINVAL;
 	}
 	ticks = (*st->caps->calc_startup_ticks)(st->startup_time, adc_clk_khz);
 
@@ -1161,7 +1147,7 @@ static int at91_adc_probe(struct platform_device *pdev)
 	ret = at91_adc_channel_init(idev);
 	if (ret < 0) {
 		dev_err(&pdev->dev, "Couldn't initialize the channels.\n");
-		goto error_disable_adc_clk;
+		return ret;
 	}
 
 	init_waitqueue_head(&st->wq_data_avail);
@@ -1176,19 +1162,19 @@ static int at91_adc_probe(struct platform_device *pdev)
 		ret = at91_adc_buffer_init(idev);
 		if (ret < 0) {
 			dev_err(&pdev->dev, "Couldn't initialize the buffer.\n");
-			goto error_disable_adc_clk;
+			return ret;
 		}
 
 		ret = at91_adc_trigger_init(idev);
 		if (ret < 0) {
 			dev_err(&pdev->dev, "Couldn't setup the triggers.\n");
 			at91_adc_buffer_remove(idev);
-			goto error_disable_adc_clk;
+			return ret;
 		}
 	} else {
 		ret = at91_ts_register(idev, pdev);
 		if (ret)
-			goto error_disable_adc_clk;
+			return ret;
 
 		at91_ts_hw_init(idev, adc_clk_khz);
 	}
@@ -1208,10 +1194,6 @@ static int at91_adc_probe(struct platform_device *pdev)
 	} else {
 		at91_ts_unregister(st);
 	}
-error_disable_adc_clk:
-	clk_disable_unprepare(st->adc_clk);
-error_disable_clk:
-	clk_disable_unprepare(st->clk);
 	return ret;
 }
 
@@ -1227,8 +1209,6 @@ static int at91_adc_remove(struct platform_device *pdev)
 	} else {
 		at91_ts_unregister(st);
 	}
-	clk_disable_unprepare(st->adc_clk);
-	clk_disable_unprepare(st->clk);
 
 	return 0;
 }
-- 
2.34.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* [PATCH -next v3 3/3] iio: adc: at91_adc: Simplify with dev_err_probe()
  2023-08-28  6:45 [PATCH -next v3 0/3] iio: adc: at91_adc: Cleanup with the helpers Jinjie Ruan
  2023-08-28  6:45 ` [PATCH -next v3 1/3] iio: adc: at91_adc: Use devm_request_irq() helper function Jinjie Ruan
  2023-08-28  6:45 ` [PATCH -next v3 2/3] iio: adc: at91_adc: Use devm_clk_get_enabled() " Jinjie Ruan
@ 2023-08-28  6:45 ` Jinjie Ruan
  2023-08-28 11:12 ` [PATCH -next v3 0/3] iio: adc: at91_adc: Cleanup with the helpers Jonathan Cameron
  3 siblings, 0 replies; 5+ messages in thread
From: Jinjie Ruan @ 2023-08-28  6:45 UTC (permalink / raw)
  To: jic23, lars, nicolas.ferre, alexandre.belloni, claudiu.beznea,
	yangyingliang, robh, heiko, linux-arm-kernel, linux-iio
  Cc: ruanjinjie

Use the dev_err_probe() helper to simplify error handling during probe.
This also handle scenario, when EDEFER is returned and useless error
is printed.

Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com>
---
v3:
- Not going any longer than 80 chars than is necessary.
v2:
- Use the dev_err_probe() helper.
---
 drivers/iio/adc/at91_adc.c | 66 ++++++++++++++++----------------------
 1 file changed, 27 insertions(+), 39 deletions(-)

diff --git a/drivers/iio/adc/at91_adc.c b/drivers/iio/adc/at91_adc.c
index e5610722ce0b..200c4599530b 100644
--- a/drivers/iio/adc/at91_adc.c
+++ b/drivers/iio/adc/at91_adc.c
@@ -1013,28 +1013,25 @@ static int at91_adc_probe(struct platform_device *pdev)
 
 	st->use_external = of_property_read_bool(node, "atmel,adc-use-external-triggers");
 
-	if (of_property_read_u32(node, "atmel,adc-channels-used", &prop)) {
-		dev_err(&idev->dev, "Missing adc-channels-used property in the DT.\n");
-		return -EINVAL;
-	}
+	if (of_property_read_u32(node, "atmel,adc-channels-used", &prop))
+		return dev_err_probe(&idev->dev, -EINVAL,
+				     "Missing adc-channels-used property in the DT.\n");
 	st->channels_mask = prop;
 
 	st->sleep_mode = of_property_read_bool(node, "atmel,adc-sleep-mode");
 
-	if (of_property_read_u32(node, "atmel,adc-startup-time", &prop)) {
-		dev_err(&idev->dev, "Missing adc-startup-time property in the DT.\n");
-		return -EINVAL;
-	}
+	if (of_property_read_u32(node, "atmel,adc-startup-time", &prop))
+		return dev_err_probe(&idev->dev, -EINVAL,
+				     "Missing adc-startup-time property in the DT.\n");
 	st->startup_time = prop;
 
 	prop = 0;
 	of_property_read_u32(node, "atmel,adc-sample-hold-time", &prop);
 	st->sample_hold_time = prop;
 
-	if (of_property_read_u32(node, "atmel,adc-vref", &prop)) {
-		dev_err(&idev->dev, "Missing adc-vref property in the DT.\n");
-		return -EINVAL;
-	}
+	if (of_property_read_u32(node, "atmel,adc-vref", &prop))
+		return dev_err_probe(&idev->dev, -EINVAL,
+				     "Missing adc-vref property in the DT.\n");
 	st->vref_mv = prop;
 
 	st->res = st->caps->high_res_bits;
@@ -1069,7 +1066,6 @@ static int at91_adc_probe(struct platform_device *pdev)
 	if (IS_ERR(st->reg_base))
 		return PTR_ERR(st->reg_base);
 
-
 	/*
 	 * Disable all IRQs before setting up the handler
 	 */
@@ -1084,24 +1080,19 @@ static int at91_adc_probe(struct platform_device *pdev)
 		ret = devm_request_irq(&pdev->dev, st->irq,
 				       at91_adc_rl_interrupt, 0,
 				       pdev->dev.driver->name, idev);
-	if (ret) {
-		dev_err(&pdev->dev, "Failed to allocate IRQ.\n");
-		return ret;
-	}
+	if (ret)
+		return dev_err_probe(&pdev->dev, ret,
+				     "Failed to allocate IRQ.\n");
 
 	st->clk = devm_clk_get_enabled(&pdev->dev, "adc_clk");
-	if (IS_ERR(st->clk)) {
-		dev_err(&pdev->dev,
-			"Could not prepare or enable the clock.\n");
-		return PTR_ERR(st->clk);
-	}
+	if (IS_ERR(st->clk))
+		return dev_err_probe(&pdev->dev, PTR_ERR(st->clk),
+				     "Could not prepare or enable the clock.\n");
 
 	st->adc_clk = devm_clk_get_enabled(&pdev->dev, "adc_op_clk");
-	if (IS_ERR(st->adc_clk)) {
-		dev_err(&pdev->dev,
-			"Could not prepare or enable the ADC clock.\n");
-		return PTR_ERR(st->adc_clk);
-	}
+	if (IS_ERR(st->adc_clk))
+		return dev_err_probe(&pdev->dev, PTR_ERR(st->adc_clk),
+				     "Could not prepare or enable the ADC clock.\n");
 
 	/*
 	 * Prescaler rate computation using the formula from the Atmel's
@@ -1117,10 +1108,9 @@ static int at91_adc_probe(struct platform_device *pdev)
 
 	prsc = (mstrclk / (2 * adc_clk)) - 1;
 
-	if (!st->startup_time) {
-		dev_err(&pdev->dev, "No startup time available.\n");
-		return -EINVAL;
-	}
+	if (!st->startup_time)
+		return dev_err_probe(&pdev->dev, -EINVAL,
+				     "No startup time available.\n");
 	ticks = (*st->caps->calc_startup_ticks)(st->startup_time, adc_clk_khz);
 
 	/*
@@ -1145,10 +1135,9 @@ static int at91_adc_probe(struct platform_device *pdev)
 
 	/* Setup the ADC channels available on the board */
 	ret = at91_adc_channel_init(idev);
-	if (ret < 0) {
-		dev_err(&pdev->dev, "Couldn't initialize the channels.\n");
-		return ret;
-	}
+	if (ret < 0)
+		return dev_err_probe(&pdev->dev, ret,
+				     "Couldn't initialize the channels.\n");
 
 	init_waitqueue_head(&st->wq_data_avail);
 	mutex_init(&st->lock);
@@ -1160,10 +1149,9 @@ static int at91_adc_probe(struct platform_device *pdev)
 	 */
 	if (!st->touchscreen_type) {
 		ret = at91_adc_buffer_init(idev);
-		if (ret < 0) {
-			dev_err(&pdev->dev, "Couldn't initialize the buffer.\n");
-			return ret;
-		}
+		if (ret < 0)
+			return dev_err_probe(&pdev->dev, ret,
+					     "Couldn't initialize the buffer.\n");
 
 		ret = at91_adc_trigger_init(idev);
 		if (ret < 0) {
-- 
2.34.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH -next v3 0/3] iio: adc: at91_adc: Cleanup with the helpers
  2023-08-28  6:45 [PATCH -next v3 0/3] iio: adc: at91_adc: Cleanup with the helpers Jinjie Ruan
                   ` (2 preceding siblings ...)
  2023-08-28  6:45 ` [PATCH -next v3 3/3] iio: adc: at91_adc: Simplify with dev_err_probe() Jinjie Ruan
@ 2023-08-28 11:12 ` Jonathan Cameron
  3 siblings, 0 replies; 5+ messages in thread
From: Jonathan Cameron @ 2023-08-28 11:12 UTC (permalink / raw)
  To: Jinjie Ruan
  Cc: robh, alexandre.belloni, lars, heiko, linux-iio, claudiu.beznea,
	yangyingliang, linux-arm-kernel

On Mon, 28 Aug 2023 14:45:43 +0800
Jinjie Ruan <ruanjinjie@huawei.com> wrote:

> Commit 7ef9651e9792 ("clk: Provide new devm_clk helpers for prepared
> and enabled clocks") provides a new helper function to prepare and
> enable a clock which keeps prepared (or enabled) during the whole
> lifetime of the driver.
> 
> Use devm_request_irq() to request the interrupt, so we can
> avoid having to manually clean this up.
> 
> Use the dev_err_probe() helper to simplify error handling during probe.
> This also handle scenario, when EDEFER is returned and useless
> error is printed.
> 
> changes in v3:
> - Take the last remove free_irq() and add it to be the first devm managed.
> - Not going any longer than 80 chars than is necessary.
> 
> Changes in v2:
> - Also use devm_request_irq() and dev_err_probe() to clean up the at91_adc.
> - Split the at91_adc patch out to be a new patch set.
> 
> Jinjie Ruan (3):
>   iio: adc: at91_adc: Use devm_request_irq() helper function
>   iio: adc: at91_adc: Use devm_clk_get_enabled() helper function
>   iio: adc: at91_adc: Simplify with dev_err_probe()
> 
>  drivers/iio/adc/at91_adc.c | 108 +++++++++++++------------------------
>  1 file changed, 37 insertions(+), 71 deletions(-)
> 

Series applied.

Thanks for jumping through the various hoops that came up in review!

Note that whilst I have applied this, that is mostly about my tracking
rather than meaning others cannot continue to comment on it.

I won't be pushing this out as a non rebasing tree (which linux-next will
pick up) for a few weeks.

Jonathan

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

end of thread, other threads:[~2023-08-28 11:12 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-08-28  6:45 [PATCH -next v3 0/3] iio: adc: at91_adc: Cleanup with the helpers Jinjie Ruan
2023-08-28  6:45 ` [PATCH -next v3 1/3] iio: adc: at91_adc: Use devm_request_irq() helper function Jinjie Ruan
2023-08-28  6:45 ` [PATCH -next v3 2/3] iio: adc: at91_adc: Use devm_clk_get_enabled() " Jinjie Ruan
2023-08-28  6:45 ` [PATCH -next v3 3/3] iio: adc: at91_adc: Simplify with dev_err_probe() Jinjie Ruan
2023-08-28 11:12 ` [PATCH -next v3 0/3] iio: adc: at91_adc: Cleanup with the helpers Jonathan Cameron

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox