Linux IIO development
 help / color / mirror / Atom feed
* [PATCH v3 0/3] iio: adc: twl6030-gpadc: convert probe/remove cleanup to devm
@ 2026-11-30  3:03 Wanhui Fu
  2026-11-30  3:03 ` [PATCH v3 1/3] iio: adc: twl6030-gpadc: use devm_add_action_or_reset() to disable IRQ Wanhui Fu
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Wanhui Fu @ 2026-11-30  3:03 UTC (permalink / raw)
  To: jic23, dlechner, nuno.sa, andy, bhelgaas, giorgitchankvetadze1997,
	o-takashi, kees+treewide, u.kleine-koenig
  Cc: linux-iio, Wanhui Fu

This series converts twl6030-gpadc's probe error
handling and remove path to devm cleanup, and
deletes redundant dev_err() messages in probe.

- Patch 1 registers twl6030_gpadc_disable_irq()
  with devm_add_action_or_reset().
- Patch 2 converts iio_device_register() to
  devm_iio_device_register().
- Patch 3 deletes redundant dev_err() messages in probe.

Compile-tested only.

Changes in v3:
- Add some details in Patch 1's commit message.
- No code changes. Patches 2 and 3 are unchanged.

Changes in v2:
- Use devm_add_action_or_reset() instead of a
  goto error path. Thanks, Jonathan!
- Convert to devm_iio_device_register() and drop
  remove(). Thanks, Jonathan!
- Drop redundant dev_err() messages after twl_i2c_write_u8().
  Thanks, Andreas!

Wanhui Fu (3):
  iio: adc: twl6030-gpadc: use devm_add_action_or_reset() to disable IRQ
  iio: adc: twl6030-gpadc: switch to devm_iio_device_register()
  iio: adc: twl6030-gpadc: delete redundant dev_err() messages in probe

 drivers/iio/adc/twl6030-gpadc.c | 41 ++++++++++++---------------------
 1 file changed, 15 insertions(+), 26 deletions(-)

-- 
2.25.1


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

* [PATCH v3 1/3] iio: adc: twl6030-gpadc: use devm_add_action_or_reset() to disable IRQ
  2026-11-30  3:03 [PATCH v3 0/3] iio: adc: twl6030-gpadc: convert probe/remove cleanup to devm Wanhui Fu
@ 2026-11-30  3:03 ` Wanhui Fu
  2026-11-30  9:13   ` Joshua Crofts
  2026-11-30  3:03 ` [PATCH v3 2/3] iio: adc: twl6030-gpadc: switch to devm_iio_device_register() Wanhui Fu
  2026-11-30  3:03 ` [PATCH v3 3/3] iio: adc: twl6030-gpadc: delete redundant dev_err() messages in probe Wanhui Fu
  2 siblings, 1 reply; 7+ messages in thread
From: Wanhui Fu @ 2026-11-30  3:03 UTC (permalink / raw)
  To: jic23, dlechner, nuno.sa, andy, bhelgaas, giorgitchankvetadze1997,
	o-takashi, kees+treewide, u.kleine-koenig
  Cc: linux-iio, Wanhui Fu

twl6030_gpadc_probe() unmasks the GPADC interrupt before completing
the remaining hardware setup and IIO device registration. If a later
step fails, probe returns without calling twl6030_gpadc_disable_irq(),
which could cause unnecessary interrupts and CPU wakeups.

Register twl6030_gpadc_disable_irq() with devm_add_action_or_reset()
after enabling the interrupt so that it is masked on subsequent
probe failures and driver detach, before the managed IRQ is freed.
Remove the manual call from twl6030_gpadc_remove().

Drop the mask argument from the enable and disable helpers, since
the mask is always TWL6030_GPADC_RT_SW1_EOC_MASK.

Fixes: 1696f36482e7 ("iio: twl6030-gpadc: TWL6030, TWL6032 GPADC driver")
Signed-off-by: Wanhui Fu <fuwh1120@163.com>
---
Found by code inspection.

Changes in v3:
 - Add some details in commit message. Thanks, Jonathan!
---
 drivers/iio/adc/twl6030-gpadc.c | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/drivers/iio/adc/twl6030-gpadc.c b/drivers/iio/adc/twl6030-gpadc.c
index e7fd371b3404..786059cf7513 100644
--- a/drivers/iio/adc/twl6030-gpadc.c
+++ b/drivers/iio/adc/twl6030-gpadc.c
@@ -360,8 +360,9 @@ static inline int twl6030_gpadc_read(u8 reg, u8 *val)
 	return twl_i2c_read(TWL6030_MODULE_GPADC, val, reg, 2);
 }
 
-static int twl6030_gpadc_enable_irq(u8 mask)
+static int twl6030_gpadc_enable_irq(void)
 {
+	u8 mask = TWL6030_GPADC_RT_SW1_EOC_MASK;
 	int ret;
 
 	ret = twl6030_interrupt_unmask(mask, REG_INT_MSK_LINE_B);
@@ -373,8 +374,10 @@ static int twl6030_gpadc_enable_irq(u8 mask)
 	return ret;
 }
 
-static void twl6030_gpadc_disable_irq(u8 mask)
+static void twl6030_gpadc_disable_irq(void *data)
 {
+	u8 mask = TWL6030_GPADC_RT_SW1_EOC_MASK;
+
 	twl6030_interrupt_mask(mask, REG_INT_MSK_LINE_B);
 	twl6030_interrupt_mask(mask, REG_INT_MSK_STS_B);
 }
@@ -921,12 +924,16 @@ static int twl6030_gpadc_probe(struct platform_device *pdev)
 	if (ret)
 		return ret;
 
-	ret = twl6030_gpadc_enable_irq(TWL6030_GPADC_RT_SW1_EOC_MASK);
+	ret = twl6030_gpadc_enable_irq();
 	if (ret < 0) {
 		dev_err(dev, "failed to enable GPADC interrupt\n");
 		return ret;
 	}
 
+	ret = devm_add_action_or_reset(dev, twl6030_gpadc_disable_irq, NULL);
+	if (ret)
+		return ret;
+
 	ret = twl_i2c_write_u8(TWL6030_MODULE_ID1, TWL6030_GPADCS,
 					TWL6030_REG_TOGGLE1);
 	if (ret < 0) {
@@ -967,7 +974,6 @@ static void twl6030_gpadc_remove(struct platform_device *pdev)
 {
 	struct iio_dev *indio_dev = platform_get_drvdata(pdev);
 
-	twl6030_gpadc_disable_irq(TWL6030_GPADC_RT_SW1_EOC_MASK);
 	iio_device_unregister(indio_dev);
 }
 
-- 
2.25.1


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

* [PATCH v3 2/3] iio: adc: twl6030-gpadc: switch to devm_iio_device_register()
  2026-11-30  3:03 [PATCH v3 0/3] iio: adc: twl6030-gpadc: convert probe/remove cleanup to devm Wanhui Fu
  2026-11-30  3:03 ` [PATCH v3 1/3] iio: adc: twl6030-gpadc: use devm_add_action_or_reset() to disable IRQ Wanhui Fu
@ 2026-11-30  3:03 ` Wanhui Fu
  2026-11-30  9:11   ` Joshua Crofts
  2026-11-30  3:03 ` [PATCH v3 3/3] iio: adc: twl6030-gpadc: delete redundant dev_err() messages in probe Wanhui Fu
  2 siblings, 1 reply; 7+ messages in thread
From: Wanhui Fu @ 2026-11-30  3:03 UTC (permalink / raw)
  To: jic23, dlechner, nuno.sa, andy, bhelgaas, giorgitchankvetadze1997,
	o-takashi, kees+treewide, u.kleine-koenig
  Cc: linux-iio, Wanhui Fu

Convert iio_device_register() to devm_iio_device_register().
This allows dropping the now-empty twl6030_gpadc_remove() and
the unused platform_set_drvdata() call.

Signed-off-by: Wanhui Fu <fuwh1120@163.com>
---
 drivers/iio/adc/twl6030-gpadc.c | 11 +----------
 1 file changed, 1 insertion(+), 10 deletions(-)

diff --git a/drivers/iio/adc/twl6030-gpadc.c b/drivers/iio/adc/twl6030-gpadc.c
index 786059cf7513..591c7b3322c7 100644
--- a/drivers/iio/adc/twl6030-gpadc.c
+++ b/drivers/iio/adc/twl6030-gpadc.c
@@ -904,7 +904,6 @@ static int twl6030_gpadc_probe(struct platform_device *pdev)
 	gpadc->dev = dev;
 	gpadc->pdata = pdata;
 
-	platform_set_drvdata(pdev, indio_dev);
 	mutex_init(&gpadc->lock);
 	init_completion(&gpadc->irq_complete);
 
@@ -967,14 +966,7 @@ static int twl6030_gpadc_probe(struct platform_device *pdev)
 	indio_dev->channels = pdata->iio_channels;
 	indio_dev->num_channels = pdata->nchannels;
 
-	return iio_device_register(indio_dev);
-}
-
-static void twl6030_gpadc_remove(struct platform_device *pdev)
-{
-	struct iio_dev *indio_dev = platform_get_drvdata(pdev);
-
-	iio_device_unregister(indio_dev);
+	return devm_iio_device_register(dev, indio_dev);
 }
 
 static int twl6030_gpadc_suspend(struct device *pdev)
@@ -1006,7 +998,6 @@ static DEFINE_SIMPLE_DEV_PM_OPS(twl6030_gpadc_pm_ops, twl6030_gpadc_suspend,
 
 static struct platform_driver twl6030_gpadc_driver = {
 	.probe		= twl6030_gpadc_probe,
-	.remove		= twl6030_gpadc_remove,
 	.driver		= {
 		.name	= DRIVER_NAME,
 		.pm	= pm_sleep_ptr(&twl6030_gpadc_pm_ops),
-- 
2.25.1


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

* [PATCH v3 3/3] iio: adc: twl6030-gpadc: delete redundant dev_err() messages in probe
  2026-11-30  3:03 [PATCH v3 0/3] iio: adc: twl6030-gpadc: convert probe/remove cleanup to devm Wanhui Fu
  2026-11-30  3:03 ` [PATCH v3 1/3] iio: adc: twl6030-gpadc: use devm_add_action_or_reset() to disable IRQ Wanhui Fu
  2026-11-30  3:03 ` [PATCH v3 2/3] iio: adc: twl6030-gpadc: switch to devm_iio_device_register() Wanhui Fu
@ 2026-11-30  3:03 ` Wanhui Fu
  2026-11-30  9:14   ` Joshua Crofts
  2 siblings, 1 reply; 7+ messages in thread
From: Wanhui Fu @ 2026-11-30  3:03 UTC (permalink / raw)
  To: jic23, dlechner, nuno.sa, andy, bhelgaas, giorgitchankvetadze1997,
	o-takashi, kees+treewide, u.kleine-koenig
  Cc: linux-iio, Wanhui Fu

twl_i2c_write() already logs error messages on I2C transfer
failures, so remove redundant dev_err() to simplify the probe
function.

Signed-off-by: Wanhui Fu <fuwh1120@163.com>
---
 drivers/iio/adc/twl6030-gpadc.c | 16 ++++------------
 1 file changed, 4 insertions(+), 12 deletions(-)

diff --git a/drivers/iio/adc/twl6030-gpadc.c b/drivers/iio/adc/twl6030-gpadc.c
index 591c7b3322c7..6e20e5a31211 100644
--- a/drivers/iio/adc/twl6030-gpadc.c
+++ b/drivers/iio/adc/twl6030-gpadc.c
@@ -935,30 +935,22 @@ static int twl6030_gpadc_probe(struct platform_device *pdev)
 
 	ret = twl_i2c_write_u8(TWL6030_MODULE_ID1, TWL6030_GPADCS,
 					TWL6030_REG_TOGGLE1);
-	if (ret < 0) {
-		dev_err(dev, "failed to enable GPADC module\n");
+	if (ret < 0)
 		return ret;
-	}
 
 	ret = twl_i2c_write_u8(TWL_MODULE_USB, VBUS_MEAS, USB_VBUS_CTRL_SET);
-	if (ret < 0) {
-		dev_err(dev, "failed to wire up inputs\n");
+	if (ret < 0)
 		return ret;
-	}
 
 	ret = twl_i2c_write_u8(TWL_MODULE_USB, ID_MEAS, USB_ID_CTRL_SET);
-	if (ret < 0) {
-		dev_err(dev, "failed to wire up inputs\n");
+	if (ret < 0)
 		return ret;
-	}
 
 	ret = twl_i2c_write_u8(TWL6030_MODULE_ID0,
 				VBAT_MEAS | BB_MEAS | VAC_MEAS,
 				TWL6030_MISC1);
-	if (ret < 0) {
-		dev_err(dev, "failed to wire up inputs\n");
+	if (ret < 0)
 		return ret;
-	}
 
 	indio_dev->name = DRIVER_NAME;
 	indio_dev->info = &twl6030_gpadc_iio_info;
-- 
2.25.1


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

* Re: [PATCH v3 2/3] iio: adc: twl6030-gpadc: switch to devm_iio_device_register()
  2026-11-30  3:03 ` [PATCH v3 2/3] iio: adc: twl6030-gpadc: switch to devm_iio_device_register() Wanhui Fu
@ 2026-11-30  9:11   ` Joshua Crofts
  0 siblings, 0 replies; 7+ messages in thread
From: Joshua Crofts @ 2026-11-30  9:11 UTC (permalink / raw)
  To: Wanhui Fu, jic23, dlechner, nuno.sa, andy, bhelgaas,
	giorgitchankvetadze1997, o-takashi, kees+treewide,
	u.kleine-koenig
  Cc: linux-iio

On 30-Nov-26 4:03, Wanhui Fu wrote:
> Convert iio_device_register() to devm_iio_device_register().
> This allows dropping the now-empty twl6030_gpadc_remove() and
> the unused platform_set_drvdata() call.
> 
> Signed-off-by: Wanhui Fu <fuwh1120@163.com>
> ---
>  drivers/iio/adc/twl6030-gpadc.c | 11 +----------
>  1 file changed, 1 insertion(+), 10 deletions(-)
> 
> diff --git a/drivers/iio/adc/twl6030-gpadc.c b/drivers/iio/adc/twl6030-gpadc.c
> index 786059cf7513..591c7b3322c7 100644
> --- a/drivers/iio/adc/twl6030-gpadc.c
> +++ b/drivers/iio/adc/twl6030-gpadc.c
> @@ -904,7 +904,6 @@ static int twl6030_gpadc_probe(struct platform_device *pdev)
>  	gpadc->dev = dev;
>  	gpadc->pdata = pdata;
>  
> -	platform_set_drvdata(pdev, indio_dev);
>  	mutex_init(&gpadc->lock);
You should also switch to devm_mutex_init() since you're doing a devm_*
conversion.

-- 
Kind regards,
Joshua Crofts


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

* Re: [PATCH v3 1/3] iio: adc: twl6030-gpadc: use devm_add_action_or_reset() to disable IRQ
  2026-11-30  3:03 ` [PATCH v3 1/3] iio: adc: twl6030-gpadc: use devm_add_action_or_reset() to disable IRQ Wanhui Fu
@ 2026-11-30  9:13   ` Joshua Crofts
  0 siblings, 0 replies; 7+ messages in thread
From: Joshua Crofts @ 2026-11-30  9:13 UTC (permalink / raw)
  To: Wanhui Fu, jic23, dlechner, nuno.sa, andy, bhelgaas,
	giorgitchankvetadze1997, o-takashi, kees+treewide,
	u.kleine-koenig
  Cc: linux-iio

On 30-Nov-26 4:03, Wanhui Fu wrote:
> twl6030_gpadc_probe() unmasks the GPADC interrupt before completing
> the remaining hardware setup and IIO device registration. If a later
> step fails, probe returns without calling twl6030_gpadc_disable_irq(),
> which could cause unnecessary interrupts and CPU wakeups.
> 
> Register twl6030_gpadc_disable_irq() with devm_add_action_or_reset()
> after enabling the interrupt so that it is masked on subsequent
> probe failures and driver detach, before the managed IRQ is freed.
> Remove the manual call from twl6030_gpadc_remove().
> 
> Drop the mask argument from the enable and disable helpers, since
> the mask is always TWL6030_GPADC_RT_SW1_EOC_MASK.
> 
> Fixes: 1696f36482e7 ("iio: twl6030-gpadc: TWL6030, TWL6032 GPADC driver")
> Signed-off-by: Wanhui Fu <fuwh1120@163.com>
> ---
Reviewed-by: Joshua Crofts <crofts@kernel.org>

-- 
Kind regards,
Joshua Crofts


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

* Re: [PATCH v3 3/3] iio: adc: twl6030-gpadc: delete redundant dev_err() messages in probe
  2026-11-30  3:03 ` [PATCH v3 3/3] iio: adc: twl6030-gpadc: delete redundant dev_err() messages in probe Wanhui Fu
@ 2026-11-30  9:14   ` Joshua Crofts
  0 siblings, 0 replies; 7+ messages in thread
From: Joshua Crofts @ 2026-11-30  9:14 UTC (permalink / raw)
  To: Wanhui Fu, jic23, dlechner, nuno.sa, andy, bhelgaas,
	giorgitchankvetadze1997, o-takashi, kees+treewide,
	u.kleine-koenig
  Cc: linux-iio

On 30-Nov-26 4:03, Wanhui Fu wrote:
> twl_i2c_write() already logs error messages on I2C transfer
> failures, so remove redundant dev_err() to simplify the probe
> function.

Wrap the commit message to ~75 characters per line.

> Signed-off-by: Wanhui Fu <fuwh1120@163.com>
> ---

Reviewed-by: Joshua Crofts <crofts@kernel.org>

-- 
Kind regards,
Joshua Crofts


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

end of thread, other threads:[~2026-11-30  9:14 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-30  3:03 [PATCH v3 0/3] iio: adc: twl6030-gpadc: convert probe/remove cleanup to devm Wanhui Fu
2026-11-30  3:03 ` [PATCH v3 1/3] iio: adc: twl6030-gpadc: use devm_add_action_or_reset() to disable IRQ Wanhui Fu
2026-11-30  9:13   ` Joshua Crofts
2026-11-30  3:03 ` [PATCH v3 2/3] iio: adc: twl6030-gpadc: switch to devm_iio_device_register() Wanhui Fu
2026-11-30  9:11   ` Joshua Crofts
2026-11-30  3:03 ` [PATCH v3 3/3] iio: adc: twl6030-gpadc: delete redundant dev_err() messages in probe Wanhui Fu
2026-11-30  9:14   ` Joshua Crofts

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