Linux IIO development
 help / color / mirror / Atom feed
* Re: [PATCH] counter: ti-eqep: fix runtime PM leak in probe error path
From: David Lechner @ 2026-04-17 15:20 UTC (permalink / raw)
  To: Felix Gu, William Breathitt Gray, Judith Mendez
  Cc: linux-iio, linux-kernel, Linux PM
In-Reply-To: <20260417-ti-eqep-v1-1-a7db4642d9d0@gmail.com>

My knowledge of pm_runtime is a bit lacking, so I would suggest
to include that mailing list on the CC to get more expert review.


On 4/17/26 10:06 AM, Felix Gu wrote:
> In ti_eqep_probe(), if devm_clk_get_enabled() fails, the function
> returns without cleaning up the runtime PM state.
> 
> Fixes: 0cf81c73e4c6 ("counter: ti-eqep: enable clock at probe")
> Signed-off-by: Felix Gu <ustc.gu@gmail.com>
> ---
>  drivers/counter/ti-eqep.c | 19 ++++++++++++-------
>  1 file changed, 12 insertions(+), 7 deletions(-)
> 
> diff --git a/drivers/counter/ti-eqep.c b/drivers/counter/ti-eqep.c
> index d21c157e531a..dfa945b3eec6 100644
> --- a/drivers/counter/ti-eqep.c
> +++ b/drivers/counter/ti-eqep.c
> @@ -548,17 +548,22 @@ static int ti_eqep_probe(struct platform_device *pdev)

Can we use devm_pm_runtime_enable() to partially solve this?

>  	pm_runtime_get_sync(dev);

I don't think we should have non-devm stuff before devm stuff
so this needs to be moved later of have some kind of devm cleanup.

>  
>  	clk = devm_clk_get_enabled(dev, NULL);
> -	if (IS_ERR(clk))
> -		return dev_err_probe(dev, PTR_ERR(clk), "failed to enable clock\n");
> +	if (IS_ERR(clk)) {
> +		err = dev_err_probe(dev, PTR_ERR(clk), "failed to enable clock\n");
> +		goto disable_pm;
> +	}
>  
>  	err = counter_add(counter);

This can be changed to devm_counter_add().

> -	if (err < 0) {
> -		pm_runtime_put_sync(dev);
> -		pm_runtime_disable(dev);
> -		return err;
> -	}
> +	if (err < 0)
> +		goto disable_pm;
>  
>  	return 0;
> +
> +disable_pm:
> +	pm_runtime_put_sync(dev);
> +	pm_runtime_disable(dev);
> +
> +	return err;
>  }
>  
>  static void ti_eqep_remove(struct platform_device *pdev)

And once everything is converted to devm, we can drop the
remove callback.

> 
> ---
> base-commit: 452c3b1ea875276105ac90ba474f72b4cd9b77a2
> change-id: 20260417-ti-eqep-8efb9cc713ea
> 
> Best regards,


^ permalink raw reply

* Re: [PATCH v2] dt-bindings: iio: dac: mcp47feb02: Fix maxItems value for reg property
From: David Lechner @ 2026-04-17 15:26 UTC (permalink / raw)
  To: Ariana Lazar, Jonathan Cameron, Nuno Sá, Andy Shevchenko,
	Rob Herring, Krzysztof Kozlowski, Conor Dooley
  Cc: Conor Dooley, Jonathan Cameron, linux-iio, devicetree,
	linux-kernel
In-Reply-To: <20260417-mcp47feb02-fix5-v2-1-6592ea499cce@microchip.com>

On 4/17/26 8:38 AM, Ariana Lazar wrote:
> Change maxItems value from 8 to 1 for the channel number reg property.

The commit message needs to explain why this is the correct thing to do.

> 
> Fixes: 4ba12d304175 ("dt-bindings: iio: dac: adding support for Microchip MCP47FEB02")
> Link: https://lore.kernel.org/all/20260403-speed-childless-1360de358229@spud/
> Signed-off-by: Ariana Lazar <ariana.lazar@microchip.com>
> ---
> Changes in v2:
> - keep just maxItems value update in this patch
> - remove Reported-by from commit message
> - Link to v1: https://lore.kernel.org/r/20260416-mcp47feb02-fix5-v1-1-9656c2fed6d2@microchip.com
> ---
>  Documentation/devicetree/bindings/iio/dac/microchip,mcp47feb02.yaml | 3 +--
>  1 file changed, 1 insertion(+), 2 deletions(-)
> 
> diff --git a/Documentation/devicetree/bindings/iio/dac/microchip,mcp47feb02.yaml b/Documentation/devicetree/bindings/iio/dac/microchip,mcp47feb02.yaml
> index d2466aa6bda2106a8b695347a0edf38462294d03..f2efa0ccbaa32482dcdc69d98c1565518538793f 100644
> --- a/Documentation/devicetree/bindings/iio/dac/microchip,mcp47feb02.yaml
> +++ b/Documentation/devicetree/bindings/iio/dac/microchip,mcp47feb02.yaml
> @@ -161,8 +161,7 @@ patternProperties:
>      properties:
>        reg:
>          description: The channel number.
> -        minItems: 1
> -        maxItems: 8
> +        maxItems: 1
>  
>        label:
>          description: Unique name to identify which channel this is.
> 
> ---
> base-commit: d2a4ec19d2a2e54c23b5180e939994d3da4a6b91
> change-id: 20260416-mcp47feb02-fix5-26994c5b428c
> 
> Best regards,


^ permalink raw reply

* [PATCH] counter: ti-eqep: fix runtime PM leak in probe error path
From: Felix Gu @ 2026-04-17 15:06 UTC (permalink / raw)
  To: David Lechner, William Breathitt Gray, Judith Mendez
  Cc: linux-iio, linux-kernel, Felix Gu

In ti_eqep_probe(), if devm_clk_get_enabled() fails, the function
returns without cleaning up the runtime PM state.

Fixes: 0cf81c73e4c6 ("counter: ti-eqep: enable clock at probe")
Signed-off-by: Felix Gu <ustc.gu@gmail.com>
---
 drivers/counter/ti-eqep.c | 19 ++++++++++++-------
 1 file changed, 12 insertions(+), 7 deletions(-)

diff --git a/drivers/counter/ti-eqep.c b/drivers/counter/ti-eqep.c
index d21c157e531a..dfa945b3eec6 100644
--- a/drivers/counter/ti-eqep.c
+++ b/drivers/counter/ti-eqep.c
@@ -548,17 +548,22 @@ static int ti_eqep_probe(struct platform_device *pdev)
 	pm_runtime_get_sync(dev);
 
 	clk = devm_clk_get_enabled(dev, NULL);
-	if (IS_ERR(clk))
-		return dev_err_probe(dev, PTR_ERR(clk), "failed to enable clock\n");
+	if (IS_ERR(clk)) {
+		err = dev_err_probe(dev, PTR_ERR(clk), "failed to enable clock\n");
+		goto disable_pm;
+	}
 
 	err = counter_add(counter);
-	if (err < 0) {
-		pm_runtime_put_sync(dev);
-		pm_runtime_disable(dev);
-		return err;
-	}
+	if (err < 0)
+		goto disable_pm;
 
 	return 0;
+
+disable_pm:
+	pm_runtime_put_sync(dev);
+	pm_runtime_disable(dev);
+
+	return err;
 }
 
 static void ti_eqep_remove(struct platform_device *pdev)

---
base-commit: 452c3b1ea875276105ac90ba474f72b4cd9b77a2
change-id: 20260417-ti-eqep-8efb9cc713ea

Best regards,
-- 
Felix Gu <ustc.gu@gmail.com>


^ permalink raw reply related

* [PATCH v2] dt-bindings: iio: dac: mcp47feb02: Fix maxItems value for reg property
From: Ariana Lazar @ 2026-04-17 13:38 UTC (permalink / raw)
  To: Jonathan Cameron, David Lechner, Nuno Sá, Andy Shevchenko,
	Rob Herring, Krzysztof Kozlowski, Conor Dooley
  Cc: Conor Dooley, Jonathan Cameron, linux-iio, devicetree,
	linux-kernel, Ariana Lazar

Change maxItems value from 8 to 1 for the channel number reg property.

Fixes: 4ba12d304175 ("dt-bindings: iio: dac: adding support for Microchip MCP47FEB02")
Link: https://lore.kernel.org/all/20260403-speed-childless-1360de358229@spud/
Signed-off-by: Ariana Lazar <ariana.lazar@microchip.com>
---
Changes in v2:
- keep just maxItems value update in this patch
- remove Reported-by from commit message
- Link to v1: https://lore.kernel.org/r/20260416-mcp47feb02-fix5-v1-1-9656c2fed6d2@microchip.com
---
 Documentation/devicetree/bindings/iio/dac/microchip,mcp47feb02.yaml | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/Documentation/devicetree/bindings/iio/dac/microchip,mcp47feb02.yaml b/Documentation/devicetree/bindings/iio/dac/microchip,mcp47feb02.yaml
index d2466aa6bda2106a8b695347a0edf38462294d03..f2efa0ccbaa32482dcdc69d98c1565518538793f 100644
--- a/Documentation/devicetree/bindings/iio/dac/microchip,mcp47feb02.yaml
+++ b/Documentation/devicetree/bindings/iio/dac/microchip,mcp47feb02.yaml
@@ -161,8 +161,7 @@ patternProperties:
     properties:
       reg:
         description: The channel number.
-        minItems: 1
-        maxItems: 8
+        maxItems: 1
 
       label:
         description: Unique name to identify which channel this is.

---
base-commit: d2a4ec19d2a2e54c23b5180e939994d3da4a6b91
change-id: 20260416-mcp47feb02-fix5-26994c5b428c

Best regards,
-- 
Ariana Lazar <ariana.lazar@microchip.com>


^ permalink raw reply related

* Re: [PATCH] iio: adc: mcp3422: write bit operations with bitfield macros
From: Jonathan Cameron @ 2026-04-17 13:26 UTC (permalink / raw)
  To: Marcelo Machado Lage
  Cc: jic23, dlechner, nuno.sa, andy, Vinicius Lira, linux-iio
In-Reply-To: <20260417005041.484742-1-marcelomlage@usp.br>

On Thu, 16 Apr 2026 21:50:40 -0300
Marcelo Machado Lage <marcelomlage@usp.br> wrote:

> Replace manual bit manipulations with GENMASK(), FIELD_GET(),
> FIELD_PREP() and FIELD_MODIFY() calls. The resulting code is more
> readable and maintainable, and some macros previously defined in the
> header are not needed anymore.
> 
> Signed-off-by: Marcelo Machado Lage <marcelomlage@usp.br>
> Co-developed-by: Vinicius Lira <vinilira@usp.br>
> Signed-off-by: Vinicius Lira <vinilira@usp.br>
> ---
>  drivers/iio/adc/mcp3422.c | 43 ++++++++++++++++-----------------------
>  1 file changed, 18 insertions(+), 25 deletions(-)
> 
> diff --git a/drivers/iio/adc/mcp3422.c b/drivers/iio/adc/mcp3422.c
> index 50834fdcf738..d93036bf9a85 100644
> --- a/drivers/iio/adc/mcp3422.c
> +++ b/drivers/iio/adc/mcp3422.c
> @@ -13,6 +13,7 @@
>   * voltage unit is nV.
>   */
>  
> +#include <linux/bitfield.h>
>  #include <linux/err.h>
>  #include <linux/i2c.h>
>  #include <linux/module.h>
> @@ -25,9 +26,9 @@
>  #include <linux/iio/sysfs.h>
>  
>  /* Masks */
> -#define MCP3422_CHANNEL_MASK	0x60
> -#define MCP3422_PGA_MASK	0x03
> -#define MCP3422_SRATE_MASK	0x0C
> +#define MCP3422_CHANNEL_MASK	GENMASK(6, 5)
> +#define MCP3422_PGA_MASK	GENMASK(1, 0)
> +#define MCP3422_SRATE_MASK	GENMASK(3, 2)
>  #define MCP3422_SRATE_240	0x0
>  #define MCP3422_SRATE_60	0x1
>  #define MCP3422_SRATE_15	0x2
> @@ -38,13 +39,9 @@
>  #define MCP3422_PGA_8	3
>  #define MCP3422_CONT_SAMPLING	0x10
>  
> -#define MCP3422_CHANNEL(config)	(((config) & MCP3422_CHANNEL_MASK) >> 5)
> -#define MCP3422_PGA(config)	((config) & MCP3422_PGA_MASK)
> -#define MCP3422_SAMPLE_RATE(config)	(((config) & MCP3422_SRATE_MASK) >> 2)
> -
> -#define MCP3422_CHANNEL_VALUE(value) (((value) << 5) & MCP3422_CHANNEL_MASK)
> -#define MCP3422_PGA_VALUE(value) ((value) & MCP3422_PGA_MASK)
> -#define MCP3422_SAMPLE_RATE_VALUE(value) ((value << 2) & MCP3422_SRATE_MASK)
> +#define MCP3422_CHANNEL(config)		FIELD_GET(MCP3422_CHANNEL_MASK, config)
> +#define MCP3422_PGA(config)			FIELD_GET(MCP3422_PGA_MASK, config)
> +#define MCP3422_SAMPLE_RATE(config)	FIELD_GET(MCP3422_SRATE_MASK, config)

Drop these 3 macros and use FIELD_GET() inline instead just as you've done for the prep side.

>  
>  #define MCP3422_CHAN(_index) \
>  	{ \
> @@ -138,10 +135,10 @@ static int mcp3422_read_channel(struct mcp3422 *adc,
>  
>  	if (req_channel != MCP3422_CHANNEL(adc->config)) {
>  		config = adc->config;
> -		config &= ~MCP3422_CHANNEL_MASK;
> -		config |= MCP3422_CHANNEL_VALUE(req_channel);
> -		config &= ~MCP3422_PGA_MASK;
> -		config |= MCP3422_PGA_VALUE(adc->pga[req_channel]);
> +
> +		FIELD_MODIFY(MCP3422_CHANNEL_MASK, &config, req_channel);
> +		FIELD_MODIFY(MCP3422_PGA_MASK, &config, adc->pga[req_channel]);
> +
>  		ret = mcp3422_update_config(adc, config);
>  		if (ret < 0) {
>  			mutex_unlock(&adc->lock);
> @@ -211,10 +208,8 @@ static int mcp3422_write_raw(struct iio_dev *iio,
>  			if (val2 == mcp3422_scales[sample_rate][i]) {
>  				adc->pga[req_channel] = i;
>  
> -				config &= ~MCP3422_CHANNEL_MASK;
> -				config |= MCP3422_CHANNEL_VALUE(req_channel);
> -				config &= ~MCP3422_PGA_MASK;
> -				config |= MCP3422_PGA_VALUE(adc->pga[req_channel]);
> +				FIELD_MODIFY(MCP3422_CHANNEL_MASK, &config, req_channel);
> +				FIELD_MODIFY(MCP3422_PGA_MASK, &config, adc->pga[req_channel]);
>  
>  				return mcp3422_update_config(adc, config);
>  			}
> @@ -241,10 +236,8 @@ static int mcp3422_write_raw(struct iio_dev *iio,
>  			return -EINVAL;
>  		}
>  
> -		config &= ~MCP3422_CHANNEL_MASK;
> -		config |= MCP3422_CHANNEL_VALUE(req_channel);
> -		config &= ~MCP3422_SRATE_MASK;
> -		config |= MCP3422_SAMPLE_RATE_VALUE(temp);
> +		FIELD_MODIFY(MCP3422_CHANNEL_MASK, &config, req_channel);
> +		FIELD_MODIFY(MCP3422_SRATE_MASK, &config, temp);
>  
>  		return mcp3422_update_config(adc, config);
>  
> @@ -377,9 +370,9 @@ static int mcp3422_probe(struct i2c_client *client)
>  
>  	/* meaningful default configuration */
>  	config = (MCP3422_CONT_SAMPLING
> -		| MCP3422_CHANNEL_VALUE(0)
> -		| MCP3422_PGA_VALUE(MCP3422_PGA_1)
> -		| MCP3422_SAMPLE_RATE_VALUE(MCP3422_SRATE_240));
> +		| FIELD_PREP(MCP3422_CHANNEL_MASK, 0)
> +		| FIELD_PREP(MCP3422_PGA_MASK, MCP3422_PGA_1)
> +		| FIELD_PREP(MCP3422_SRATE_MASK, MCP3422_SRATE_240));
>  	err = mcp3422_update_config(adc, config);
>  	if (err < 0)
>  		return err;


^ permalink raw reply

* [PATCH v3] iio: adc: ad7280a: use cleanup helpers guard() and scoped_guard() for mutex locking
From: Lucas Ivars Cadima Ciziks @ 2026-04-17 13:09 UTC (permalink / raw)
  To: lars, Michael.Hennerich, jic23, dlechner, nuno.sa, andy
  Cc: Felipe Ribeiro de Souza, linux-iio

Replace open-coded mutex_lock/unlock pairs with the cleanup-based
guard() and scoped_guard() helpers in ad7280a_write_thresh(),
ad7280_show_balance_timer(), ad7280_store_balance_sw(),
ad7280_store_balance_timer() and ad7280_read_raw().

This removes the need for the err_unlock label and explicit
mutex_unlock() calls, as the lock is now automatically released
when the function returns or the guarded scope exits, regardless
of the exit path.

Signed-off-by: Lucas Ivars Cadima Ciziks <lucas@ciziks.com>
Co-developed-by: Felipe Ribeiro de Souza <felipers@usp.br>
Signed-off-by: Felipe Ribeiro de Souza <felipers@usp.br>
---
v3:
  - Restore scoped_guard() in ad7280_show_balance_timer() instead of
    guard() to avoid holding the mutex during post-processing, as
    suggested by Andy Shevchenko.

v2:
  - Replace scoped_guard with guard as suggested by Andy Shevchenko (Code Legibility).
  - Fix indentation issues.
---
 drivers/iio/adc/ad7280a.c | 57 +++++++++++++++++----------------------
 1 file changed, 24 insertions(+), 33 deletions(-)

diff --git a/drivers/iio/adc/ad7280a.c b/drivers/iio/adc/ad7280a.c
index ba12a3796e2b..228e06307aae 100644
--- a/drivers/iio/adc/ad7280a.c
+++ b/drivers/iio/adc/ad7280a.c
@@ -496,7 +496,8 @@ static ssize_t ad7280_store_balance_sw(struct iio_dev *indio_dev,
 	devaddr = chan->address >> 8;
 	ch = chan->address & 0xFF;
 
-	mutex_lock(&st->lock);
+	guard(mutex)(&st->lock);
+
 	if (readin)
 		st->cb_mask[devaddr] |= BIT(ch);
 	else
@@ -505,7 +506,6 @@ static ssize_t ad7280_store_balance_sw(struct iio_dev *indio_dev,
 	ret = ad7280_write(st, devaddr, AD7280A_CELL_BALANCE_REG, 0,
 			   FIELD_PREP(AD7280A_CELL_BALANCE_CHAN_BITMAP_MSK,
 				      st->cb_mask[devaddr]));
-	mutex_unlock(&st->lock);
 
 	return ret ? ret : len;
 }
@@ -519,10 +519,9 @@ static ssize_t ad7280_show_balance_timer(struct iio_dev *indio_dev,
 	unsigned int msecs;
 	int ret;
 
-	mutex_lock(&st->lock);
-	ret = ad7280_read_reg(st, chan->address >> 8,
-			      (chan->address & 0xFF) + AD7280A_CB1_TIMER_REG);
-	mutex_unlock(&st->lock);
+	scoped_guard(mutex, &st->lock)
+		ret = ad7280_read_reg(st, chan->address >> 8,
+					(chan->address & 0xFF) + AD7280A_CB1_TIMER_REG);
 
 	if (ret < 0)
 		return ret;
@@ -551,11 +550,11 @@ static ssize_t ad7280_store_balance_timer(struct iio_dev *indio_dev,
 	if (val > 31)
 		return -EINVAL;
 
-	mutex_lock(&st->lock);
+	guard(mutex)(&st->lock);
+
 	ret = ad7280_write(st, chan->address >> 8,
 			   (chan->address & 0xFF) + AD7280A_CB1_TIMER_REG, 0,
 			   FIELD_PREP(AD7280A_CB_TIMER_VAL_MSK, val));
-	mutex_unlock(&st->lock);
 
 	return ret ? ret : len;
 }
@@ -737,7 +736,8 @@ static int ad7280a_write_thresh(struct iio_dev *indio_dev,
 	if (val2 != 0)
 		return -EINVAL;
 
-	mutex_lock(&st->lock);
+	guard(mutex)(&st->lock);
+
 	switch (chan->type) {
 	case IIO_VOLTAGE:
 		value = ((val - 1000) * 100) / 1568; /* LSB 15.68mV */
@@ -748,22 +748,20 @@ static int ad7280a_write_thresh(struct iio_dev *indio_dev,
 			ret = ad7280_write(st, AD7280A_DEVADDR_MASTER, addr,
 					   1, value);
 			if (ret)
-				break;
+				return ret;
 			st->cell_threshhigh = value;
-			break;
+			return 0;
 		case IIO_EV_DIR_FALLING:
 			addr = AD7280A_CELL_UNDERVOLTAGE_REG;
 			ret = ad7280_write(st, AD7280A_DEVADDR_MASTER, addr,
 					   1, value);
 			if (ret)
-				break;
+				return ret;
 			st->cell_threshlow = value;
-			break;
+			return 0;
 		default:
-			ret = -EINVAL;
-			goto err_unlock;
+			return -EINVAL;
 		}
-		break;
 	case IIO_TEMP:
 		value = (val * 10) / 196; /* LSB 19.6mV */
 		value = clamp(value, 0L, 0xFFL);
@@ -773,31 +771,23 @@ static int ad7280a_write_thresh(struct iio_dev *indio_dev,
 			ret = ad7280_write(st, AD7280A_DEVADDR_MASTER, addr,
 					   1, value);
 			if (ret)
-				break;
+				return ret;
 			st->aux_threshhigh = value;
-			break;
+			return 0;
 		case IIO_EV_DIR_FALLING:
 			addr = AD7280A_AUX_ADC_UNDERVOLTAGE_REG;
 			ret = ad7280_write(st, AD7280A_DEVADDR_MASTER, addr,
 					   1, value);
 			if (ret)
-				break;
+				return ret;
 			st->aux_threshlow = value;
-			break;
+			return 0;
 		default:
-			ret = -EINVAL;
-			goto err_unlock;
+			return -EINVAL;
 		}
-		break;
 	default:
-		ret = -EINVAL;
-		goto err_unlock;
+		return -EINVAL;
 	}
-
-err_unlock:
-	mutex_unlock(&st->lock);
-
-	return ret;
 }
 
 static irqreturn_t ad7280_event_handler(int irq, void *private)
@@ -884,14 +874,14 @@ static int ad7280_read_raw(struct iio_dev *indio_dev,
 	int ret;
 
 	switch (m) {
-	case IIO_CHAN_INFO_RAW:
-		mutex_lock(&st->lock);
+	case IIO_CHAN_INFO_RAW: {
+		guard(mutex)(&st->lock);
+
 		if (chan->address == AD7280A_ALL_CELLS)
 			ret = ad7280_read_all_channels(st, st->scan_cnt, NULL);
 		else
 			ret = ad7280_read_channel(st, chan->address >> 8,
 						  chan->address & 0xFF);
-		mutex_unlock(&st->lock);
 
 		if (ret < 0)
 			return ret;
@@ -899,6 +889,7 @@ static int ad7280_read_raw(struct iio_dev *indio_dev,
 		*val = ret;
 
 		return IIO_VAL_INT;
+	}
 	case IIO_CHAN_INFO_SCALE:
 		if ((chan->address & 0xFF) <= AD7280A_CELL_VOLTAGE_6_REG)
 			*val = 4000;
-- 
2.47.3


^ permalink raw reply related

* [PATCH] iio: magnetometer: ak8975: remove unnecessary braces
From: Joshua Crofts @ 2026-04-17 13:02 UTC (permalink / raw)
  To: jic23; +Cc: dlechner, nuno.sa, andy, linux-iio, linux-kernel, Joshua Crofts

Remove unnecessary braces at single if statement block.

No functional change.

Signed-off-by: Joshua Crofts <joshua.crofts1@gmail.com>
---
 drivers/iio/magnetometer/ak8975.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/iio/magnetometer/ak8975.c b/drivers/iio/magnetometer/ak8975.c
index d30315ad85..443011748b 100644
--- a/drivers/iio/magnetometer/ak8975.c
+++ b/drivers/iio/magnetometer/ak8975.c
@@ -541,9 +541,9 @@ static int ak8975_set_mode(struct ak8975_data *data, enum ak_ctrl_mode mode)
 		 data->def->ctrl_modes[mode];
 	ret = i2c_smbus_write_byte_data(data->client,
 					data->def->ctrl_regs[CNTL], regval);
-	if (ret < 0) {
+	if (ret < 0)
 		return ret;
-	}
+
 	data->cntl_cache = regval;
 	/* After mode change wait atleast 100us */
 	usleep_range(100, 500);
-- 
2.47.3


^ permalink raw reply related

* Re: [PATCH v8 2/2] iio: dac: ad5706r: Add support for AD5706R DAC
From: Jonathan Cameron @ 2026-04-17 12:56 UTC (permalink / raw)
  To: Andy Shevchenko
  Cc: Alexis Czezar Torreno, Lars-Peter Clausen, Michael Hennerich,
	Jonathan Cameron, David Lechner, Nuno Sá, Andy Shevchenko,
	Rob Herring, Krzysztof Kozlowski, Conor Dooley, linux-iio,
	devicetree, linux-kernel
In-Reply-To: <aeHwwN2sFJBzQ21H@ashevche-desk.local>

On Fri, 17 Apr 2026 11:35:12 +0300
Andy Shevchenko <andriy.shevchenko@intel.com> wrote:

> On Fri, Apr 17, 2026 at 04:27:16PM +0800, Alexis Czezar Torreno wrote:
> > Add support for the Analog Devices AD5706R, a 4-channel 16-bit
> > current output digital-to-analog converter with SPI interface.
> > 
> > Features:
> >   - 4 independent DAC channels
> >   - Hardware and software LDAC trigger
> >   - Configurable output range
> >   - PWM-based LDAC control
> >   - Dither and toggle modes
> >   - Dynamically configurable SPI speed  
> 
> ...
> 
> > +#define AD5706R_DAC_RESOLUTION		16
> > +#define AD5706R_DAC_MAX_CODE		GENMASK(15, 0)  
> 
> I know Jonathan asked for this, hence it's comment for him.
> I think that BIT() notation in a form of (BIT(16) - 1) is
> also appropriate here as it gives the relationship to the
> resolution of the given register / bitfield in HW.
> 
> GENMASK() works for me, but it might require an additional
> operation to deduce the above.
> 
> (Note, there is no request to change or resend for you, Alexis. It's just
>  a remark to make Jonathan to think about which one suits better. He might
>  change that whilst applying.)
>
I'm not against that form.  It was more being against bare BIT(16) as that was
1 greater than the maximum value it can take.
However making the relationship explicit would be even better.

#define AD5705_DAC_MAX_CODE	(BIT(AD5706R_DAC_RESOLUTION) - 1)

I might tweak it when picking this up.

^ permalink raw reply

* Re: [PATCH v2] iio: buffer: fix warning in requesting threaded irq
From: Jonathan Cameron @ 2026-04-17 12:50 UTC (permalink / raw)
  To: Andy Shevchenko
  Cc: Junxiao Chang, jic23, dlechner, nuno.sa, andy, gye976, linux-iio,
	linux-kernel, lars
In-Reply-To: <aeIZw2gvbZGJEXy9@ashevche-desk.local>

On Fri, 17 Apr 2026 14:30:11 +0300
Andy Shevchenko <andriy.shevchenko@intel.com> wrote:

> On Sat, Apr 18, 2026 at 04:51:56PM +0800, Junxiao Chang wrote:
> > IRQF_ONESHOT is for threaded IRQ. If there is no threaded IRQ
> > handler, this flag should not be set.
> > 
> > This change fixes a warning during booting with kernel v7.0-rc3:
> > 
> > WARNING: kernel/irq/manage.c:1502 at __setup_irq+0x1639/0x2510, CPU#3: iio-sensor-prox/974  
Please provide details on which driver is in use to hit this corner case.

That may help people identify if the bug applies to what they are seeing
and also provide some background on how urgent this is to get upstream + backported.

Jonathan

> 
> > RIP: 0010:__setup_irq+0x1639/0x2510  
> 
> Unneeded line (it dups the previous one).
> 
> > Call Trace:
> > request_threaded_irq+0x2c7/0x490
> > iio_trigger_attach_poll_func+0x353/0x6b0
> > __iio_update_buffers+0x2420/0x2c70
> > enable_store+0x183/0x270
> > dev_attr_store+0x5e/0x90  
> 
> > sysfs_kf_write+0x1e8/0x290
> > kernfs_fop_write_iter+0x406/0x5f0
> > vfs_write+0x71c/0xea0  
> 
> These 3 lines are also redundant.
> 
> > v2: using ternary and drop temp variable  
> 
> Changelog should go...
> 
> > Fixes: 23f2d735a932 ("iio: Add helper function for initializing triggered buffers")
> > Signed-off-by: Junxiao Chang <junxiao.chang@intel.com>
> > ---  
> 
> ...here, when it doesn't go to the commit message. One may find this in the
> lore archive.
> 
> ...
> 
> Code wise now it looks good.
> 


^ permalink raw reply

* [PATCH v2 8/8] iio: accel: adxl372: Use dev_err_probe
From: Sanjay Chitroda @ 2026-04-17 12:49 UTC (permalink / raw)
  To: lucas.p.stankus, lars, Michael.Hennerich, jic23, puranjay,
	cosmin.tanislav, marcelo.schmitt, antoniu.miclaus,
	ramona.gradinariu
  Cc: dlechner, nuno.sa, andy, linux-iio, linux-kernel
In-Reply-To: <20260417124924.353189-1-sanjayembedded@gmail.com>

From: Sanjay Chitroda <sanjayembeddedse@gmail.com>

dev_err_probe() makes error code handling simpler and handles
deferred probe nicely (avoid spamming logs).

Signed-off-by: Sanjay Chitroda <sanjayembeddedse@gmail.com>
---
 drivers/iio/accel/adxl372.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/drivers/iio/accel/adxl372.c b/drivers/iio/accel/adxl372.c
index 1a6ba94f54f4..e375d068a3f5 100644
--- a/drivers/iio/accel/adxl372.c
+++ b/drivers/iio/accel/adxl372.c
@@ -1316,10 +1316,8 @@ int adxl372_probe(struct device *dev, struct regmap *regmap,
 	}
 
 	ret = adxl372_setup(st);
-	if (ret < 0) {
-		dev_err(dev, "ADXL372 setup failed\n");
-		return ret;
-	}
+	if (ret < 0)
+		return dev_err_probe(dev, ret, "ADXL372 setup failed\n");
 
 	if (chip_info->fifo_supported) {
 		ret = adxl372_buffer_setup(indio_dev);
-- 
2.34.1


^ permalink raw reply related

* [PATCH v2 7/8] iio: accel: adxl372: Use devm-managed mutex initialization
From: Sanjay Chitroda @ 2026-04-17 12:49 UTC (permalink / raw)
  To: lucas.p.stankus, lars, Michael.Hennerich, jic23, puranjay,
	cosmin.tanislav, marcelo.schmitt, antoniu.miclaus,
	ramona.gradinariu
  Cc: dlechner, nuno.sa, andy, linux-iio, linux-kernel
In-Reply-To: <20260417124924.353189-1-sanjayembedded@gmail.com>

From: Sanjay Chitroda <sanjayembeddedse@gmail.com>

Use devm_mutex_init() to tie the mutex lifetime to the device and
improve debugging when CONFIG_DEBUG_MUTEXES is enabled.

Signed-off-by: Sanjay Chitroda <sanjayembeddedse@gmail.com>
---
 drivers/iio/accel/adxl372.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/iio/accel/adxl372.c b/drivers/iio/accel/adxl372.c
index 545a21e5a308..1a6ba94f54f4 100644
--- a/drivers/iio/accel/adxl372.c
+++ b/drivers/iio/accel/adxl372.c
@@ -1299,7 +1299,9 @@ int adxl372_probe(struct device *dev, struct regmap *regmap,
 	st->irq = irq;
 	st->chip_info = chip_info;
 
-	mutex_init(&st->threshold_m);
+	ret = devm_mutex_init(dev, &st->threshold_m);
+	if (ret < 0)
+		return ret;
 
 	indio_dev->channels = adxl372_channels;
 	indio_dev->num_channels = ARRAY_SIZE(adxl372_channels);
-- 
2.34.1


^ permalink raw reply related

* [PATCH v2 6/8] iio: accel: adxl367: Use devm-managed mutex initialization
From: Sanjay Chitroda @ 2026-04-17 12:49 UTC (permalink / raw)
  To: lucas.p.stankus, lars, Michael.Hennerich, jic23, puranjay,
	cosmin.tanislav, marcelo.schmitt, antoniu.miclaus,
	ramona.gradinariu
  Cc: dlechner, nuno.sa, andy, linux-iio, linux-kernel
In-Reply-To: <20260417124924.353189-1-sanjayembedded@gmail.com>

From: Sanjay Chitroda <sanjayembeddedse@gmail.com>

Use devm_mutex_init() to tie the mutex lifetime to the device and
improve debugging when CONFIG_DEBUG_MUTEXES is enabled.

Signed-off-by: Sanjay Chitroda <sanjayembeddedse@gmail.com>
---
 drivers/iio/accel/adxl367.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/iio/accel/adxl367.c b/drivers/iio/accel/adxl367.c
index 0c04b2bb7efb..63a0b182824f 100644
--- a/drivers/iio/accel/adxl367.c
+++ b/drivers/iio/accel/adxl367.c
@@ -1445,7 +1445,9 @@ int adxl367_probe(struct device *dev, const struct adxl367_ops *ops,
 	st->context = context;
 	st->ops = ops;
 
-	mutex_init(&st->lock);
+	ret = devm_mutex_init(dev, &st->lock);
+	if (ret)
+		return ret;
 
 	indio_dev->channels = adxl367_channels;
 	indio_dev->num_channels = ARRAY_SIZE(adxl367_channels);
-- 
2.34.1


^ permalink raw reply related

* [PATCH v2 5/8] iio: accel: adxl355: Use dev_err_probe
From: Sanjay Chitroda @ 2026-04-17 12:49 UTC (permalink / raw)
  To: lucas.p.stankus, lars, Michael.Hennerich, jic23, puranjay,
	cosmin.tanislav, marcelo.schmitt, antoniu.miclaus,
	ramona.gradinariu
  Cc: dlechner, nuno.sa, andy, linux-iio, linux-kernel
In-Reply-To: <20260417124924.353189-1-sanjayembedded@gmail.com>

From: Sanjay Chitroda <sanjayembeddedse@gmail.com>

dev_err_probe() makes error code handling simpler and handles
deferred probe nicely (avoid spamming logs).

Signed-off-by: Sanjay Chitroda <sanjayembeddedse@gmail.com>
---
 drivers/iio/accel/adxl355_core.c | 24 ++++++++----------------
 drivers/iio/accel/adxl355_i2c.c  | 11 ++++-------
 drivers/iio/accel/adxl355_spi.c  | 11 ++++-------
 3 files changed, 16 insertions(+), 30 deletions(-)

diff --git a/drivers/iio/accel/adxl355_core.c b/drivers/iio/accel/adxl355_core.c
index a310f8e37e3d..03e5744d9667 100644
--- a/drivers/iio/accel/adxl355_core.c
+++ b/drivers/iio/accel/adxl355_core.c
@@ -336,10 +336,8 @@ static int adxl355_setup(struct adxl355_data *data)
 		return ret;
 
 	do {
-		if (--retries == 0) {
-			dev_err(data->dev, "Shadow registers mismatch\n");
-			return -EIO;
-		}
+		if (--retries == 0)
+			return dev_err_probe(data->dev, -EIO, "Shadow registers mismatch\n");
 
 		/*
 		 * Perform a software reset to make sure the device is in a consistent
@@ -775,10 +773,8 @@ static int adxl355_probe_trigger(struct iio_dev *indio_dev, int irq)
 				     irq);
 
 	ret = devm_iio_trigger_register(data->dev, data->dready_trig);
-	if (ret) {
-		dev_err(data->dev, "iio trigger register failed\n");
-		return ret;
-	}
+	if (ret)
+		return dev_err_probe(data->dev, ret, "iio trigger register failed\n");
 
 	indio_dev->trig = iio_trigger_get(data->dready_trig);
 
@@ -814,18 +810,14 @@ int adxl355_core_probe(struct device *dev, struct regmap *regmap,
 	indio_dev->available_scan_masks = adxl355_avail_scan_masks;
 
 	ret = adxl355_setup(data);
-	if (ret) {
-		dev_err(dev, "ADXL355 setup failed\n");
-		return ret;
-	}
+	if (ret)
+		return dev_err_probe(dev, ret, "ADXL355 setup failed\n");
 
 	ret = devm_iio_triggered_buffer_setup(dev, indio_dev,
 					      &iio_pollfunc_store_time,
 					      &adxl355_trigger_handler, NULL);
-	if (ret) {
-		dev_err(dev, "iio triggered buffer setup failed\n");
-		return ret;
-	}
+	if (ret)
+		return dev_err_probe(dev, ret, "iio triggered buffer setup failed\n");
 
 	irq = fwnode_irq_get_byname(dev_fwnode(dev), "DRDY");
 	if (irq > 0) {
diff --git a/drivers/iio/accel/adxl355_i2c.c b/drivers/iio/accel/adxl355_i2c.c
index 1a512c7b792b..19490a6e1f35 100644
--- a/drivers/iio/accel/adxl355_i2c.c
+++ b/drivers/iio/accel/adxl355_i2c.c
@@ -23,6 +23,7 @@ static const struct regmap_config adxl355_i2c_regmap_config = {
 static int adxl355_i2c_probe(struct i2c_client *client)
 {
 	struct regmap *regmap;
+	struct device *dev = &client->dev;
 	const struct adxl355_chip_info *chip_data;
 
 	chip_data = i2c_get_match_data(client);
@@ -30,14 +31,10 @@ static int adxl355_i2c_probe(struct i2c_client *client)
 		return -ENODEV;
 
 	regmap = devm_regmap_init_i2c(client, &adxl355_i2c_regmap_config);
-	if (IS_ERR(regmap)) {
-		dev_err(&client->dev, "Error initializing i2c regmap: %ld\n",
-			PTR_ERR(regmap));
+	if (IS_ERR(regmap))
+		return dev_err_probe(dev, PTR_ERR(regmap), "Error initializing i2c regmap\n");
 
-		return PTR_ERR(regmap);
-	}
-
-	return adxl355_core_probe(&client->dev, regmap, chip_data);
+	return adxl355_core_probe(dev, regmap, chip_data);
 }
 
 static const struct i2c_device_id adxl355_i2c_id[] = {
diff --git a/drivers/iio/accel/adxl355_spi.c b/drivers/iio/accel/adxl355_spi.c
index 869e3e57d6f7..347ed62b6582 100644
--- a/drivers/iio/accel/adxl355_spi.c
+++ b/drivers/iio/accel/adxl355_spi.c
@@ -26,6 +26,7 @@ static const struct regmap_config adxl355_spi_regmap_config = {
 static int adxl355_spi_probe(struct spi_device *spi)
 {
 	const struct adxl355_chip_info *chip_data;
+	struct device *dev = &spi->dev;
 	struct regmap *regmap;
 
 	chip_data = spi_get_device_match_data(spi);
@@ -33,14 +34,10 @@ static int adxl355_spi_probe(struct spi_device *spi)
 		return -EINVAL;
 
 	regmap = devm_regmap_init_spi(spi, &adxl355_spi_regmap_config);
-	if (IS_ERR(regmap)) {
-		dev_err(&spi->dev, "Error initializing spi regmap: %ld\n",
-			PTR_ERR(regmap));
+	if (IS_ERR(regmap))
+		return dev_err_probe(dev, PTR_ERR(regmap), "Error initializing spi regmap\n");
 
-		return PTR_ERR(regmap);
-	}
-
-	return adxl355_core_probe(&spi->dev, regmap, chip_data);
+	return adxl355_core_probe(dev, regmap, chip_data);
 }
 
 static const struct spi_device_id adxl355_spi_id[] = {
-- 
2.34.1


^ permalink raw reply related

* [PATCH v2 4/8] iio: accel: adxl355_core: Use devm-managed mutex initialization
From: Sanjay Chitroda @ 2026-04-17 12:49 UTC (permalink / raw)
  To: lucas.p.stankus, lars, Michael.Hennerich, jic23, puranjay,
	cosmin.tanislav, marcelo.schmitt, antoniu.miclaus,
	ramona.gradinariu
  Cc: dlechner, nuno.sa, andy, linux-iio, linux-kernel
In-Reply-To: <20260417124924.353189-1-sanjayembedded@gmail.com>

From: Sanjay Chitroda <sanjayembeddedse@gmail.com>

Use devm_mutex_init() to tie the mutex lifetime to the device and
improve debugging when CONFIG_DEBUG_MUTEXES is enabled.

Signed-off-by: Sanjay Chitroda <sanjayembeddedse@gmail.com>
---
 drivers/iio/accel/adxl355_core.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/iio/accel/adxl355_core.c b/drivers/iio/accel/adxl355_core.c
index 8f90c58f4100..a310f8e37e3d 100644
--- a/drivers/iio/accel/adxl355_core.c
+++ b/drivers/iio/accel/adxl355_core.c
@@ -802,7 +802,9 @@ int adxl355_core_probe(struct device *dev, struct regmap *regmap,
 	data->dev = dev;
 	data->op_mode = ADXL355_STANDBY;
 	data->chip_info = chip_info;
-	mutex_init(&data->lock);
+	ret = devm_mutex_init(dev, &data->lock);
+	if (ret)
+		return ret;
 
 	indio_dev->name = chip_info->name;
 	indio_dev->info = &adxl355_info;
-- 
2.34.1


^ permalink raw reply related

* [PATCH v2 3/8] iio: accel: adxl380: Use devm-managed mutex initialization
From: Sanjay Chitroda @ 2026-04-17 12:49 UTC (permalink / raw)
  To: lucas.p.stankus, lars, Michael.Hennerich, jic23, puranjay,
	cosmin.tanislav, marcelo.schmitt, antoniu.miclaus,
	ramona.gradinariu
  Cc: dlechner, nuno.sa, andy, linux-iio, linux-kernel
In-Reply-To: <20260417124924.353189-1-sanjayembedded@gmail.com>

From: Sanjay Chitroda <sanjayembeddedse@gmail.com>

Use devm_mutex_init() to tie the mutex lifetime to the device and
improve debugging when CONFIG_DEBUG_MUTEXES is enabled.

Signed-off-by: Sanjay Chitroda <sanjayembeddedse@gmail.com>
---
 drivers/iio/accel/adxl380.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/iio/accel/adxl380.c b/drivers/iio/accel/adxl380.c
index e7bb32fbc475..7dca5523091f 100644
--- a/drivers/iio/accel/adxl380.c
+++ b/drivers/iio/accel/adxl380.c
@@ -1967,7 +1967,9 @@ int adxl380_probe(struct device *dev, struct regmap *regmap,
 	st->chip_info = chip_info;
 	st->odr = ADXL380_ODR_DSM;
 
-	mutex_init(&st->lock);
+	ret = devm_mutex_init(dev, &st->lock);
+	if (ret)
+		return ret;
 
 	indio_dev->channels = adxl380_channels;
 	indio_dev->num_channels = ARRAY_SIZE(adxl380_channels);
-- 
2.34.1


^ permalink raw reply related

* [PATCH v2 2/8] iio: accel: adxl313: Use dev_err_probe
From: Sanjay Chitroda @ 2026-04-17 12:49 UTC (permalink / raw)
  To: lucas.p.stankus, lars, Michael.Hennerich, jic23, puranjay,
	cosmin.tanislav, marcelo.schmitt, antoniu.miclaus,
	ramona.gradinariu
  Cc: dlechner, nuno.sa, andy, linux-iio, linux-kernel
In-Reply-To: <20260417124924.353189-1-sanjayembedded@gmail.com>

From: Sanjay Chitroda <sanjayembeddedse@gmail.com>

dev_err_probe() makes error code handling simpler and handles
deferred probe nicely (avoid spamming logs).

Signed-off-by: Sanjay Chitroda <sanjayembeddedse@gmail.com>
---
 drivers/iio/accel/adxl313_core.c |  6 ++----
 drivers/iio/accel/adxl313_i2c.c  | 10 ++++------
 drivers/iio/accel/adxl313_spi.c  | 10 ++++------
 3 files changed, 10 insertions(+), 16 deletions(-)

diff --git a/drivers/iio/accel/adxl313_core.c b/drivers/iio/accel/adxl313_core.c
index 1fc96b7b0f1f..6dc918c4ae17 100644
--- a/drivers/iio/accel/adxl313_core.c
+++ b/drivers/iio/accel/adxl313_core.c
@@ -1252,10 +1252,8 @@ int adxl313_core_probe(struct device *dev,
 	indio_dev->available_scan_masks = adxl313_scan_masks;
 
 	ret = adxl313_setup(dev, data, setup);
-	if (ret) {
-		dev_err(dev, "ADXL313 setup failed\n");
-		return ret;
-	}
+	if (ret)
+		return dev_err_probe(dev, ret, "ADXL313 setup failed\n");
 
 	int_line = adxl313_get_int_type(dev, &irq);
 	if (int_line == ADXL313_INT_NONE) {
diff --git a/drivers/iio/accel/adxl313_i2c.c b/drivers/iio/accel/adxl313_i2c.c
index b67ff0b4dc54..6736b83f23bd 100644
--- a/drivers/iio/accel/adxl313_i2c.c
+++ b/drivers/iio/accel/adxl313_i2c.c
@@ -65,6 +65,7 @@ MODULE_DEVICE_TABLE(of, adxl313_of_match);
 static int adxl313_i2c_probe(struct i2c_client *client)
 {
 	const struct adxl313_chip_info *chip_data;
+	struct device *dev = &client->dev;
 	struct regmap *regmap;
 
 	/*
@@ -75,13 +76,10 @@ static int adxl313_i2c_probe(struct i2c_client *client)
 
 	regmap = devm_regmap_init_i2c(client,
 				      &adxl31x_i2c_regmap_config[chip_data->type]);
-	if (IS_ERR(regmap)) {
-		dev_err(&client->dev, "Error initializing i2c regmap: %ld\n",
-			PTR_ERR(regmap));
-		return PTR_ERR(regmap);
-	}
+	if (IS_ERR(regmap))
+		return dev_err_probe(dev, PTR_ERR(regmap), "Error initializing i2c regmap\n");
 
-	return adxl313_core_probe(&client->dev, regmap, chip_data, NULL);
+	return adxl313_core_probe(dev, regmap, chip_data, NULL);
 }
 
 static struct i2c_driver adxl313_i2c_driver = {
diff --git a/drivers/iio/accel/adxl313_spi.c b/drivers/iio/accel/adxl313_spi.c
index dedb0885c277..555c11b68421 100644
--- a/drivers/iio/accel/adxl313_spi.c
+++ b/drivers/iio/accel/adxl313_spi.c
@@ -70,6 +70,7 @@ static int adxl313_spi_setup(struct device *dev, struct regmap *regmap)
 static int adxl313_spi_probe(struct spi_device *spi)
 {
 	const struct adxl313_chip_info *chip_data;
+	struct device *dev = &spi->dev;
 	struct regmap *regmap;
 	int ret;
 
@@ -83,13 +84,10 @@ static int adxl313_spi_probe(struct spi_device *spi)
 	regmap = devm_regmap_init_spi(spi,
 				      &adxl31x_spi_regmap_config[chip_data->type]);
 
-	if (IS_ERR(regmap)) {
-		dev_err(&spi->dev, "Error initializing spi regmap: %ld\n",
-			PTR_ERR(regmap));
-		return PTR_ERR(regmap);
-	}
+	if (IS_ERR(regmap))
+		return dev_err_probe(dev, PTR_ERR(regmap), "Error initializing spi regmap\n");
 
-	return adxl313_core_probe(&spi->dev, regmap,
+	return adxl313_core_probe(dev, regmap,
 				  chip_data, &adxl313_spi_setup);
 }
 
-- 
2.34.1


^ permalink raw reply related

* [PATCH v2 1/8] iio: accel: adxl313_core: Use devm-managed mutex initialization
From: Sanjay Chitroda @ 2026-04-17 12:49 UTC (permalink / raw)
  To: lucas.p.stankus, lars, Michael.Hennerich, jic23, puranjay,
	cosmin.tanislav, marcelo.schmitt, antoniu.miclaus,
	ramona.gradinariu
  Cc: dlechner, nuno.sa, andy, linux-iio, linux-kernel
In-Reply-To: <20260417124924.353189-1-sanjayembedded@gmail.com>

From: Sanjay Chitroda <sanjayembeddedse@gmail.com>

Use devm_mutex_init() to tie the mutex lifetime to the device and
improve debugging when CONFIG_DEBUG_MUTEXES is enabled.

Signed-off-by: Sanjay Chitroda <sanjayembeddedse@gmail.com>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@intel.com>
---
 drivers/iio/accel/adxl313_core.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/iio/accel/adxl313_core.c b/drivers/iio/accel/adxl313_core.c
index bcc11dabdf22..1fc96b7b0f1f 100644
--- a/drivers/iio/accel/adxl313_core.c
+++ b/drivers/iio/accel/adxl313_core.c
@@ -1240,7 +1240,9 @@ int adxl313_core_probe(struct device *dev,
 	data->regmap = regmap;
 	data->chip_info = chip_info;
 
-	mutex_init(&data->lock);
+	ret = devm_mutex_init(dev, &data->lock);
+	if (ret)
+		return ret;
 
 	indio_dev->name = chip_info->name;
 	indio_dev->info = &adxl313_info;
-- 
2.34.1


^ permalink raw reply related

* [PATCH 0/2] iio: accel: small cleanups and error-handling improvements
From: Sanjay Chitroda @ 2026-04-17 12:49 UTC (permalink / raw)
  To: lucas.p.stankus, lars, Michael.Hennerich, jic23, puranjay,
	cosmin.tanislav, marcelo.schmitt, antoniu.miclaus,
	ramona.gradinariu
  Cc: dlechner, nuno.sa, andy, linux-iio, linux-kernel

From: Sanjay Chitroda <sanjayembeddedse@gmail.com>

Hi all,

This series contains a few small cleanups and robustness improvements to
adxl313, adxl380, adxl355, adxl367 and adxl372 IIO accelerometer drivers.

The changes modernize mutex handling using devm-managed helpers.
In addition, error handling during probe is cleaned up by switching to
dev_err_probe() to better handle deferred probing.

Changes in v2:
- Drop guard() changes as it's already available in iio/testing.
- Rebase changes on top of iio/testing with guidance from Andy.
- Added new change for additional iio accel drivers.

No functional changes are intended.

Testing:
  - Compiled with W=1
  - Build-tested on QEMU x86_64

Thanks,
Sanjay Chitroda

Sanjay Chitroda (8):
  iio: accel: adxl313_core: Use devm-managed mutex initialization
  iio: accel: adxl313: Use dev_err_probe
  iio: accel: adxl380: Use devm-managed mutex initialization
  iio: accel: adxl355_core: Use devm-managed mutex initialization
  iio: accel: adxl355: Use dev_err_probe
  iio: accel: adxl367: Use devm-managed mutex initialization
  iio: accel: adxl372: Use devm-managed mutex initialization
  iio: accel: adxl372: Use dev_err_probe

 drivers/iio/accel/adxl313_core.c | 10 +++++-----
 drivers/iio/accel/adxl313_i2c.c  | 10 ++++------
 drivers/iio/accel/adxl313_spi.c  | 10 ++++------
 drivers/iio/accel/adxl355_core.c | 28 +++++++++++-----------------
 drivers/iio/accel/adxl355_i2c.c  | 11 ++++-------
 drivers/iio/accel/adxl355_spi.c  | 11 ++++-------
 drivers/iio/accel/adxl367.c      |  4 +++-
 drivers/iio/accel/adxl372.c      | 10 +++++-----
 drivers/iio/accel/adxl380.c      |  4 +++-
 9 files changed, 43 insertions(+), 55 deletions(-)


base-commit: 0ccdcdc698b7ba52f2c9bc09bfdf9f020ca0e6e6
-- 
2.34.1


^ permalink raw reply

* Re: [PATCH] iio: magnetometer: hid-sensor-magn-3d: prefer 'unsigned int'
From: Joshua Crofts @ 2026-04-17 11:40 UTC (permalink / raw)
  To: Andy Shevchenko
  Cc: jikos, jic23, srinivas.pandruvada, dlechner, nuno.sa, andy,
	linux-input, linux-iio, linux-kernel
In-Reply-To: <aeIajr-NaBGdhvK9@ashevche-desk.local>

On Fri, 17 Apr 2026 at 13:33, Andy Shevchenko
<andriy.shevchenko@intel.com> wrote:
> Please, use the same types as defined in the respective data structure.
> https://elixir.bootlin.com/linux/v7.0/source/include/linux/hid-sensor-hub.h#L87

Fair enough, I'll send a version using u32 tomorrow.

-- 
Kind regards

CJD

^ permalink raw reply

* Re: [PATCH] iio: magnetometer: hid-sensor-magn-3d: prefer 'unsigned int'
From: Andy Shevchenko @ 2026-04-17 11:33 UTC (permalink / raw)
  To: Joshua Crofts
  Cc: jikos, jic23, srinivas.pandruvada, dlechner, nuno.sa, andy,
	linux-input, linux-iio, linux-kernel
In-Reply-To: <20260417112808.1280-1-joshua.crofts1@gmail.com>

On Fri, Apr 17, 2026 at 11:28:08AM +0000, Joshua Crofts wrote:
> Use 'unsigned int' instead of bare 'unsigned' to resolve checkpatch.pl
> warnings and adhere to kernel coding style.
> 
> No functional change.

Please, use the same types as defined in the respective data structure.
https://elixir.bootlin.com/linux/v7.0/source/include/linux/hid-sensor-hub.h#L87

-- 
With Best Regards,
Andy Shevchenko



^ permalink raw reply

* Re: [PATCH v2] iio: buffer: fix warning in requesting threaded irq
From: Andy Shevchenko @ 2026-04-17 11:30 UTC (permalink / raw)
  To: Junxiao Chang
  Cc: jic23, dlechner, nuno.sa, andy, gye976, linux-iio, linux-kernel,
	lars
In-Reply-To: <20260418085156.121947-1-junxiao.chang@intel.com>

On Sat, Apr 18, 2026 at 04:51:56PM +0800, Junxiao Chang wrote:
> IRQF_ONESHOT is for threaded IRQ. If there is no threaded IRQ
> handler, this flag should not be set.
> 
> This change fixes a warning during booting with kernel v7.0-rc3:
> 
> WARNING: kernel/irq/manage.c:1502 at __setup_irq+0x1639/0x2510, CPU#3: iio-sensor-prox/974

> RIP: 0010:__setup_irq+0x1639/0x2510

Unneeded line (it dups the previous one).

> Call Trace:
> request_threaded_irq+0x2c7/0x490
> iio_trigger_attach_poll_func+0x353/0x6b0
> __iio_update_buffers+0x2420/0x2c70
> enable_store+0x183/0x270
> dev_attr_store+0x5e/0x90

> sysfs_kf_write+0x1e8/0x290
> kernfs_fop_write_iter+0x406/0x5f0
> vfs_write+0x71c/0xea0

These 3 lines are also redundant.

> v2: using ternary and drop temp variable

Changelog should go...

> Fixes: 23f2d735a932 ("iio: Add helper function for initializing triggered buffers")
> Signed-off-by: Junxiao Chang <junxiao.chang@intel.com>
> ---

...here, when it doesn't go to the commit message. One may find this in the
lore archive.

...

Code wise now it looks good.

-- 
With Best Regards,
Andy Shevchenko



^ permalink raw reply

* [PATCH] iio: magnetometer: hid-sensor-magn-3d: prefer 'unsigned int'
From: Joshua Crofts @ 2026-04-17 11:28 UTC (permalink / raw)
  To: jikos, jic23, srinivas.pandruvada
  Cc: dlechner, nuno.sa, andy, linux-input, linux-iio, linux-kernel,
	Joshua Crofts

Use 'unsigned int' instead of bare 'unsigned' to resolve checkpatch.pl
warnings and adhere to kernel coding style.

No functional change.

Signed-off-by: Joshua Crofts <joshua.crofts1@gmail.com>
---
 drivers/iio/magnetometer/hid-sensor-magn-3d.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/iio/magnetometer/hid-sensor-magn-3d.c b/drivers/iio/magnetometer/hid-sensor-magn-3d.c
index c673f9323e..67550f16a9 100644
--- a/drivers/iio/magnetometer/hid-sensor-magn-3d.c
+++ b/drivers/iio/magnetometer/hid-sensor-magn-3d.c
@@ -280,7 +280,7 @@ static const struct iio_info magn_3d_info = {
 
 /* Callback handler to send event after all samples are received and captured */
 static int magn_3d_proc_event(struct hid_sensor_hub_device *hsdev,
-				unsigned usage_id,
+				unsigned int usage_id,
 				void *priv)
 {
 	struct iio_dev *indio_dev = platform_get_drvdata(priv);
@@ -302,7 +302,7 @@ static int magn_3d_proc_event(struct hid_sensor_hub_device *hsdev,
 
 /* Capture samples in local storage */
 static int magn_3d_capture_sample(struct hid_sensor_hub_device *hsdev,
-				unsigned usage_id,
+				unsigned int usage_id,
 				size_t raw_len, char *raw_data,
 				void *priv)
 {
@@ -350,7 +350,7 @@ static int magn_3d_parse_report(struct platform_device *pdev,
 				struct hid_sensor_hub_device *hsdev,
 				struct iio_chan_spec **channels,
 				int *chan_count,
-				unsigned usage_id,
+				unsigned int usage_id,
 				struct magn_3d_state *st)
 {
 	int i;
-- 
2.47.3


^ permalink raw reply related

* [PATCH v6 2/2] iio: frequency: ad9832: simplify bitwise math
From: Joshua Crofts @ 2026-04-17 10:16 UTC (permalink / raw)
  To: lars, Michael.Hennerich, jic23, gregkh
  Cc: dlechner, nuno.sa, andy, linux-iio, linux-staging, linux-kernel,
	Joshua Crofts, Andy Shevchenko
In-Reply-To: <20260417101623.1281-1-joshua.crofts1@gmail.com>

Refactor the ad9832_calc_freqreg by adding a BIT_ULL() macro instead of
manual bit shifting for better readability.

Signed-off-by: Joshua Crofts <joshua.crofts1@gmail.com>
Reviewed-by: Nuno Sá <nuno.sa@analog.com>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@intel.com>
---
 drivers/staging/iio/frequency/ad9832.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/staging/iio/frequency/ad9832.c b/drivers/staging/iio/frequency/ad9832.c
index c0b7852f1c..6ce9651542 100644
--- a/drivers/staging/iio/frequency/ad9832.c
+++ b/drivers/staging/iio/frequency/ad9832.c
@@ -117,8 +117,8 @@ struct ad9832_state {
 
 static unsigned long ad9832_calc_freqreg(unsigned long mclk, unsigned long fout)
 {
-	unsigned long long freqreg = (u64)fout *
-				     (u64)((u64)1L << AD9832_FREQ_BITS);
+	u64 freqreg = (u64)fout * BIT_ULL(AD9832_FREQ_BITS);
+
 	do_div(freqreg, mclk);
 	return freqreg;
 }
-- 
2.47.3


^ permalink raw reply related

* [PATCH v6 1/2] iio: frequency: ad9832: remove kernel.h proxy header
From: Joshua Crofts @ 2026-04-17 10:16 UTC (permalink / raw)
  To: lars, Michael.Hennerich, jic23, gregkh
  Cc: dlechner, nuno.sa, andy, linux-iio, linux-staging, linux-kernel,
	Joshua Crofts, Andy Shevchenko
In-Reply-To: <20260417101623.1281-1-joshua.crofts1@gmail.com>

Remove kernel.h proxy header and add replacement headers (array_size,
dev_printk.h, kstrtox, mod_devicetable, mutex, types, asm/byteorder) to
maintain atomicity. Moved asm/div64.h header below generic <linux/*>
headers. Additionally, add bitops.h for BIT_ULL() macro.

Audited using the include-what-you-use tool.

Signed-off-by: Joshua Crofts <joshua.crofts1@gmail.com>
Reviewed-by: Nuno Sá <nuno.sa@analog.com>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@intel.com>
---
 drivers/staging/iio/frequency/ad9832.c | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)

diff --git a/drivers/staging/iio/frequency/ad9832.c b/drivers/staging/iio/frequency/ad9832.c
index b87ea1781b..c0b7852f1c 100644
--- a/drivers/staging/iio/frequency/ad9832.c
+++ b/drivers/staging/iio/frequency/ad9832.c
@@ -5,21 +5,25 @@
  * Copyright 2011 Analog Devices Inc.
  */
 
-#include <asm/div64.h>
-
+#include <linux/array_size.h>
 #include <linux/bitfield.h>
-#include <linux/bits.h>
+#include <linux/bitops.h>
 #include <linux/clk.h>
-#include <linux/device.h>
+#include <linux/dev_printk.h>
 #include <linux/err.h>
-#include <linux/kernel.h>
+#include <linux/kstrtox.h>
+#include <linux/mod_devicetable.h>
 #include <linux/module.h>
+#include <linux/mutex.h>
 #include <linux/regulator/consumer.h>
-#include <linux/slab.h>
 #include <linux/spi/spi.h>
 #include <linux/sysfs.h>
+#include <linux/types.h>
 #include <linux/unaligned.h>
 
+#include <asm/byteorder.h>
+#include <asm/div64.h>
+
 #include <linux/iio/iio.h>
 #include <linux/iio/sysfs.h>
 
-- 
2.47.3


^ permalink raw reply related

* [PATCH v6 0/2] iio: frequency: ad9832: cleanups
From: Joshua Crofts @ 2026-04-17 10:16 UTC (permalink / raw)
  To: lars, Michael.Hennerich, jic23, gregkh
  Cc: dlechner, nuno.sa, andy, linux-iio, linux-staging, linux-kernel,
	Joshua Crofts

This series cleans up issues in the AD9832 driver, including proxy
header removal and bit math simplification.

v2:
 - PATCH 1: removed redundant bits.h include as it is implied in
   bitops.h
 - PATCH 2: changed ull to u64 type
v3:
 - PATCH 2: remove rogue vim typo
v4:
 - PATCH 1: removed slab.h based on IWYU recommendation, header
   reordering
v5:
 - PATCH 1: commit message stylistic changes
v6:
 - PATCH 1: add additional headers per kernel.h removal, commit message
   edit
 - PATCH 2: commit message edit

Joshua Crofts (2):
  iio: frequency: ad9832: remove kernel.h proxy header
  iio: frequency: ad9832: simplify bitwise math

 drivers/staging/iio/frequency/ad9832.c | 20 ++++++++++++--------
 1 file changed, 12 insertions(+), 8 deletions(-)

-- 
2.47.3


^ permalink raw reply


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