public inbox for linux-iio@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] iio: dac: ad5360: convert to guard(mutex)
@ 2026-01-28 11:37 Menderes Sabaz
  2026-01-28 14:54 ` David Lechner
  2026-01-28 15:32 ` [PATCH v2] " Menderes Sabaz
  0 siblings, 2 replies; 11+ messages in thread
From: Menderes Sabaz @ 2026-01-28 11:37 UTC (permalink / raw)
  To: lars, Michael.Hennerich, jic23
  Cc: dlechner, nuno.sa, andy, linux-iio, Menderes Sabaz

Converting mutex_lock and mutex_unlock to guard(mutex)
Simplify the locking logic by using guard(mutex).
This removes the need for explicit unlock calls in error paths and
simplifies the code by removing goto labels.

Signed-off-by: Menderes Sabaz <sabazmenderes@gmail.com>
---
 drivers/iio/dac/ad5360.c | 12 +++---------
 1 file changed, 3 insertions(+), 9 deletions(-)

diff --git a/drivers/iio/dac/ad5360.c b/drivers/iio/dac/ad5360.c
index 8271849b1..a22bafa45 100644
--- a/drivers/iio/dac/ad5360.c
+++ b/drivers/iio/dac/ad5360.c
@@ -209,10 +209,8 @@ static int ad5360_write(struct iio_dev *indio_dev, unsigned int cmd,
 	int ret;
 	struct ad5360_state *st = iio_priv(indio_dev);
 
-	mutex_lock(&st->lock);
+	guard(mutex)(&st->lock);
 	ret = ad5360_write_unlocked(indio_dev, cmd, addr, val, shift);
-	mutex_unlock(&st->lock);
-
 	return ret;
 }
 
@@ -232,7 +230,7 @@ static int ad5360_read(struct iio_dev *indio_dev, unsigned int type,
 		},
 	};
 
-	mutex_lock(&st->lock);
+	guard(mutex)(&st->lock);
 
 	st->data[0].d32 = cpu_to_be32(AD5360_CMD(AD5360_CMD_SPECIAL_FUNCTION) |
 		AD5360_ADDR(AD5360_REG_SF_READBACK) |
@@ -243,8 +241,6 @@ static int ad5360_read(struct iio_dev *indio_dev, unsigned int type,
 	if (ret >= 0)
 		ret = be32_to_cpu(st->data[1].d32) & 0xffff;
 
-	mutex_unlock(&st->lock);
-
 	return ret;
 }
 
@@ -264,7 +260,7 @@ static int ad5360_update_ctrl(struct iio_dev *indio_dev, unsigned int set,
 	struct ad5360_state *st = iio_priv(indio_dev);
 	int ret;
 
-	mutex_lock(&st->lock);
+	guard(mutex)(&st->lock);
 
 	st->ctrl |= set;
 	st->ctrl &= ~clr;
@@ -272,8 +268,6 @@ static int ad5360_update_ctrl(struct iio_dev *indio_dev, unsigned int set,
 	ret = ad5360_write_unlocked(indio_dev, AD5360_CMD_SPECIAL_FUNCTION,
 			AD5360_REG_SF_CTRL, st->ctrl, 0);
 
-	mutex_unlock(&st->lock);
-
 	return ret;
 }
 
-- 
2.52.0


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

* Re: [PATCH] iio: dac: ad5360: convert to guard(mutex)
  2026-01-28 11:37 [PATCH] iio: dac: ad5360: convert to guard(mutex) Menderes Sabaz
@ 2026-01-28 14:54 ` David Lechner
  2026-01-28 15:32 ` [PATCH v2] " Menderes Sabaz
  1 sibling, 0 replies; 11+ messages in thread
From: David Lechner @ 2026-01-28 14:54 UTC (permalink / raw)
  To: Menderes Sabaz, lars, Michael.Hennerich, jic23; +Cc: nuno.sa, andy, linux-iio

On 1/28/26 5:37 AM, Menderes Sabaz wrote:
> Converting mutex_lock and mutex_unlock to guard(mutex)
> Simplify the locking logic by using guard(mutex).
> This removes the need for explicit unlock calls in error paths and
> simplifies the code by removing goto labels.
> 
> Signed-off-by: Menderes Sabaz <sabazmenderes@gmail.com>
> ---
>  drivers/iio/dac/ad5360.c | 12 +++---------
>  1 file changed, 3 insertions(+), 9 deletions(-)
> 
> diff --git a/drivers/iio/dac/ad5360.c b/drivers/iio/dac/ad5360.c
> index 8271849b1..a22bafa45 100644
> --- a/drivers/iio/dac/ad5360.c
> +++ b/drivers/iio/dac/ad5360.c
> @@ -209,10 +209,8 @@ static int ad5360_write(struct iio_dev *indio_dev, unsigned int cmd,
>  	int ret;
>  	struct ad5360_state *st = iio_priv(indio_dev);
>  
> -	mutex_lock(&st->lock);
> +	guard(mutex)(&st->lock);
>  	ret = ad5360_write_unlocked(indio_dev, cmd, addr, val, shift);
> -	mutex_unlock(&st->lock);
> -
>  	return ret;
>  }
>  

All of the `return ret` can be removed now and function calls can return
directly. Otherwise, this isn't really an improvement. Same applies below.

> @@ -232,7 +230,7 @@ static int ad5360_read(struct iio_dev *indio_dev, unsigned int type,
>  		},
>  	};
>  
> -	mutex_lock(&st->lock);
> +	guard(mutex)(&st->lock);
>  
>  	st->data[0].d32 = cpu_to_be32(AD5360_CMD(AD5360_CMD_SPECIAL_FUNCTION) |
>  		AD5360_ADDR(AD5360_REG_SF_READBACK) |
> @@ -243,8 +241,6 @@ static int ad5360_read(struct iio_dev *indio_dev, unsigned int type,
>  	if (ret >= 0)
>  		ret = be32_to_cpu(st->data[1].d32) & 0xffff;
>  
> -	mutex_unlock(&st->lock);
> -
>  	return ret;
>  }
>  
> @@ -264,7 +260,7 @@ static int ad5360_update_ctrl(struct iio_dev *indio_dev, unsigned int set,
>  	struct ad5360_state *st = iio_priv(indio_dev);
>  	int ret;
>  
> -	mutex_lock(&st->lock);
> +	guard(mutex)(&st->lock);
>  
>  	st->ctrl |= set;
>  	st->ctrl &= ~clr;
> @@ -272,8 +268,6 @@ static int ad5360_update_ctrl(struct iio_dev *indio_dev, unsigned int set,
>  	ret = ad5360_write_unlocked(indio_dev, AD5360_CMD_SPECIAL_FUNCTION,
>  			AD5360_REG_SF_CTRL, st->ctrl, 0);
>  
> -	mutex_unlock(&st->lock);
> -
>  	return ret;
>  }
>  


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

* [PATCH v2] iio: dac: ad5360: convert to guard(mutex)
  2026-01-28 11:37 [PATCH] iio: dac: ad5360: convert to guard(mutex) Menderes Sabaz
  2026-01-28 14:54 ` David Lechner
@ 2026-01-28 15:32 ` Menderes Sabaz
  2026-01-28 22:32   ` Andy Shevchenko
                     ` (3 more replies)
  1 sibling, 4 replies; 11+ messages in thread
From: Menderes Sabaz @ 2026-01-28 15:32 UTC (permalink / raw)
  To: sabazmenderes
  Cc: Michael.Hennerich, andy, dlechner, jic23, lars, linux-iio,
	nuno.sa

Converting mutex_lock and mutex_unlock to guard(mutex)
Simplify the locking logic by using guard(mutex).
This removes the need for explicit unlock calls in error paths and
simplifies the code by removing goto labels.

Signed-off-by: Menderes Sabaz <sabazmenderes@gmail.com>
---
Changes in v2:
- Removed unnecessary local variables
 drivers/iio/dac/ad5360.c | 27 ++++++++-------------------
 1 file changed, 8 insertions(+), 19 deletions(-)

diff --git a/drivers/iio/dac/ad5360.c b/drivers/iio/dac/ad5360.c
index 8271849b1..15df5dd2a 100644
--- a/drivers/iio/dac/ad5360.c
+++ b/drivers/iio/dac/ad5360.c
@@ -206,14 +206,10 @@ static int ad5360_write_unlocked(struct iio_dev *indio_dev,
 static int ad5360_write(struct iio_dev *indio_dev, unsigned int cmd,
 	unsigned int addr, unsigned int val, unsigned int shift)
 {
-	int ret;
 	struct ad5360_state *st = iio_priv(indio_dev);
 
-	mutex_lock(&st->lock);
-	ret = ad5360_write_unlocked(indio_dev, cmd, addr, val, shift);
-	mutex_unlock(&st->lock);
-
-	return ret;
+	guard(mutex)(&st->lock);
+	return ad5360_write_unlocked(indio_dev, cmd, addr, val, shift);
 }
 
 static int ad5360_read(struct iio_dev *indio_dev, unsigned int type,
@@ -232,7 +228,7 @@ static int ad5360_read(struct iio_dev *indio_dev, unsigned int type,
 		},
 	};
 
-	mutex_lock(&st->lock);
+	guard(mutex)(&st->lock);
 
 	st->data[0].d32 = cpu_to_be32(AD5360_CMD(AD5360_CMD_SPECIAL_FUNCTION) |
 		AD5360_ADDR(AD5360_REG_SF_READBACK) |
@@ -240,12 +236,10 @@ static int ad5360_read(struct iio_dev *indio_dev, unsigned int type,
 		AD5360_READBACK_ADDR(addr));
 
 	ret = spi_sync_transfer(st->spi, t, ARRAY_SIZE(t));
-	if (ret >= 0)
-		ret = be32_to_cpu(st->data[1].d32) & 0xffff;
-
-	mutex_unlock(&st->lock);
+	if (ret < 0)
+		return ret;
 
-	return ret;
+	return be32_to_cpu(st->data[1].d32) & 0xffff;
 }
 
 static ssize_t ad5360_read_dac_powerdown(struct device *dev,
@@ -262,19 +256,14 @@ static int ad5360_update_ctrl(struct iio_dev *indio_dev, unsigned int set,
 	unsigned int clr)
 {
 	struct ad5360_state *st = iio_priv(indio_dev);
-	int ret;
 
-	mutex_lock(&st->lock);
+	guard(mutex)(&st->lock);
 
 	st->ctrl |= set;
 	st->ctrl &= ~clr;
 
-	ret = ad5360_write_unlocked(indio_dev, AD5360_CMD_SPECIAL_FUNCTION,
+	return ad5360_write_unlocked(indio_dev, AD5360_CMD_SPECIAL_FUNCTION,
 			AD5360_REG_SF_CTRL, st->ctrl, 0);
-
-	mutex_unlock(&st->lock);
-
-	return ret;
 }
 
 static ssize_t ad5360_write_dac_powerdown(struct device *dev,
-- 
2.52.0


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

* Re: [PATCH v2] iio: dac: ad5360: convert to guard(mutex)
  2026-01-28 15:32 ` [PATCH v2] " Menderes Sabaz
@ 2026-01-28 22:32   ` Andy Shevchenko
  2026-01-28 22:47   ` David Lechner
                     ` (2 subsequent siblings)
  3 siblings, 0 replies; 11+ messages in thread
From: Andy Shevchenko @ 2026-01-28 22:32 UTC (permalink / raw)
  To: Menderes Sabaz
  Cc: Michael.Hennerich, andy, dlechner, jic23, lars, linux-iio,
	nuno.sa

On Wed, Jan 28, 2026 at 06:32:21PM +0300, Menderes Sabaz wrote:
> Converting mutex_lock and mutex_unlock to guard(mutex)
> Simplify the locking logic by using guard(mutex).
> This removes the need for explicit unlock calls in error paths and
> simplifies the code by removing goto labels.

...

> Changes in v2:
> - Removed unnecessary local variables

Avoid sending v<N+1> in the v<N> email threads.

...

> -	ret = ad5360_write_unlocked(indio_dev, AD5360_CMD_SPECIAL_FUNCTION,
> +	return ad5360_write_unlocked(indio_dev, AD5360_CMD_SPECIAL_FUNCTION,
>  			AD5360_REG_SF_CTRL, st->ctrl, 0);

The second line is wrongly indented.


-- 
With Best Regards,
Andy Shevchenko



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

* Re: [PATCH v2] iio: dac: ad5360: convert to guard(mutex)
  2026-01-28 15:32 ` [PATCH v2] " Menderes Sabaz
  2026-01-28 22:32   ` Andy Shevchenko
@ 2026-01-28 22:47   ` David Lechner
  2026-01-28 23:14   ` [PATCH] iio: dac: ad5360: converting " Menderes Sabaz
  2026-01-29 16:16   ` [PATCH v2] iio: dac: ad5360: convert " Jonathan Cameron
  3 siblings, 0 replies; 11+ messages in thread
From: David Lechner @ 2026-01-28 22:47 UTC (permalink / raw)
  To: Menderes Sabaz; +Cc: Michael.Hennerich, andy, jic23, lars, linux-iio, nuno.sa

On 1/28/26 9:32 AM, Menderes Sabaz wrote:
> Converting mutex_lock and mutex_unlock to guard(mutex)

Usually we phrase this as "Covert" instead of "Converting".
And should have period at end of sentence.

> Simplify the locking logic by using guard(mutex).

This sentence is a bit redundant.

> This removes the need for explicit unlock calls in error paths and
> simplifies the code by removing goto labels.

Can leave out this sentence since it doesn't apply to this patch
(e.g. no gotos were removed).

> 
> Signed-off-by: Menderes Sabaz <sabazmenderes@gmail.com>
> ---
> Changes in v2:
> - Removed unnecessary local variables
>  drivers/iio/dac/ad5360.c | 27 ++++++++-------------------
>  1 file changed, 8 insertions(+), 19 deletions(-)
> 
> diff --git a/drivers/iio/dac/ad5360.c b/drivers/iio/dac/ad5360.c
> index 8271849b1..15df5dd2a 100644
> --- a/drivers/iio/dac/ad5360.c
> +++ b/drivers/iio/dac/ad5360.c
> @@ -206,14 +206,10 @@ static int ad5360_write_unlocked(struct iio_dev *indio_dev,
>  static int ad5360_write(struct iio_dev *indio_dev, unsigned int cmd,
>  	unsigned int addr, unsigned int val, unsigned int shift)
>  {
> -	int ret;
>  	struct ad5360_state *st = iio_priv(indio_dev);
>  
> -	mutex_lock(&st->lock);
> -	ret = ad5360_write_unlocked(indio_dev, cmd, addr, val, shift);
> -	mutex_unlock(&st->lock);
> -
> -	return ret;
> +	guard(mutex)(&st->lock);
> +	return ad5360_write_unlocked(indio_dev, cmd, addr, val, shift);
>  }
>  
>  static int ad5360_read(struct iio_dev *indio_dev, unsigned int type,
> @@ -232,7 +228,7 @@ static int ad5360_read(struct iio_dev *indio_dev, unsigned int type,
>  		},
>  	};
>  
> -	mutex_lock(&st->lock);
> +	guard(mutex)(&st->lock);
>  
>  	st->data[0].d32 = cpu_to_be32(AD5360_CMD(AD5360_CMD_SPECIAL_FUNCTION) |
>  		AD5360_ADDR(AD5360_REG_SF_READBACK) |
> @@ -240,12 +236,10 @@ static int ad5360_read(struct iio_dev *indio_dev, unsigned int type,
>  		AD5360_READBACK_ADDR(addr));
>  
>  	ret = spi_sync_transfer(st->spi, t, ARRAY_SIZE(t));
> -	if (ret >= 0)
> -		ret = be32_to_cpu(st->data[1].d32) & 0xffff;
> -
> -	mutex_unlock(&st->lock);
> +	if (ret < 0)
> +		return ret;
>  
> -	return ret;
> +	return be32_to_cpu(st->data[1].d32) & 0xffff;
>  }
>  
>  static ssize_t ad5360_read_dac_powerdown(struct device *dev,
> @@ -262,19 +256,14 @@ static int ad5360_update_ctrl(struct iio_dev *indio_dev, unsigned int set,
>  	unsigned int clr)
>  {
>  	struct ad5360_state *st = iio_priv(indio_dev);
> -	int ret;
>  
> -	mutex_lock(&st->lock);
> +	guard(mutex)(&st->lock);
>  
>  	st->ctrl |= set;
>  	st->ctrl &= ~clr;
>  
> -	ret = ad5360_write_unlocked(indio_dev, AD5360_CMD_SPECIAL_FUNCTION,
> +	return ad5360_write_unlocked(indio_dev, AD5360_CMD_SPECIAL_FUNCTION,
>  			AD5360_REG_SF_CTRL, st->ctrl, 0);
> -
> -	mutex_unlock(&st->lock);
> -
> -	return ret;
>  }
>  
>  static ssize_t ad5360_write_dac_powerdown(struct device *dev,

Patch looks better now.

With a bit more tidying (commit message and alignment that Andy
pointed out):

Reviewed-by: David Lechner <dlechner@baylibre.com>



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

* [PATCH] iio: dac: ad5360: converting to guard(mutex)
  2026-01-28 15:32 ` [PATCH v2] " Menderes Sabaz
  2026-01-28 22:32   ` Andy Shevchenko
  2026-01-28 22:47   ` David Lechner
@ 2026-01-28 23:14   ` Menderes Sabaz
  2026-01-29 10:54     ` Andy Shevchenko
  2026-01-29 16:16   ` [PATCH v2] iio: dac: ad5360: convert " Jonathan Cameron
  3 siblings, 1 reply; 11+ messages in thread
From: Menderes Sabaz @ 2026-01-28 23:14 UTC (permalink / raw)
  To: linux-iio, lars, Michael.Hennerich, jic23
  Cc: dlechner, nuno.sa, andy, Menderes Sabaz

Converting mutex_lock and mutex_unlock to guard(mutex)

Signed-off-by: Menderes Sabaz <sabazmenderes@gmail.com>
---
 drivers/iio/dac/ad5360.c | 29 +++++++++--------------------
 1 file changed, 9 insertions(+), 20 deletions(-)

diff --git a/drivers/iio/dac/ad5360.c b/drivers/iio/dac/ad5360.c
index 8271849b1..e79ad64d7 100644
--- a/drivers/iio/dac/ad5360.c
+++ b/drivers/iio/dac/ad5360.c
@@ -206,14 +206,10 @@ static int ad5360_write_unlocked(struct iio_dev *indio_dev,
 static int ad5360_write(struct iio_dev *indio_dev, unsigned int cmd,
 	unsigned int addr, unsigned int val, unsigned int shift)
 {
-	int ret;
 	struct ad5360_state *st = iio_priv(indio_dev);
 
-	mutex_lock(&st->lock);
-	ret = ad5360_write_unlocked(indio_dev, cmd, addr, val, shift);
-	mutex_unlock(&st->lock);
-
-	return ret;
+	guard(mutex)(&st->lock);
+	return ad5360_write_unlocked(indio_dev, cmd, addr, val, shift);
 }
 
 static int ad5360_read(struct iio_dev *indio_dev, unsigned int type,
@@ -232,7 +228,7 @@ static int ad5360_read(struct iio_dev *indio_dev, unsigned int type,
 		},
 	};
 
-	mutex_lock(&st->lock);
+	guard(mutex)(&st->lock);
 
 	st->data[0].d32 = cpu_to_be32(AD5360_CMD(AD5360_CMD_SPECIAL_FUNCTION) |
 		AD5360_ADDR(AD5360_REG_SF_READBACK) |
@@ -240,12 +236,10 @@ static int ad5360_read(struct iio_dev *indio_dev, unsigned int type,
 		AD5360_READBACK_ADDR(addr));
 
 	ret = spi_sync_transfer(st->spi, t, ARRAY_SIZE(t));
-	if (ret >= 0)
-		ret = be32_to_cpu(st->data[1].d32) & 0xffff;
-
-	mutex_unlock(&st->lock);
+	if (ret < 0)
+		return ret;
 
-	return ret;
+	return be32_to_cpu(st->data[1].d32) & 0xffff;
 }
 
 static ssize_t ad5360_read_dac_powerdown(struct device *dev,
@@ -262,19 +256,14 @@ static int ad5360_update_ctrl(struct iio_dev *indio_dev, unsigned int set,
 	unsigned int clr)
 {
 	struct ad5360_state *st = iio_priv(indio_dev);
-	int ret;
 
-	mutex_lock(&st->lock);
+	guard(mutex)(&st->lock);
 
 	st->ctrl |= set;
 	st->ctrl &= ~clr;
 
-	ret = ad5360_write_unlocked(indio_dev, AD5360_CMD_SPECIAL_FUNCTION,
-			AD5360_REG_SF_CTRL, st->ctrl, 0);
-
-	mutex_unlock(&st->lock);
-
-	return ret;
+	return ad5360_write_unlocked(indio_dev, AD5360_CMD_SPECIAL_FUNCTION,
+		AD5360_REG_SF_CTRL, st->ctrl, 0);
 }
 
 static ssize_t ad5360_write_dac_powerdown(struct device *dev,
-- 
2.52.0


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

* Re: [PATCH] iio: dac: ad5360: converting to guard(mutex)
  2026-01-28 23:14   ` [PATCH] iio: dac: ad5360: converting " Menderes Sabaz
@ 2026-01-29 10:54     ` Andy Shevchenko
  0 siblings, 0 replies; 11+ messages in thread
From: Andy Shevchenko @ 2026-01-29 10:54 UTC (permalink / raw)
  To: Menderes Sabaz
  Cc: linux-iio, lars, Michael.Hennerich, jic23, dlechner, nuno.sa,
	andy

On Thu, Jan 29, 2026 at 02:14:19AM +0300, Menderes Sabaz wrote:
> Converting mutex_lock and mutex_unlock to guard(mutex)

Refer to the functions as func() and don't forget period at the end.

  Converting mutex_lock() and mutex_unlock() to guard(mutex)().

  ...

> +	return ad5360_write_unlocked(indio_dev, AD5360_CMD_SPECIAL_FUNCTION,
> +		AD5360_REG_SF_CTRL, st->ctrl, 0);

Wrong indentation.

-- 
With Best Regards,
Andy Shevchenko



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

* [PATCH] iio: dac: ad5360: converting to guard(mutex)
@ 2026-01-29 11:37 Menderes Sabaz
  2026-01-29 14:38 ` David Lechner
  0 siblings, 1 reply; 11+ messages in thread
From: Menderes Sabaz @ 2026-01-29 11:37 UTC (permalink / raw)
  To: lars, Michael.Hennerich, jic23; +Cc: dlechner, andy, linux-iio, Menderes Sabaz

Converting mutex_lock and mutex_unlock to guard(mutex)

Signed-off-by: Menderes Sabaz <sabazmenderes@gmail.com>
---
 drivers/iio/dac/ad5360.c | 29 +++++++++--------------------
 1 file changed, 9 insertions(+), 20 deletions(-)

diff --git a/drivers/iio/dac/ad5360.c b/drivers/iio/dac/ad5360.c
index 8271849b1..5f51f0c12 100644
--- a/drivers/iio/dac/ad5360.c
+++ b/drivers/iio/dac/ad5360.c
@@ -206,14 +206,10 @@ static int ad5360_write_unlocked(struct iio_dev *indio_dev,
 static int ad5360_write(struct iio_dev *indio_dev, unsigned int cmd,
 	unsigned int addr, unsigned int val, unsigned int shift)
 {
-	int ret;
 	struct ad5360_state *st = iio_priv(indio_dev);
 
-	mutex_lock(&st->lock);
-	ret = ad5360_write_unlocked(indio_dev, cmd, addr, val, shift);
-	mutex_unlock(&st->lock);
-
-	return ret;
+	guard(mutex)(&st->lock);
+	return ad5360_write_unlocked(indio_dev, cmd, addr, val, shift);
 }
 
 static int ad5360_read(struct iio_dev *indio_dev, unsigned int type,
@@ -232,7 +228,7 @@ static int ad5360_read(struct iio_dev *indio_dev, unsigned int type,
 		},
 	};
 
-	mutex_lock(&st->lock);
+	guard(mutex)(&st->lock);
 
 	st->data[0].d32 = cpu_to_be32(AD5360_CMD(AD5360_CMD_SPECIAL_FUNCTION) |
 		AD5360_ADDR(AD5360_REG_SF_READBACK) |
@@ -240,12 +236,10 @@ static int ad5360_read(struct iio_dev *indio_dev, unsigned int type,
 		AD5360_READBACK_ADDR(addr));
 
 	ret = spi_sync_transfer(st->spi, t, ARRAY_SIZE(t));
-	if (ret >= 0)
-		ret = be32_to_cpu(st->data[1].d32) & 0xffff;
-
-	mutex_unlock(&st->lock);
+	if (ret < 0)
+		return ret;
 
-	return ret;
+	return be32_to_cpu(st->data[1].d32) & 0xffff;
 }
 
 static ssize_t ad5360_read_dac_powerdown(struct device *dev,
@@ -262,19 +256,14 @@ static int ad5360_update_ctrl(struct iio_dev *indio_dev, unsigned int set,
 	unsigned int clr)
 {
 	struct ad5360_state *st = iio_priv(indio_dev);
-	int ret;
 
-	mutex_lock(&st->lock);
+	guard(mutex)(&st->lock);
 
 	st->ctrl |= set;
 	st->ctrl &= ~clr;
 
-	ret = ad5360_write_unlocked(indio_dev, AD5360_CMD_SPECIAL_FUNCTION,
-			AD5360_REG_SF_CTRL, st->ctrl, 0);
-
-	mutex_unlock(&st->lock);
-
-	return ret;
+	return ad5360_write_unlocked(indio_dev, AD5360_CMD_SPECIAL_FUNCTION,
+				 AD5360_REG_SF_CTRL, st->ctrl, 0);
 }
 
 static ssize_t ad5360_write_dac_powerdown(struct device *dev,
-- 
2.52.0


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

* Re: [PATCH] iio: dac: ad5360: converting to guard(mutex)
  2026-01-29 11:37 [PATCH] iio: dac: ad5360: converting " Menderes Sabaz
@ 2026-01-29 14:38 ` David Lechner
  0 siblings, 0 replies; 11+ messages in thread
From: David Lechner @ 2026-01-29 14:38 UTC (permalink / raw)
  To: Menderes Sabaz, lars, Michael.Hennerich, jic23; +Cc: andy, linux-iio

I'm confused. Is this supposed to be v3 or v4?

See https://www.kernel.org/doc/html/latest/process/submitting-patches.html

On 1/29/26 5:37 AM, Menderes Sabaz wrote:
> Converting mutex_lock and mutex_unlock to guard(mutex)
> 

I gave my Reviewed-by: tag. It should have been picked up here
or an explanation given why it was not. (Also explained in the link
above.)

> Signed-off-by: Menderes Sabaz <sabazmenderes@gmail.com>
> ---

A changelog should go here on what was changed since the last
revision. (Also explained in the link above.)

>  drivers/iio/dac/ad5360.c | 29 +++++++++--------------------
>  1 file changed, 9 insertions(+), 20 deletions(-)
> 
> diff --git a/drivers/iio/dac/ad5360.c b/drivers/iio/dac/ad5360.c
> index 8271849b1..5f51f0c12 100644
> --- a/drivers/iio/dac/ad5360.c
> +++ b/drivers/iio/dac/ad5360.c
> @@ -206,14 +206,10 @@ static int ad5360_write_unlocked(struct iio_dev *indio_dev,
>  static int ad5360_write(struct iio_dev *indio_dev, unsigned int cmd,
>  	unsigned int addr, unsigned int val, unsigned int shift)
>  {
> -	int ret;
>  	struct ad5360_state *st = iio_priv(indio_dev);
>  
> -	mutex_lock(&st->lock);
> -	ret = ad5360_write_unlocked(indio_dev, cmd, addr, val, shift);
> -	mutex_unlock(&st->lock);
> -
> -	return ret;
> +	guard(mutex)(&st->lock);
> +	return ad5360_write_unlocked(indio_dev, cmd, addr, val, shift);
>  }
>  
>  static int ad5360_read(struct iio_dev *indio_dev, unsigned int type,
> @@ -232,7 +228,7 @@ static int ad5360_read(struct iio_dev *indio_dev, unsigned int type,
>  		},
>  	};
>  
> -	mutex_lock(&st->lock);
> +	guard(mutex)(&st->lock);
>  
>  	st->data[0].d32 = cpu_to_be32(AD5360_CMD(AD5360_CMD_SPECIAL_FUNCTION) |
>  		AD5360_ADDR(AD5360_REG_SF_READBACK) |
> @@ -240,12 +236,10 @@ static int ad5360_read(struct iio_dev *indio_dev, unsigned int type,
>  		AD5360_READBACK_ADDR(addr));
>  
>  	ret = spi_sync_transfer(st->spi, t, ARRAY_SIZE(t));
> -	if (ret >= 0)
> -		ret = be32_to_cpu(st->data[1].d32) & 0xffff;
> -
> -	mutex_unlock(&st->lock);
> +	if (ret < 0)
> +		return ret;
>  
> -	return ret;
> +	return be32_to_cpu(st->data[1].d32) & 0xffff;
>  }
>  
>  static ssize_t ad5360_read_dac_powerdown(struct device *dev,
> @@ -262,19 +256,14 @@ static int ad5360_update_ctrl(struct iio_dev *indio_dev, unsigned int set,
>  	unsigned int clr)
>  {
>  	struct ad5360_state *st = iio_priv(indio_dev);
> -	int ret;
>  
> -	mutex_lock(&st->lock);
> +	guard(mutex)(&st->lock);
>  
>  	st->ctrl |= set;
>  	st->ctrl &= ~clr;
>  
> -	ret = ad5360_write_unlocked(indio_dev, AD5360_CMD_SPECIAL_FUNCTION,
> -			AD5360_REG_SF_CTRL, st->ctrl, 0);
> -
> -	mutex_unlock(&st->lock);
> -
> -	return ret;
> +	return ad5360_write_unlocked(indio_dev, AD5360_CMD_SPECIAL_FUNCTION,
> +				 AD5360_REG_SF_CTRL, st->ctrl, 0);

Not sure the alignment is still quite right here. "indio_dev" and
"AD5360_REG_SF_CTRL" should be starting on the same column. Running
./scipts/checkpatch.pl should give a warning if they are not.

>  }
>  
>  static ssize_t ad5360_write_dac_powerdown(struct device *dev,


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

* Re: [PATCH v2] iio: dac: ad5360: convert to guard(mutex)
  2026-01-28 15:32 ` [PATCH v2] " Menderes Sabaz
                     ` (2 preceding siblings ...)
  2026-01-28 23:14   ` [PATCH] iio: dac: ad5360: converting " Menderes Sabaz
@ 2026-01-29 16:16   ` Jonathan Cameron
  2026-01-29 16:18     ` Jonathan Cameron
  3 siblings, 1 reply; 11+ messages in thread
From: Jonathan Cameron @ 2026-01-29 16:16 UTC (permalink / raw)
  To: Menderes Sabaz
  Cc: Michael.Hennerich, andy, dlechner, lars, linux-iio, nuno.sa

On Wed, 28 Jan 2026 18:32:21 +0300
Menderes Sabaz <sabazmenderes@gmail.com> wrote:

> Converting mutex_lock and mutex_unlock to guard(mutex)
> Simplify the locking logic by using guard(mutex).
> This removes the need for explicit unlock calls in error paths and
> simplifies the code by removing goto labels.
> 
> Signed-off-by: Menderes Sabaz <sabazmenderes@gmail.com>

Hi Menderes,

Applied to the togreg branch of iio.git.

Thanks,

Jonathan

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

* Re: [PATCH v2] iio: dac: ad5360: convert to guard(mutex)
  2026-01-29 16:16   ` [PATCH v2] iio: dac: ad5360: convert " Jonathan Cameron
@ 2026-01-29 16:18     ` Jonathan Cameron
  0 siblings, 0 replies; 11+ messages in thread
From: Jonathan Cameron @ 2026-01-29 16:18 UTC (permalink / raw)
  To: Menderes Sabaz
  Cc: Michael.Hennerich, andy, dlechner, lars, linux-iio, nuno.sa

On Thu, 29 Jan 2026 16:16:21 +0000
Jonathan Cameron <jic23@kernel.org> wrote:

> On Wed, 28 Jan 2026 18:32:21 +0300
> Menderes Sabaz <sabazmenderes@gmail.com> wrote:
> 
> > Converting mutex_lock and mutex_unlock to guard(mutex)
> > Simplify the locking logic by using guard(mutex).
> > This removes the need for explicit unlock calls in error paths and
> > simplifies the code by removing goto labels.
> > 
> > Signed-off-by: Menderes Sabaz <sabazmenderes@gmail.com>  
> 
> Hi Menderes,
> 
> Applied to the togreg branch of iio.git.
Dropped again.  For some reason my local email hadn't picked up
the rest of the discussion and I only noticed when I looked at patchwork.

> 
> Thanks,
> 
> Jonathan
> 


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

end of thread, other threads:[~2026-01-29 16:18 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-01-28 11:37 [PATCH] iio: dac: ad5360: convert to guard(mutex) Menderes Sabaz
2026-01-28 14:54 ` David Lechner
2026-01-28 15:32 ` [PATCH v2] " Menderes Sabaz
2026-01-28 22:32   ` Andy Shevchenko
2026-01-28 22:47   ` David Lechner
2026-01-28 23:14   ` [PATCH] iio: dac: ad5360: converting " Menderes Sabaz
2026-01-29 10:54     ` Andy Shevchenko
2026-01-29 16:16   ` [PATCH v2] iio: dac: ad5360: convert " Jonathan Cameron
2026-01-29 16:18     ` Jonathan Cameron
  -- strict thread matches above, loose matches on Subject: below --
2026-01-29 11:37 [PATCH] iio: dac: ad5360: converting " Menderes Sabaz
2026-01-29 14:38 ` David Lechner

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