iio: light: iqs621-als: use lock guards
PATCH v2 1/1 iio: light: iqs621-als: use lock guards
Use guard(mutex)() for handling mutex lock instead of manually locking and unlocking the mutex. This prevents forgotten locks due to early exits and remove the need of gotos.
---
v2:
- Keep include list ordered
- Remove redundant 'else'
- Remove unnecessary variable 'ret'
--- drivers/iio/light/iqs621-als.c | 85 +++++++++++----------------------- 1 file changed, 28 insertions(+), 57 deletions(-)
drivers/iio/light/iqs621-als.c +28 -57
@@ -5,6 +5,7 @@* Copyright (C) 2019 Jeff LaBundy <[email protected]> */ +#include <linux/cleanup.h> #include <linux/device.h> #include <linux/iio/events.h> #include <linux/iio/iio.h>
@@ -107,25 +108,21 @@ static int iqs621_als_notifier(struct notifier_block *notifier, indio_dev = iqs621_als->indio_dev; timestamp =iio_get_time_ns (indio_dev); -mutex_lock (&iqs621_als->lock); +guard (mutex)(&iqs621_als->lock);if (event_flags &BIT (IQS62X_EVENT_SYS_RESET )) { ret =iqs621_als_init (iqs621_als);if (ret) {dev_err (indio_dev->dev.parent,"Failed to re-initialize device: %d\n" , ret); - ret =NOTIFY_BAD ; - }else { - ret =NOTIFY_OK ; +return NOTIFY_BAD ; } - - goto err_mutex; +return NOTIFY_OK ; }if (!iqs621_als->light_en && !iqs621_als->range_en && !iqs621_als->prox_en) { - ret =NOTIFY_DONE ; - goto err_mutex; +return NOTIFY_DONE ; }/* IQS621 only */
@@ -181,12 +178,7 @@ static int iqs621_als_notifier(struct notifier_block *notifier, iqs621_als->als_flags = event_data->als_flags; iqs621_als->ir_flags = event_data->ir_flags; - ret =NOTIFY_OK ; - -err_mutex: -mutex_unlock (&iqs621_als->lock); - -return ret; +return NOTIFY_OK ; }static void iqs621_als_notifier_unregister (void *context)
@@ -241,30 +233,22 @@ static int iqs621_als_read_event_config(struct iio_dev *indio_dev, enum iio_event_direction dir) {struct iqs621_als_private *iqs621_als =iio_priv (indio_dev); -int ret; -mutex_lock (&iqs621_als->lock); +guard (mutex)(&iqs621_als->lock);switch (chan->type) {case IIO_LIGHT : - ret = iqs621_als->light_en; -break ; +return iqs621_als->light_en;case IIO_INTENSITY : - ret = iqs621_als->range_en; -break ; +return iqs621_als->range_en;case IIO_PROXIMITY : - ret = iqs621_als->prox_en; -break ; +return iqs621_als->prox_en;default : - ret = -EINVAL ; +return -EINVAL ; } - -mutex_unlock (&iqs621_als->lock); - -return ret; } static int iqs621_als_write_event_config(struct iio_dev *indio_dev,
@@ -278,11 +262,11 @@ static int iqs621_als_write_event_config(struct iio_dev *indio_dev,unsigned int val;int ret; -mutex_lock (&iqs621_als->lock); +guard (mutex)(&iqs621_als->lock); ret =regmap_read (iqs62x->regmap, iqs62x->dev_desc->als_flags, &val);if (ret) - goto err_mutex; +return ret; iqs621_als->als_flags = val;switch (chan->type) {
@@ -293,7 +277,7 @@ static int iqs621_als_write_event_config(struct iio_dev *indio_dev, 0xFF);if (!ret) iqs621_als->light_en = state; -break ; +return ret;case IIO_INTENSITY : ret = regmap_update_bits(iqs62x->regmap, IQS620_GLBL_EVENT_MASK,
@@ -302,12 +286,12 @@ static int iqs621_als_write_event_config(struct iio_dev *indio_dev, 0xFF);if (!ret) iqs621_als->range_en = state; -break ; +return ret;case IIO_PROXIMITY : ret =regmap_read (iqs62x->regmap,IQS622_IR_FLAGS , &val);if (ret) - goto err_mutex; +return ret; iqs621_als->ir_flags = val; ret = regmap_update_bits(iqs62x->regmap, IQS620_GLBL_EVENT_MASK,
@@ -315,16 +299,11 @@ static int iqs621_als_write_event_config(struct iio_dev *indio_dev, state ? 0 : 0xFF);if (!ret) iqs621_als->prox_en = state; -break ; +return ret;default : - ret = -EINVAL ; +return -EINVAL ; } - -err_mutex: -mutex_unlock (&iqs621_als->lock); - -return ret; } static int iqs621_als_read_event_value(struct iio_dev *indio_dev,
@@ -335,33 +314,28 @@ static int iqs621_als_read_event_value(struct iio_dev *indio_dev, int *val, int *val2) { struct iqs621_als_private *iqs621_als = iio_priv(indio_dev); -int ret =IIO_VAL_INT ; -mutex_lock (&iqs621_als->lock); +guard (mutex)(&iqs621_als->lock);switch (dir) {case IIO_EV_DIR_RISING : *val = iqs621_als->thresh_light *16 ; -break ; +return IIO_VAL_INT ;case IIO_EV_DIR_FALLING : *val = iqs621_als->thresh_dark *4 ; -break ; +return IIO_VAL_INT ;case IIO_EV_DIR_EITHER :if (iqs621_als->ir_flags_mask ==IQS622_IR_FLAGS_TOUCH ) *val = iqs621_als->thresh_prox *4 ;else *val = iqs621_als->thresh_prox; -break ; +return IIO_VAL_INT ;default : - ret = -EINVAL ; +return -EINVAL ; } - -mutex_unlock (&iqs621_als->lock); - -return ret; } static int iqs621_als_write_event_value(struct iio_dev *indio_dev,
@@ -377,7 +351,7 @@ static int iqs621_als_write_event_value(struct iio_dev *indio_dev,u8 ir_flags_mask, *thresh_cache;int ret = -EINVAL ; -mutex_lock (&iqs621_als->lock); +guard (mutex)(&iqs621_als->lock);switch (dir) {case IIO_EV_DIR_RISING :
@@ -426,29 +400,26 @@ static int iqs621_als_write_event_value(struct iio_dev *indio_dev,break ;default : - goto err_mutex; +return ret; } thresh_cache = &iqs621_als->thresh_prox;break ;default : - goto err_mutex; +return ret; }if (thresh_val >0xFF ) - goto err_mutex; +return ret; ret =regmap_write (iqs62x->regmap, thresh_reg, thresh_val);if (ret) - goto err_mutex; +return ret; *thresh_cache = thresh_val; iqs621_als->ir_flags_mask = ir_flags_mask; -err_mutex: -mutex_unlock (&iqs621_als->lock); -return ret; }
Signature · 1 line
2.51.0
Jonathan Cameron
maintainerQuoted 10 lines · On Tue, 21 Apr 2026 01:00:11 -0300 Pedro Barletta Gennari <[email protected]>…
Use guard(mutex)() for handling mutex lock instead of manually locking and unlocking the mutex. This prevents forgotten locks due to early exits and remove the need of gotos.
Signed-off-by Pedro Barletta Gennari <[email protected]>---
v2:
- Keep include list ordered
- Remove redundant 'else'
- Remove unnecessary variable 'ret'
Hi Pedro,
The changes here enable a few additional code improvements that I'd like to see made in the same patch.
See below,
Thanks,
Jonathan
Quoted 30 lines
--- drivers/iio/light/iqs621-als.c | 85 +++++++++++----------------------- 1 file changed, 28 insertions(+), 57 deletions(-)drivers/iio/light/iqs621-als.c +2
-3@@ -5,6 +5,7 @@* Copyright (C) 2019 Jeff LaBundy <[email protected]> */ +#include <linux/cleanup.h> #include <linux/device.h> #include <linux/iio/events.h> #include <linux/iio/iio.h> @@ -107,25 +108,21 @@ static int iqs621_als_notifier(struct notifier_block *notifier, indio_dev = iqs621_als->indio_dev; timestamp =iio_get_time_ns (indio_dev); -mutex_lock (&iqs621_als->lock); +guard (mutex)(&iqs621_als->lock);if (event_flags &BIT (IQS62X_EVENT_SYS_RESET )) { ret =iqs621_als_init (iqs621_als);if (ret) {dev_err (indio_dev->dev.parent,"Failed to re-initialize device: %d\n" , ret); - ret =NOTIFY_BAD ; - }else {
drivers/iio/light/iqs621-als.c static int iqs621_als_notifier(struct notifier_block *notifier, · line 124
Quoted 10 lines
drivers/iio/light/iqs621-als.c +2
-3- ret =NOTIFY_OK ; +return NOTIFY_BAD ; } - - goto err_mutex; +return NOTIFY_OK ; }if (!iqs621_als->light_en && !iqs621_als->range_en && !iqs621_als->prox_en) {
if (!iqs621_als->light_en && !iqs621_als->range_en && !iqs621_als->prox_en)
After change noted below, I'd just make this a slightly long single line. We have gotten more relaxed on going a little over 80 chars since this code was written.
drivers/iio/light/iqs621-als.c static int iqs621_als_notifier(struct notifier_block *notifier, · line 126
Quoted 4 lines
drivers/iio/light/iqs621-als.c +1
-2- ret =NOTIFY_DONE ; - goto err_mutex; +return NOTIFY_DONE ; }
Single statement so { } not needed
Quoted 19 lines
drivers/iio/light/iqs621-als.c +2
-2static int iqs621_als_write_event_config(struct iio_dev *indio_dev,@@ -278,11 +262,11 @@ static int iqs621_als_write_event_config(struct iio_dev *indio_dev,unsigned int val;int ret; -mutex_lock (&iqs621_als->lock); +guard (mutex)(&iqs621_als->lock); ret =regmap_read (iqs62x->regmap, iqs62x->dev_desc->als_flags, &val);if (ret) - goto err_mutex; +return ret; iqs621_als->als_flags = val;switch (chan->type) {
drivers/iio/light/iqs621-als.c static int iqs621_als_write_event_config(struct iio_dev *indio_dev, · line 280
Quoted 5 lines
drivers/iio/light/iqs621-als.c +1
-1@@ -293,7 +277,7 @@ static int iqs621_als_write_event_config(struct iio_dev *indio_dev, 0xFF);if (!ret) iqs621_als->light_en = state; -break ; +return ret;
Same as two cases below
drivers/iio/light/iqs621-als.c static int iqs621_als_write_event_config(struct iio_dev *indio_dev, · line 289
Quoted 9 lines
drivers/iio/light/iqs621-als.c +1
-1case IIO_INTENSITY : ret = regmap_update_bits(iqs62x->regmap, IQS620_GLBL_EVENT_MASK,@@ -302,12 +286,12 @@ static int iqs621_als_write_event_config(struct iio_dev *indio_dev, 0xFF);if (!ret) iqs621_als->range_en = state; -break ; +return ret;
As below, flip this to
if (ret) return ret; iqs621_als->range_en = state; return 0;
drivers/iio/light/iqs621-als.c static int iqs621_als_write_event_config(struct iio_dev *indio_dev, · line 301
Quoted 13 lines
drivers/iio/light/iqs621-als.c +1
-1case IIO_PROXIMITY : ret =regmap_read (iqs62x->regmap,IQS622_IR_FLAGS , &val);if (ret) - goto err_mutex; +return ret; iqs621_als->ir_flags = val; ret = regmap_update_bits(iqs62x->regmap, IQS620_GLBL_EVENT_MASK,@@ -315,16 +299,11 @@ static int iqs621_als_write_event_config(struct iio_dev *indio_dev, state ? 0 : 0xFF);if (!ret) iqs621_als->prox_en = state;
Please flip this to the more common form. Makes reading the code a little easier if errors are handled out of line as early as possible.
if (ret) return ret; iqs621_als->prox_en = state; return 0;
Quoted 16 lines
drivers/iio/light/iqs621-als.c +2
-7-break ; +return ret;default : - ret = -EINVAL ; +return -EINVAL ; } - -err_mutex: -mutex_unlock (&iqs621_als->lock); - -return ret; } static int iqs621_als_write_event_value(struct iio_dev *indio_dev,
drivers/iio/light/iqs621-als.c static int iqs621_als_write_event_value(struct iio_dev *indio_dev, · line 352
Quoted 2 lines
drivers/iio/light/iqs621-als.c +0
-0@@ -377,7 +351,7 @@ static int iqs621_als_write_event_value(struct iio_dev *indio_dev,u8 ir_flags_mask, *thresh_cache;int ret = -EINVAL ;
Drop this initialization and instead return the specific value on error paths.
Quoted 10 lines
drivers/iio/light/iqs621-als.c +1
-1-mutex_lock (&iqs621_als->lock); +guard (mutex)(&iqs621_als->lock);switch (dir) {case IIO_EV_DIR_RISING :@@ -426,29 +400,26 @@ static int iqs621_als_write_event_value(struct iio_dev *indio_dev,break ;default :
drivers/iio/light/iqs621-als.c static int iqs621_als_write_event_value(struct iio_dev *indio_dev, · line 410
Quoted 10 lines
drivers/iio/light/iqs621-als.c +2
-2- goto err_mutex; +return ret; } thresh_cache = &iqs621_als->thresh_prox;break ;default : - goto err_mutex; +return ret;
return -EINVAL;
drivers/iio/light/iqs621-als.c static int iqs621_als_write_event_value(struct iio_dev *indio_dev, · line 414
Quoted 5 lines
drivers/iio/light/iqs621-als.c +1
-1}if (thresh_val >0xFF ) - goto err_mutex; +return ret;
return -EINVAL;
Quoted 15 lines
drivers/iio/light/iqs621-als.c +1
-4ret =regmap_write (iqs62x->regmap, thresh_reg, thresh_val);if (ret) - goto err_mutex; +return ret; *thresh_cache = thresh_val; iqs621_als->ir_flags_mask = ir_flags_mask; -err_mutex: -mutex_unlock (&iqs621_als->lock); -return ret; }
Quoted 16 lines · Jonathan Cameron
Quoted 10 lines · On Tue, 21 Apr 2026 01:00:11 -0300 Pedro Barletta Gennari <[email protected]>…
Use guard(mutex)() for handling mutex lock instead of manually locking and unlocking the mutex. This prevents forgotten locks due to early exits and remove the need of gotos.
Signed-off-by Pedro Barletta Gennari <[email protected]>---
v2:
- Keep include list ordered
- Remove redundant 'else'
- Remove unnecessary variable 'ret'Hi Pedro,
Quoted 9 lines
The changes here enable a few additional code improvements that I'd like to see made in the same patch.
See below,
Thanks,
Jonathan
Hi Jonathan,
Just to be sure, do you want everything to be in the same commit?
Quoted 30 lines
Quoted 14 lines
drivers/iio/light/iqs621-als.c +1
-3@@ -107,25 +108,21 @@ static int iqs621_als_notifier(struct notifier_block *notifier, indio_dev = iqs621_als->indio_dev; timestamp =iio_get_time_ns (indio_dev); -mutex_lock (&iqs621_als->lock); +guard (mutex)(&iqs621_als->lock);if (event_flags &BIT (IQS62X_EVENT_SYS_RESET )) { ret =iqs621_als_init (iqs621_als);if (ret) {dev_err (indio_dev->dev.parent,"Failed to re-initialize device: %d\n" , ret); - ret =NOTIFY_BAD ; - }else {drivers/iio/light/iqs621-als.c static int iqs621_als_notifier(struct notifier_block *notifier, · line 124
Quoted 10 lines
drivers/iio/light/iqs621-als.c +2
-3- ret =NOTIFY_OK ; +return NOTIFY_BAD ; } - - goto err_mutex; +return NOTIFY_OK ; }if (!iqs621_als->light_en && !iqs621_als->range_en && !iqs621_als->prox_en) {if (!iqs621_als->light_en && !iqs621_als->range_en && !iqs621_als->prox_en)After change noted below, I'd just make this a slightly long single line. We have gotten more relaxed on going a little over 80 chars since this code was written.
Quoted 7 lines
drivers/iio/light/iqs621-als.c static int iqs621_als_notifier(struct notifier_block *notifier, · line 126
Quoted 4 lines
drivers/iio/light/iqs621-als.c +1
-2- ret =NOTIFY_DONE ; - goto err_mutex; +return NOTIFY_DONE ; }Single statement so { } not needed
Ok!
Quoted 41 lines
drivers/iio/light/iqs621-als.c static int iqs621_als_write_event_config(struct iio_dev *indio_dev, · line 280
Quoted 6 lines
drivers/iio/light/iqs621-als.c +1
-1@@ -293,7 +277,7 @@ static int iqs621_als_write_event_config(struct iio_dev *indio_dev, 0xFF);if (!ret) iqs621_als->light_en = state; -break ; +return ret;Same as two cases below
drivers/iio/light/iqs621-als.c static int iqs621_als_write_event_config(struct iio_dev *indio_dev, · line 289
Quoted 9 lines
drivers/iio/light/iqs621-als.c +1
-1case IIO_INTENSITY : ret = regmap_update_bits(iqs62x->regmap, IQS620_GLBL_EVENT_MASK,@@ -302,12 +286,12 @@ static int iqs621_als_write_event_config(struct iio_dev *indio_dev, 0xFF);if (!ret) iqs621_als->range_en = state; -break ; +return ret;As below, flip this to
if (ret) return ret; iqs621_als->range_en = state; return 0;drivers/iio/light/iqs621-als.c static int iqs621_als_write_event_config(struct iio_dev *indio_dev, · line 301
Quoted 13 lines
drivers/iio/light/iqs621-als.c +1
-1case IIO_PROXIMITY : ret =regmap_read (iqs62x->regmap,IQS622_IR_FLAGS , &val);if (ret) - goto err_mutex; +return ret; iqs621_als->ir_flags = val; ret = regmap_update_bits(iqs62x->regmap, IQS620_GLBL_EVENT_MASK,@@ -315,16 +299,11 @@ static int iqs621_als_write_event_config(struct iio_dev *indio_dev, state ? 0 : 0xFF);if (!ret) iqs621_als->prox_en = state;Please flip this to the more common form. Makes reading the code a little easier if errors are handled out of line as early as possible.
Quoted 7 lines
if (ret)
return ret;
iqs621_als->prox_en = state;
return 0;Ok!
Quoted 7 lines
drivers/iio/light/iqs621-als.c static int iqs621_als_write_event_value(struct iio_dev *indio_dev, · line 352
Quoted 4 lines
drivers/iio/light/iqs621-als.c +0
-0static int iqs621_als_write_event_value(struct iio_dev *indio_dev,@@ -377,7 +351,7 @@ static int iqs621_als_write_event_value(struct iio_dev *indio_dev,u8 ir_flags_mask, *thresh_cache;int ret = -EINVAL ;Drop this initialization and instead return the specific value on error paths.
Ok!
Quoted 34 lines
Quoted 4 lines
drivers/iio/light/iqs621-als.c +0
-0@@ -426,29 +400,26 @@ static int iqs621_als_write_event_value(struct iio_dev *indio_dev,break ;default :drivers/iio/light/iqs621-als.c static int iqs621_als_write_event_value(struct iio_dev *indio_dev, · line 410
Quoted 10 lines
drivers/iio/light/iqs621-als.c +2
-2- goto err_mutex; +return ret; } thresh_cache = &iqs621_als->thresh_prox;break ;default : - goto err_mutex; +return ret;return
-EINVAL;drivers/iio/light/iqs621-als.c static int iqs621_als_write_event_value(struct iio_dev *indio_dev, · line 414
Quoted 5 lines
drivers/iio/light/iqs621-als.c +1
-1}if (thresh_val >0xFF ) - goto err_mutex; +return ret;return
-EINVAL;Quoted 9 lines
drivers/iio/light/iqs621-als.c +1
-1ret =regmap_write (iqs62x->regmap, thresh_reg, thresh_val);if (ret) - goto err_mutex; +return ret; *thresh_cache = thresh_val; iqs621_als->ir_flags_mask = ir_flags_mask;
Quoted 7 lines
drivers/iio/light/iqs621-als.c static int iqs621_als_write_event_value(struct iio_dev *indio_dev, · line 425
Quoted 6 lines
drivers/iio/light/iqs621-als.c +0
-3-err_mutex: -mutex_unlock (&iqs621_als->lock); -return ret; }
In this case, should this last return be "return 0;"?
--
Thanks,
Pedro
Jonathan Cameron
maintainerQuoted 22 lines · On Sun, 26 Apr 2026 13:17:01 -0300 Pedro Barletta Gennari <[email protected]>…
Quoted 21 lines · Jonathan Cameron
Quoted 10 lines · On Tue, 21 Apr 2026 01:00:11 -0300 Pedro Barletta Gennari <[email protected]>…
Use guard(mutex)() for handling mutex lock instead of manually locking and unlocking the mutex. This prevents forgotten locks due to early exits and remove the need of gotos.
Signed-off-by Pedro Barletta Gennari <[email protected]>---
v2:
- Keep include list ordered
- Remove redundant 'else'
- Remove unnecessary variable 'ret'Hi Pedro,
The changes here enable a few additional code improvements that I'd like to see made in the same patch.
See below,
Quoted 8 lines
Quoted 4 lines
Thanks,
Jonathan
Hi Jonathan,
Just to be sure, do you want everything to be in the same commit?
The places where I'm asking you to flip if (!ret) to if (ret) logic should be a second patch. Do them in which ever order makes for cleanest series.
I've commented more on individual changes below.
Quoted 23 lines
Quoted 23 lines
Quoted 23 lines
drivers/iio/light/iqs621-als.c +3
-6@@ -107,25 +108,21 @@ static int iqs621_als_notifier(struct notifier_block *notifier, indio_dev = iqs621_als->indio_dev; timestamp =iio_get_time_ns (indio_dev); -mutex_lock (&iqs621_als->lock); +guard (mutex)(&iqs621_als->lock);if (event_flags &BIT (IQS62X_EVENT_SYS_RESET )) { ret =iqs621_als_init (iqs621_als);if (ret) {dev_err (indio_dev->dev.parent,"Failed to re-initialize device: %d\n" , ret); - ret =NOTIFY_BAD ; - }else { - ret =NOTIFY_OK ; +return NOTIFY_BAD ; } - - goto err_mutex; +return NOTIFY_OK ; }
Quoted 7 lines
Quoted 7 lines
drivers/iio/light/iqs621-als.c static int iqs621_als_notifier(struct notifier_block *notifier, · line 124
Quoted 2 lines
drivers/iio/light/iqs621-als.c +0
-0if (!iqs621_als->light_en && !iqs621_als->range_en && !iqs621_als->prox_en) {if (!iqs621_als->light_en && !iqs621_als->range_en && !iqs621_als->prox_en)After change noted below, I'd just make this a slightly long single line. We have gotten more relaxed on going a little over 80 chars since this code was written.
This one is fine rolled into the guard() patch as you'll be changing it anyway to drop the {
Quoted 6 lines
Quoted 6 lines
Quoted 5 lines
drivers/iio/light/iqs621-als.c +1
-2- ret =NOTIFY_DONE ; - goto err_mutex; +return NOTIFY_DONE ; }
Quoted 26 lines
Quoted 2 lines
Single statement so { } not needed
Ok!
Quoted 21 lines
drivers/iio/light/iqs621-als.c static int iqs621_als_write_event_config(struct iio_dev *indio_dev, · line 280
Quoted 6 lines
drivers/iio/light/iqs621-als.c +1
-1@@ -293,7 +277,7 @@ static int iqs621_als_write_event_config(struct iio_dev *indio_dev, 0xFF);if (!ret) iqs621_als->light_en = state; -break ; +return ret;Same as two cases below
drivers/iio/light/iqs621-als.c static int iqs621_als_write_event_config(struct iio_dev *indio_dev, · line 289
Quoted 9 lines
drivers/iio/light/iqs621-als.c +1
-1case IIO_INTENSITY : ret = regmap_update_bits(iqs62x->regmap, IQS620_GLBL_EVENT_MASK,@@ -302,12 +286,12 @@ static int iqs621_als_write_event_config(struct iio_dev *indio_dev, 0xFF);if (!ret) iqs621_als->range_en = state; -break ; +return ret;As below, flip this to
if (ret) return ret; iqs621_als->range_en = state;
This ideally in a different patch.
Quoted 82 lines
Quoted 20 lines
return 0;drivers/iio/light/iqs621-als.c static int iqs621_als_write_event_config(struct iio_dev *indio_dev, · line 301
Quoted 13 lines
drivers/iio/light/iqs621-als.c +1
-1case IIO_PROXIMITY : ret =regmap_read (iqs62x->regmap,IQS622_IR_FLAGS , &val);if (ret) - goto err_mutex; +return ret; iqs621_als->ir_flags = val; ret = regmap_update_bits(iqs62x->regmap, IQS620_GLBL_EVENT_MASK,@@ -315,16 +299,11 @@ static int iqs621_als_write_event_config(struct iio_dev *indio_dev, state ? 0 : 0xFF);if (!ret) iqs621_als->prox_en = state;Please flip this to the more common form. Makes reading the code a little easier if errors are handled out of line as early as possible.
Quoted 7 lines
if (ret) return ret; iqs621_als->prox_en = state; return 0;Ok!
Quoted 7 lines
drivers/iio/light/iqs621-als.c static int iqs621_als_write_event_value(struct iio_dev *indio_dev, · line 352
Quoted 4 lines
drivers/iio/light/iqs621-als.c +0
-0static int iqs621_als_write_event_value(struct iio_dev *indio_dev,@@ -377,7 +351,7 @@ static int iqs621_als_write_event_value(struct iio_dev *indio_dev,u8 ir_flags_mask, *thresh_cache;int ret = -EINVAL ;Drop this initialization and instead return the specific value on error paths.
Ok!
Quoted 34 lines
Quoted 4 lines
drivers/iio/light/iqs621-als.c +0
-0@@ -426,29 +400,26 @@ static int iqs621_als_write_event_value(struct iio_dev *indio_dev,break ;default :drivers/iio/light/iqs621-als.c static int iqs621_als_write_event_value(struct iio_dev *indio_dev, · line 410
Quoted 10 lines
drivers/iio/light/iqs621-als.c +2
-2- goto err_mutex; +return ret; } thresh_cache = &iqs621_als->thresh_prox;break ;default : - goto err_mutex; +return ret;return
-EINVAL;drivers/iio/light/iqs621-als.c static int iqs621_als_write_event_value(struct iio_dev *indio_dev, · line 414
Quoted 5 lines
drivers/iio/light/iqs621-als.c +1
-1}if (thresh_val >0xFF ) - goto err_mutex; +return ret;return
-EINVAL;Quoted 9 lines
drivers/iio/light/iqs621-als.c +1
-1ret =regmap_write (iqs62x->regmap, thresh_reg, thresh_val);if (ret) - goto err_mutex; +return ret; *thresh_cache = thresh_val; iqs621_als->ir_flags_mask = ir_flags_mask;Quoted 7 lines
drivers/iio/light/iqs621-als.c static int iqs621_als_write_event_value(struct iio_dev *indio_dev, · line 425
Quoted 6 lines
drivers/iio/light/iqs621-als.c +0
-3-err_mutex: -mutex_unlock (&iqs621_als->lock); -return ret; }
Quoted 1 line
In this case, should this last return be "return 0;"?
Yes.
Quoted 5 lines
--
Thanks,Pedro