Skip to contentSkip to conversation

iio: adc: twl6030-gpadc: convert probe/remove cleanup to devm

PATCH In review Wanhui Fu 3 participants 6 messages Dec 4 – Dec 5 IIO

lore
Share & tools
lore

Wanhui Fu

author
#0 lore raw

v5 cover iio: adc: twl6030-gpadc: convert probe/remove cleanup to devm

This series uses devm to manage interrupt masking and IIO device registration in the TWL6030 GPADC driver. It also removes redundant I2C error messages from probe.

Patch 1 registers the interrupt masking action with devm. Patch 2 uses devm for IIO device registration and mutex initialization. Patch 3 removes redundant probe error messages.

Compile-tested passed.

Changes in v5:
- Pass the GPADC private data to the interrupt cleanup action and read the IRQ mask from it. Thanks, Andy!
- Move irq_mask after pdata to keep the original member offsets and place the three bytes of padding at the end. On ARM32, pahole reports 48 bytes with mutex debugging disabled and 52 bytes with it enabled, matching the v4 size in both builds.

Changes in v4:
- Store the IRQ mask in struct twl6030_gpadc_data. Thanks, Andy!
- Use devm_mutex_init() and check its return value. Thanks, Joshua!
- Wrap the commit messages to 75 characters.

Changes in v3:
- Add details to 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 | 50 +++++++++++++++------------------
 1 file changed, 22 insertions(+), 28 deletions(-)

base-commit: 25faec9ce61c01fb45abf812a222c5b43c3cd5c5

Signature · 1 line
2.25.1
author
#1 lore raw

PATCH v5 1/3 iio: adc: twl6030-gpadc: use devm_add_action_or_reset() to disable IRQ

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

Store the interrupt mask in struct twl6030_gpadc_data and pass the private data to the cleanup action. Use the stored mask when enabling and disabling the interrupt.

Fixes 1696f36482e7 ("iio: twl6030-gpadc: TWL6030, TWL6032 GPADC driver")

---
Found by code inspection.

Changes in v5:
- Pass the GPADC private data to the interrupt cleanup action.
- Place irq_mask after pdata to avoid a hole between members.

Changes in v4:
- Store the interrupt mask in the private data. Thanks, Andy!

Changes in v3:
- Add details to the commit message. Thanks, Jonathan!

 drivers/iio/adc/twl6030-gpadc.c | 18 +++++++++++++-----
 1 file changed, 13 insertions(+), 5 deletions(-)
drivers/iio/adc/twl6030-gpadc.c +13 -5
index e7fd371b3404..d35d22ae1a35 100644
@@ -129,6 +129,7 @@ struct twl6030_gpadc_platform_data {
  * @twl6030_cal_tbl:	pointer to calibration data for each
  *			channel with gain error and offset
  * @pdata:		pointer to device specific data
+ * @irq_mask:		GPADC interrupt mask
  */
 struct twl6030_gpadc_data {
 	struct device	*dev;
@@ -136,6 +137,7 @@ struct twl6030_gpadc_data {
 	struct completion	irq_complete;
 	struct twl6030_chnl_calib	*twl6030_cal_tbl;
 	const struct twl6030_gpadc_platform_data *pdata;
+	u8	irq_mask;
 };
 
 /*
@@ -373,10 +375,12 @@ 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)
 {
-	twl6030_interrupt_mask(mask, REG_INT_MSK_LINE_B);
-	twl6030_interrupt_mask(mask, REG_INT_MSK_STS_B);
+	struct twl6030_gpadc_data *gpadc = data;
+
+	twl6030_interrupt_mask(gpadc->irq_mask, REG_INT_MSK_LINE_B);
+	twl6030_interrupt_mask(gpadc->irq_mask, REG_INT_MSK_STS_B);
 }
 
 static irqreturn_t twl6030_gpadc_irq_handler(int irq, void *indio_dev)
@@ -900,6 +904,7 @@ static int twl6030_gpadc_probe(struct platform_device *pdev)
 
 	gpadc->dev = dev;
 	gpadc->pdata = pdata;
+	gpadc->irq_mask = TWL6030_GPADC_RT_SW1_EOC_MASK;
 
 	platform_set_drvdata(pdev, indio_dev);
 	mutex_init(&gpadc->lock);
@@ -921,12 +926,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(gpadc->irq_mask);
 	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, gpadc);
+	if (ret)
+		return ret;
+
 	ret = twl_i2c_write_u8(TWL6030_MODULE_ID1, TWL6030_GPADCS,
 					TWL6030_REG_TOGGLE1);
 	if (ret < 0) {
@@ -967,7 +976,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);
 }
 
Signature · 1 line
2.25.1
maintainer
#2 lore raw

Re: [PATCH v5 1/3] iio: adc: twl6030-gpadc: use devm_add_action_or_reset() to disable IRQ

Quoted 10 lines · On Sat, 5 Dec 2026 01:15:37 +0800 Wanhui Fu <[email protected]> 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().

Quoted 5 lines

Store the interrupt mask in struct twl6030_gpadc_data and pass the private data to the cleanup action. Use the stored mask when enabling and disabling the interrupt.

Fixes 1696f36482e7 ("iio: twl6030-gpadc: TWL6030, TWL6032 GPADC driver")

This has somehow lost your Sign-off

Unfortunately without that the Developer Certificate of Origin doesn't apply and I can't apply it! :(

So please send a v6 with that fixed up and Andy's tag.

author
#3 lore raw

PATCH v5 2/3 iio: adc: twl6030-gpadc: switch to devm_iio_device_register()

In reply to 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.

Use devm_mutex_init() to manage the mutex lifetime as well, and handle initialization errors.

---
Changes in v4:
- Use devm_mutex_init() and check its return value. Thanks, Joshua!

 drivers/iio/adc/twl6030-gpadc.c | 16 +++++-----------
 1 file changed, 5 insertions(+), 11 deletions(-)
drivers/iio/adc/twl6030-gpadc.c +5 -11
index d35d22ae1a35..4dcce641c53d 100644
@@ -906,8 +906,10 @@ static int twl6030_gpadc_probe(struct platform_device *pdev)
 	gpadc->pdata = pdata;
 	gpadc->irq_mask = TWL6030_GPADC_RT_SW1_EOC_MASK;
 
-	platform_set_drvdata(pdev, indio_dev);
-	mutex_init(&gpadc->lock);
+	ret = devm_mutex_init(dev, &gpadc->lock);
+	if (ret)
+		return ret;
+
 	init_completion(&gpadc->irq_complete);
 
 	ret = pdata->calibrate(gpadc);
@@ -969,14 +971,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)
@@ -1008,7 +1003,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),
Signature · 1 line
2.25.1
author
#4 lore raw

PATCH v5 3/3 iio: adc: twl6030-gpadc: delete redundant dev_err() messages in probe

In reply to Wanhui Fu

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

---
Changes in v4:
- Wrap the commit message to around 75 columns.

 drivers/iio/adc/twl6030-gpadc.c | 16 ++++------------
 1 file changed, 4 insertions(+), 12 deletions(-)
drivers/iio/adc/twl6030-gpadc.c +4 -12
index 4dcce641c53d..59f064c4b845 100644
@@ -940,30 +940,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;
Signature · 1 line
2.25.1
Reviewed-by on the v5 series
#5 lore raw
In reply to Wanhui Fu
Quoted 7 lines · Wanhui Fu

This series uses devm to manage interrupt masking and IIO device registration in the TWL6030 GPADC driver. It also removes redundant I2C error messages from probe.

Patch 1 registers the interrupt masking action with devm. Patch 2 uses devm for IIO device registration and mutex initialization. Patch 3 removes redundant probe error messages.

All LGTM now

Signature · 2 lines
With Best Regards,
Andy Shevchenko