From: Pedro Barletta Gennari <pedro.pbg@usp.br>
To: andy@kernel.org, dlechner@baylibre.com, jic23@kernel.org,
nuno.sa@analog.com
Cc: pedro.pbg@usp.br, linux-iio@vger.kernel.org
Subject: [PATCH v3 2/2] iio: light: iqs621-als: prefer early error handling over if (!ret)
Date: Tue, 28 Apr 2026 22:29:55 -0300 [thread overview]
Message-ID: <20260429013640.26870-3-pedro.pbg@usp.br> (raw)
In-Reply-To: <20260429013640.26870-1-pedro.pbg@usp.br>
Handle errors as early as possible by replacing 'if (!ret)' with the
more common form 'if (ret)'. This makes the code easier to read.
Signed-off-by: Pedro Barletta Gennari <pedro.pbg@usp.br>
---
drivers/iio/light/iqs621-als.c | 24 +++++++++++++++---------
1 file changed, 15 insertions(+), 9 deletions(-)
diff --git a/drivers/iio/light/iqs621-als.c b/drivers/iio/light/iqs621-als.c
index 25a655b328fc..cd5843e3e2c3 100644
--- a/drivers/iio/light/iqs621-als.c
+++ b/drivers/iio/light/iqs621-als.c
@@ -273,18 +273,22 @@ static int iqs621_als_write_event_config(struct iio_dev *indio_dev,
iqs62x->dev_desc->als_mask,
iqs621_als->range_en || state ? 0 :
0xFF);
- if (!ret)
- iqs621_als->light_en = state;
- return ret;
+ if (ret)
+ return ret;
+ iqs621_als->light_en = state;
+
+ return 0;
case IIO_INTENSITY:
ret = regmap_update_bits(iqs62x->regmap, IQS620_GLBL_EVENT_MASK,
iqs62x->dev_desc->als_mask,
iqs621_als->light_en || state ? 0 :
0xFF);
- if (!ret)
- iqs621_als->range_en = state;
- return ret;
+ if (ret)
+ return ret;
+ iqs621_als->range_en = state;
+
+ return 0;
case IIO_PROXIMITY:
ret = regmap_read(iqs62x->regmap, IQS622_IR_FLAGS, &val);
@@ -295,9 +299,11 @@ static int iqs621_als_write_event_config(struct iio_dev *indio_dev,
ret = regmap_update_bits(iqs62x->regmap, IQS620_GLBL_EVENT_MASK,
iqs62x->dev_desc->ir_mask,
state ? 0 : 0xFF);
- if (!ret)
- iqs621_als->prox_en = state;
- return ret;
+ if (ret)
+ return ret;
+ iqs621_als->prox_en = state;
+
+ return 0;
default:
return -EINVAL;
--
2.51.0
next prev parent reply other threads:[~2026-04-29 1:38 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-29 1:29 [PATCH v3 0/2] iio: light: iqs621-als: use lock guards and prefer early error handling Pedro Barletta Gennari
2026-04-29 1:29 ` [PATCH v3 1/2] iio: light: iqs621-als: use lock guards Pedro Barletta Gennari
2026-04-29 1:29 ` Pedro Barletta Gennari [this message]
2026-04-29 20:01 ` [PATCH v3 0/2] iio: light: iqs621-als: use lock guards and prefer early error handling Andy Shevchenko
2026-05-05 16:35 ` Jonathan Cameron
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260429013640.26870-3-pedro.pbg@usp.br \
--to=pedro.pbg@usp.br \
--cc=andy@kernel.org \
--cc=dlechner@baylibre.com \
--cc=jic23@kernel.org \
--cc=linux-iio@vger.kernel.org \
--cc=nuno.sa@analog.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox