* [PATCH v4 0/8] iio: light: si1133: driver cleanup
@ 2026-04-30 15:04 Joshua Crofts via B4 Relay
2026-04-30 15:04 ` [PATCH v4 1/8] iio: light: si1133: reset counter to prevent race condition Joshua Crofts via B4 Relay
` (8 more replies)
0 siblings, 9 replies; 17+ messages in thread
From: Joshua Crofts via B4 Relay @ 2026-04-30 15:04 UTC (permalink / raw)
To: Jonathan Cameron, David Lechner, Nuno Sá, Andy Shevchenko
Cc: linux-iio, linux-kernel, Joshua Crofts, sashiko-bot,
Andy Shevchenko
This series deals with the cleanup and modernization of the Silicon
Labs SI1133 UV/Ambient light sensor.
What seemed like a simple checkpatch cleanup turned out to be more
complex, therefore I've ended up doing a patch series instead.
Changes include:
- adding missing headers
- removing unused macros
- adding guard(mutex)() support
- code style fixes
- race condition fixes reported by Sashiko
Signed-off-by: Joshua Crofts <joshua.crofts1@gmail.com>
---
Changes in v4:
- Changed logical ordering of patchset
- PATCH 1: fix typo in comment, edit commit message
- PATCH 2: edit commit message
- PATCH 3: edit commit message
- PATCH 5: remove irqreturn.h and add mod_devicetable.h
- Link to v3: https://lore.kernel.org/r/20260429-si1133-checkup-v3-0-469f21d960eb@gmail.com
Changes in v3:
- PATCH 6: add local variable for timeout
- PATCH 7 & 8: fix potential race conditions as pointed out by Sashiko
- Link to v2: https://lore.kernel.org/r/20260428-si1133-checkup-v2-0-70ad14bfefe2@gmail.com
Changes in v2:
- Change v2 to patch series
- PATCH 2: remove unused macros
- PATCH 3: add missing include headers
- PATCH 4: group generic <linux/*> headers
- PATCH 5: add guard(mutex)() support
- Link to v1: https://lore.kernel.org/r/20260427-si1133-checkup-v1-1-20f5f11eba6c@gmail.com
---
Joshua Crofts (8):
iio: light: si1133: reset counter to prevent race condition
iio: light: si1133: prevent race condition on timeout
iio: light: si1133: remove unused macros
iio: light: si1133: prefer complex macros enclosed in parenthesis
iio: light: si1133: add missing include headers
iio: light: si1133: group generic <linux/*> headers
iio: light: si1133: add local variable for timeout
iio: light: si1133: use guard(mutex)() macro
drivers/iio/light/si1133.c | 69 +++++++++++++++++++++++++++-------------------
1 file changed, 41 insertions(+), 28 deletions(-)
---
base-commit: d86db1905add39f905cf9f04252804b359914ed6
change-id: 20260427-si1133-checkup-abcc5280adf3
Best regards,
--
Joshua Crofts <joshua.crofts1@gmail.com>
^ permalink raw reply [flat|nested] 17+ messages in thread
* [PATCH v4 1/8] iio: light: si1133: reset counter to prevent race condition
2026-04-30 15:04 [PATCH v4 0/8] iio: light: si1133: driver cleanup Joshua Crofts via B4 Relay
@ 2026-04-30 15:04 ` Joshua Crofts via B4 Relay
2026-04-30 15:04 ` [PATCH v4 2/8] iio: light: si1133: prevent race condition on timeout Joshua Crofts via B4 Relay
` (7 subsequent siblings)
8 siblings, 0 replies; 17+ messages in thread
From: Joshua Crofts via B4 Relay @ 2026-04-30 15:04 UTC (permalink / raw)
To: Jonathan Cameron, David Lechner, Nuno Sá, Andy Shevchenko
Cc: linux-iio, linux-kernel, Joshua Crofts, sashiko-bot
From: Joshua Crofts <joshua.crofts1@gmail.com>
Sashiko reported a potential race condition happening when the driver
returns an errno after a timeout in the si1133_command() function. The
premature exit causes the hardware and software counters to become out
of sync by not updating data->rsp_seq, therefore the internal hardware
counter keeps incrementing.
Fix this by adding a call to si1133_cmd_reset_counter() before returning
from timeout.
Fixes: e01e7eaf37d8 ("iio: light: introduce si1133")
Reported-by: sashiko-bot <sashiko-bot@kernel.org>
Closes: https://sashiko.dev/#/message/20260428-si1133-checkup-v2-5-70ad14bfefe2%40gmail.com
Assisted-by: gemini:gemini-3.1-pro-preview
Signed-off-by: Joshua Crofts <joshua.crofts1@gmail.com>
---
drivers/iio/light/si1133.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/drivers/iio/light/si1133.c b/drivers/iio/light/si1133.c
index 44fa152dbd24c26c97cc778cbe641d92ecd56afa..c88c79202be2e21abb72067426e31b6bf97c61cf 100644
--- a/drivers/iio/light/si1133.c
+++ b/drivers/iio/light/si1133.c
@@ -427,6 +427,11 @@ static int si1133_command(struct si1133_data *data, u8 cmd)
dev_warn(dev,
"Failed to read command 0x%02x, ret=%d\n",
cmd, err);
+ /*
+ * Reset counter on err to prevent software and hardware
+ * counters being out of sync.
+ */
+ si1133_cmd_reset_counter(data);
goto out;
}
}
--
2.47.3
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [PATCH v4 2/8] iio: light: si1133: prevent race condition on timeout
2026-04-30 15:04 [PATCH v4 0/8] iio: light: si1133: driver cleanup Joshua Crofts via B4 Relay
2026-04-30 15:04 ` [PATCH v4 1/8] iio: light: si1133: reset counter to prevent race condition Joshua Crofts via B4 Relay
@ 2026-04-30 15:04 ` Joshua Crofts via B4 Relay
2026-04-30 15:04 ` [PATCH v4 3/8] iio: light: si1133: remove unused macros Joshua Crofts via B4 Relay
` (6 subsequent siblings)
8 siblings, 0 replies; 17+ messages in thread
From: Joshua Crofts via B4 Relay @ 2026-04-30 15:04 UTC (permalink / raw)
To: Jonathan Cameron, David Lechner, Nuno Sá, Andy Shevchenko
Cc: linux-iio, linux-kernel, Joshua Crofts, sashiko-bot
From: Joshua Crofts <joshua.crofts1@gmail.com>
Sashiko reported a bug where the si1133_command exits on timeout
without halting the sensor or masking the interrupt. If the sensor
completes the command later, any subsequent command to the sensor
will cause the IRQ handler to complete immediately, returning stale
data to the driver all while the command hasn't finished yet, shifting
all potential reads in the future.
Fix this by masking the IRQ if wait_for_completion_timeout() fails.
When initiating a new command, do a dummy read of the IRQ_STATUS
register and turn the IRQ back on.
Fixes: e01e7eaf37d8 ("iio: light: introduce si1133")
Reported-by: sashiko-bot <sashiko-bot@kernel.org>
Closes: https://sashiko.dev/#/message/20260428-si1133-checkup-v2-5-70ad14bfefe2%40gmail.com
Assisted-by: gemini:gemini-3.1-pro-preview
Signed-off-by: Joshua Crofts <joshua.crofts1@gmail.com>
---
drivers/iio/light/si1133.c | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)
diff --git a/drivers/iio/light/si1133.c b/drivers/iio/light/si1133.c
index c88c79202be2e21abb72067426e31b6bf97c61cf..bf7bf0f1631d49a1d04b89f172646e4afaf46438 100644
--- a/drivers/iio/light/si1133.c
+++ b/drivers/iio/light/si1133.c
@@ -395,8 +395,14 @@ static int si1133_command(struct si1133_data *data, u8 cmd)
expected_seq = (data->rsp_seq + 1) & SI1133_MAX_CMD_CTR;
- if (cmd == SI1133_CMD_FORCE)
+ if (cmd == SI1133_CMD_FORCE) {
+ /* Flush pending IRQs from a previous timeout. */
+ regmap_read(data->regmap, SI1133_REG_IRQ_STATUS, &resp);
+ regmap_write(data->regmap, SI1133_REG_IRQ_ENABLE,
+ SI1133_IRQ_CHANNEL_ENABLE);
+
reinit_completion(&data->completion);
+ }
err = regmap_write(data->regmap, SI1133_REG_COMMAND, cmd);
if (err) {
@@ -409,6 +415,7 @@ static int si1133_command(struct si1133_data *data, u8 cmd)
/* wait for irq */
if (!wait_for_completion_timeout(&data->completion,
msecs_to_jiffies(SI1133_COMPLETION_TIMEOUT_MS))) {
+ regmap_write(data->regmap, SI1133_REG_IRQ_ENABLE, 0);
err = -ETIMEDOUT;
goto out;
}
--
2.47.3
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [PATCH v4 3/8] iio: light: si1133: remove unused macros
2026-04-30 15:04 [PATCH v4 0/8] iio: light: si1133: driver cleanup Joshua Crofts via B4 Relay
2026-04-30 15:04 ` [PATCH v4 1/8] iio: light: si1133: reset counter to prevent race condition Joshua Crofts via B4 Relay
2026-04-30 15:04 ` [PATCH v4 2/8] iio: light: si1133: prevent race condition on timeout Joshua Crofts via B4 Relay
@ 2026-04-30 15:04 ` Joshua Crofts via B4 Relay
2026-05-04 8:49 ` Andy Shevchenko
2026-04-30 15:04 ` [PATCH v4 4/8] iio: light: si1133: prefer complex macros enclosed in parenthesis Joshua Crofts via B4 Relay
` (5 subsequent siblings)
8 siblings, 1 reply; 17+ messages in thread
From: Joshua Crofts via B4 Relay @ 2026-04-30 15:04 UTC (permalink / raw)
To: Jonathan Cameron, David Lechner, Nuno Sá, Andy Shevchenko
Cc: linux-iio, linux-kernel, Joshua Crofts, Andy Shevchenko
From: Joshua Crofts <joshua.crofts1@gmail.com>
Remove unused macros unrelated to hardware definition.
No functional change.
Suggested-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Joshua Crofts <joshua.crofts1@gmail.com>
---
drivers/iio/light/si1133.c | 4 ----
1 file changed, 4 deletions(-)
diff --git a/drivers/iio/light/si1133.c b/drivers/iio/light/si1133.c
index bf7bf0f1631d49a1d04b89f172646e4afaf46438..ed9b3e0a12d66d749f09f570de1ccdda2174b6ba 100644
--- a/drivers/iio/light/si1133.c
+++ b/drivers/iio/light/si1133.c
@@ -86,13 +86,9 @@
#define SI1133_CMD_MINSLEEP_US_LOW 5000
#define SI1133_CMD_MINSLEEP_US_HIGH 7500
#define SI1133_CMD_TIMEOUT_MS 25
-#define SI1133_CMD_LUX_TIMEOUT_MS 5000
-#define SI1133_CMD_TIMEOUT_US SI1133_CMD_TIMEOUT_MS * 1000
#define SI1133_REG_HOSTOUT(x) (x) + 0x13
-#define SI1133_MEASUREMENT_FREQUENCY 1250
-
#define SI1133_X_ORDER_MASK 0x0070
#define SI1133_Y_ORDER_MASK 0x0007
#define si1133_get_x_order(m) ((m) & SI1133_X_ORDER_MASK) >> 4
--
2.47.3
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [PATCH v4 4/8] iio: light: si1133: prefer complex macros enclosed in parenthesis
2026-04-30 15:04 [PATCH v4 0/8] iio: light: si1133: driver cleanup Joshua Crofts via B4 Relay
` (2 preceding siblings ...)
2026-04-30 15:04 ` [PATCH v4 3/8] iio: light: si1133: remove unused macros Joshua Crofts via B4 Relay
@ 2026-04-30 15:04 ` Joshua Crofts via B4 Relay
2026-04-30 15:04 ` [PATCH v4 5/8] iio: light: si1133: add missing include headers Joshua Crofts via B4 Relay
` (4 subsequent siblings)
8 siblings, 0 replies; 17+ messages in thread
From: Joshua Crofts via B4 Relay @ 2026-04-30 15:04 UTC (permalink / raw)
To: Jonathan Cameron, David Lechner, Nuno Sá, Andy Shevchenko
Cc: linux-iio, linux-kernel, Joshua Crofts
From: Joshua Crofts <joshua.crofts1@gmail.com>
Enclose complex macros in parenthesis per checkpatch.pl error to
improve code style.
Signed-off-by: Joshua Crofts <joshua.crofts1@gmail.com>
---
drivers/iio/light/si1133.c | 16 ++++++++--------
1 file changed, 8 insertions(+), 8 deletions(-)
diff --git a/drivers/iio/light/si1133.c b/drivers/iio/light/si1133.c
index ed9b3e0a12d66d749f09f570de1ccdda2174b6ba..9abc0a7e2ecf0d2fb1bd3af88eb675e9f1be4665 100644
--- a/drivers/iio/light/si1133.c
+++ b/drivers/iio/light/si1133.c
@@ -50,23 +50,23 @@
#define SI1133_MAX_CMD_CTR 0xF
#define SI1133_PARAM_REG_CHAN_LIST 0x01
-#define SI1133_PARAM_REG_ADCCONFIG(x) ((x) * 4) + 2
-#define SI1133_PARAM_REG_ADCSENS(x) ((x) * 4) + 3
-#define SI1133_PARAM_REG_ADCPOST(x) ((x) * 4) + 4
+#define SI1133_PARAM_REG_ADCCONFIG(x) (((x) * 4) + 2)
+#define SI1133_PARAM_REG_ADCSENS(x) (((x) * 4) + 3)
+#define SI1133_PARAM_REG_ADCPOST(x) (((x) * 4) + 4)
#define SI1133_ADCMUX_MASK 0x1F
-#define SI1133_ADCCONFIG_DECIM_RATE(x) (x) << 5
+#define SI1133_ADCCONFIG_DECIM_RATE(x) ((x) << 5)
#define SI1133_ADCSENS_SCALE_MASK 0x70
#define SI1133_ADCSENS_SCALE_SHIFT 4
#define SI1133_ADCSENS_HSIG_MASK BIT(7)
#define SI1133_ADCSENS_HSIG_SHIFT 7
#define SI1133_ADCSENS_HW_GAIN_MASK 0xF
-#define SI1133_ADCSENS_NB_MEAS(x) fls(x) << SI1133_ADCSENS_SCALE_SHIFT
+#define SI1133_ADCSENS_NB_MEAS(x) (fls(x) << SI1133_ADCSENS_SCALE_SHIFT)
#define SI1133_ADCPOST_24BIT_EN BIT(6)
-#define SI1133_ADCPOST_POSTSHIFT_BITQTY(x) (x & GENMASK(2, 0)) << 3
+#define SI1133_ADCPOST_POSTSHIFT_BITQTY(x) (((x) & GENMASK(2, 0)) << 3)
#define SI1133_PARAM_ADCMUX_SMALL_IR 0x0
#define SI1133_PARAM_ADCMUX_MED_IR 0x1
@@ -87,11 +87,11 @@
#define SI1133_CMD_MINSLEEP_US_HIGH 7500
#define SI1133_CMD_TIMEOUT_MS 25
-#define SI1133_REG_HOSTOUT(x) (x) + 0x13
+#define SI1133_REG_HOSTOUT(x) ((x) + 0x13)
#define SI1133_X_ORDER_MASK 0x0070
#define SI1133_Y_ORDER_MASK 0x0007
-#define si1133_get_x_order(m) ((m) & SI1133_X_ORDER_MASK) >> 4
+#define si1133_get_x_order(m) (((m) & SI1133_X_ORDER_MASK) >> 4)
#define si1133_get_y_order(m) ((m) & SI1133_Y_ORDER_MASK)
#define SI1133_LUX_ADC_MASK 0xE
--
2.47.3
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [PATCH v4 5/8] iio: light: si1133: add missing include headers
2026-04-30 15:04 [PATCH v4 0/8] iio: light: si1133: driver cleanup Joshua Crofts via B4 Relay
` (3 preceding siblings ...)
2026-04-30 15:04 ` [PATCH v4 4/8] iio: light: si1133: prefer complex macros enclosed in parenthesis Joshua Crofts via B4 Relay
@ 2026-04-30 15:04 ` Joshua Crofts via B4 Relay
2026-04-30 19:42 ` Joshua Crofts
2026-04-30 15:04 ` [PATCH v4 6/8] iio: light: si1133: group generic <linux/*> headers Joshua Crofts via B4 Relay
` (3 subsequent siblings)
8 siblings, 1 reply; 17+ messages in thread
From: Joshua Crofts via B4 Relay @ 2026-04-30 15:04 UTC (permalink / raw)
To: Jonathan Cameron, David Lechner, Nuno Sá, Andy Shevchenko
Cc: linux-iio, linux-kernel, Joshua Crofts
From: Joshua Crofts <joshua.crofts1@gmail.com>
Add missing include headers to prevent compilation relying on transient
dependencies (array_size.h, bitops.h, completion.h, dev_printk.h, err.h,
irqreturn.h, jiffies.h, math.h, mutex.h, types.h).
Signed-off-by: Joshua Crofts <joshua.crofts1@gmail.com>
---
drivers/iio/light/si1133.c | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/drivers/iio/light/si1133.c b/drivers/iio/light/si1133.c
index 9abc0a7e2ecf0d2fb1bd3af88eb675e9f1be4665..ab66a5a9ffb4a89bbba7474b6e984ddb61cfeebe 100644
--- a/drivers/iio/light/si1133.c
+++ b/drivers/iio/light/si1133.c
@@ -6,11 +6,21 @@
* Copyright 2018 Maxime Roussin-Belanger <maxime.roussinbelanger@gmail.com>
*/
+#include <linux/array_size.h>
+#include <linux/bitops.h>
+#include <linux/completion.h>
#include <linux/delay.h>
+#include <linux/dev_printk.h>
+#include <linux/err.h>
#include <linux/i2c.h>
#include <linux/interrupt.h>
+#include <linux/jiffies.h>
+#include <linux/math.h>
+#include <linux/mod_devicetable.h>
#include <linux/module.h>
+#include <linux/mutex.h>
#include <linux/regmap.h>
+#include <linux/types.h>
#include <linux/iio/iio.h>
#include <linux/iio/sysfs.h>
--
2.47.3
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [PATCH v4 6/8] iio: light: si1133: group generic <linux/*> headers
2026-04-30 15:04 [PATCH v4 0/8] iio: light: si1133: driver cleanup Joshua Crofts via B4 Relay
` (4 preceding siblings ...)
2026-04-30 15:04 ` [PATCH v4 5/8] iio: light: si1133: add missing include headers Joshua Crofts via B4 Relay
@ 2026-04-30 15:04 ` Joshua Crofts via B4 Relay
2026-04-30 15:04 ` [PATCH v4 7/8] iio: light: si1133: add local variable for timeout Joshua Crofts via B4 Relay
` (2 subsequent siblings)
8 siblings, 0 replies; 17+ messages in thread
From: Joshua Crofts via B4 Relay @ 2026-04-30 15:04 UTC (permalink / raw)
To: Jonathan Cameron, David Lechner, Nuno Sá, Andy Shevchenko
Cc: linux-iio, linux-kernel, Joshua Crofts
From: Joshua Crofts <joshua.crofts1@gmail.com>
Group generic <linux/*> include headers to improve code style.
No functional change.
Signed-off-by: Joshua Crofts <joshua.crofts1@gmail.com>
---
drivers/iio/light/si1133.c | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)
diff --git a/drivers/iio/light/si1133.c b/drivers/iio/light/si1133.c
index ab66a5a9ffb4a89bbba7474b6e984ddb61cfeebe..fdffdee16e493277d95c369ec2f6c0678cf9f61c 100644
--- a/drivers/iio/light/si1133.c
+++ b/drivers/iio/light/si1133.c
@@ -21,14 +21,12 @@
#include <linux/mutex.h>
#include <linux/regmap.h>
#include <linux/types.h>
+#include <linux/unaligned.h>
+#include <linux/util_macros.h>
#include <linux/iio/iio.h>
#include <linux/iio/sysfs.h>
-#include <linux/util_macros.h>
-
-#include <linux/unaligned.h>
-
#define SI1133_REG_PART_ID 0x00
#define SI1133_REG_REV_ID 0x01
#define SI1133_REG_MFR_ID 0x02
--
2.47.3
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [PATCH v4 7/8] iio: light: si1133: add local variable for timeout
2026-04-30 15:04 [PATCH v4 0/8] iio: light: si1133: driver cleanup Joshua Crofts via B4 Relay
` (5 preceding siblings ...)
2026-04-30 15:04 ` [PATCH v4 6/8] iio: light: si1133: group generic <linux/*> headers Joshua Crofts via B4 Relay
@ 2026-04-30 15:04 ` Joshua Crofts via B4 Relay
2026-05-04 8:53 ` Andy Shevchenko
2026-04-30 15:04 ` [PATCH v4 8/8] iio: light: si1133: use guard(mutex)() macro Joshua Crofts via B4 Relay
2026-05-04 8:55 ` [PATCH v4 0/8] iio: light: si1133: driver cleanup Andy Shevchenko
8 siblings, 1 reply; 17+ messages in thread
From: Joshua Crofts via B4 Relay @ 2026-04-30 15:04 UTC (permalink / raw)
To: Jonathan Cameron, David Lechner, Nuno Sá, Andy Shevchenko
Cc: linux-iio, linux-kernel, Joshua Crofts
From: Joshua Crofts <joshua.crofts1@gmail.com>
Add local variable for timeout to improve readability.
No functional change.
Suggested-by: Jonathan Cameron <jic23@kernel.org>
Signed-off-by: Joshua Crofts <joshua.crofts1@gmail.com>
---
drivers/iio/light/si1133.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/iio/light/si1133.c b/drivers/iio/light/si1133.c
index fdffdee16e493277d95c369ec2f6c0678cf9f61c..a3e4ab25acdc105d3800994f4391a7e4291e1c74 100644
--- a/drivers/iio/light/si1133.c
+++ b/drivers/iio/light/si1133.c
@@ -390,6 +390,7 @@ static int si1133_cmd_reset_counter(struct si1133_data *data)
static int si1133_command(struct si1133_data *data, u8 cmd)
{
+ unsigned long timeout = msecs_to_jiffies(SI1133_COMPLETION_TIMEOUT_MS);
struct device *dev = &data->client->dev;
u32 resp;
int err;
@@ -417,8 +418,7 @@ static int si1133_command(struct si1133_data *data, u8 cmd)
if (cmd == SI1133_CMD_FORCE) {
/* wait for irq */
- if (!wait_for_completion_timeout(&data->completion,
- msecs_to_jiffies(SI1133_COMPLETION_TIMEOUT_MS))) {
+ if (!wait_for_completion_timeout(&data->completion, timeout)) {
regmap_write(data->regmap, SI1133_REG_IRQ_ENABLE, 0);
err = -ETIMEDOUT;
goto out;
--
2.47.3
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [PATCH v4 8/8] iio: light: si1133: use guard(mutex)() macro
2026-04-30 15:04 [PATCH v4 0/8] iio: light: si1133: driver cleanup Joshua Crofts via B4 Relay
` (6 preceding siblings ...)
2026-04-30 15:04 ` [PATCH v4 7/8] iio: light: si1133: add local variable for timeout Joshua Crofts via B4 Relay
@ 2026-04-30 15:04 ` Joshua Crofts via B4 Relay
2026-05-04 8:55 ` [PATCH v4 0/8] iio: light: si1133: driver cleanup Andy Shevchenko
8 siblings, 0 replies; 17+ messages in thread
From: Joshua Crofts via B4 Relay @ 2026-04-30 15:04 UTC (permalink / raw)
To: Jonathan Cameron, David Lechner, Nuno Sá, Andy Shevchenko
Cc: linux-iio, linux-kernel, Joshua Crofts
From: Joshua Crofts <joshua.crofts1@gmail.com>
Remove mutex_lock()/mutex_unlock() and goto instances and add
guard(mutex)() macro to modernize driver and improve mutex handling.
Signed-off-by: Joshua Crofts <joshua.crofts1@gmail.com>
---
drivers/iio/light/si1133.c | 15 ++++++---------
1 file changed, 6 insertions(+), 9 deletions(-)
diff --git a/drivers/iio/light/si1133.c b/drivers/iio/light/si1133.c
index a3e4ab25acdc105d3800994f4391a7e4291e1c74..55660dccfc7956e77b1d8105b7261221176c1736 100644
--- a/drivers/iio/light/si1133.c
+++ b/drivers/iio/light/si1133.c
@@ -8,6 +8,7 @@
#include <linux/array_size.h>
#include <linux/bitops.h>
+#include <linux/cleanup.h>
#include <linux/completion.h>
#include <linux/delay.h>
#include <linux/dev_printk.h>
@@ -396,7 +397,7 @@ static int si1133_command(struct si1133_data *data, u8 cmd)
int err;
int expected_seq;
- mutex_lock(&data->mutex);
+ guard(mutex)(&data->mutex);
expected_seq = (data->rsp_seq + 1) & SI1133_MAX_CMD_CTR;
@@ -413,19 +414,18 @@ static int si1133_command(struct si1133_data *data, u8 cmd)
if (err) {
dev_warn(dev, "Failed to write command 0x%02x, ret=%d\n", cmd,
err);
- goto out;
+ return err;
}
if (cmd == SI1133_CMD_FORCE) {
/* wait for irq */
if (!wait_for_completion_timeout(&data->completion, timeout)) {
regmap_write(data->regmap, SI1133_REG_IRQ_ENABLE, 0);
- err = -ETIMEDOUT;
- goto out;
+ return -ETIMEDOUT;
}
err = regmap_read(data->regmap, SI1133_REG_RESPONSE0, &resp);
if (err)
- goto out;
+ return err;
} else {
err = regmap_read_poll_timeout(data->regmap,
SI1133_REG_RESPONSE0, resp,
@@ -443,7 +443,7 @@ static int si1133_command(struct si1133_data *data, u8 cmd)
* counters being out of sync.
*/
si1133_cmd_reset_counter(data);
- goto out;
+ return err;
}
}
@@ -454,9 +454,6 @@ static int si1133_command(struct si1133_data *data, u8 cmd)
data->rsp_seq = expected_seq;
}
-out:
- mutex_unlock(&data->mutex);
-
return err;
}
--
2.47.3
^ permalink raw reply related [flat|nested] 17+ messages in thread
* Re: [PATCH v4 5/8] iio: light: si1133: add missing include headers
2026-04-30 15:04 ` [PATCH v4 5/8] iio: light: si1133: add missing include headers Joshua Crofts via B4 Relay
@ 2026-04-30 19:42 ` Joshua Crofts
0 siblings, 0 replies; 17+ messages in thread
From: Joshua Crofts @ 2026-04-30 19:42 UTC (permalink / raw)
To: joshua.crofts1
Cc: Jonathan Cameron, David Lechner, Nuno Sá, Andy Shevchenko,
linux-iio, linux-kernel
On Thu, 30 Apr 2026 at 17:05, Joshua Crofts via B4 Relay
<devnull+joshua.crofts1.gmail.com@kernel.org> wrote:
>
> From: Joshua Crofts <joshua.crofts1@gmail.com>
>
> Add missing include headers to prevent compilation relying on transient
> dependencies (array_size.h, bitops.h, completion.h, dev_printk.h, err.h,
> irqreturn.h, jiffies.h, math.h, mutex.h, types.h).
>
Minor issue - I forgot to remove irqreturn.h from the commit message and
add mod_devicetable.h.
--
Kind regards
CJD
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH v4 3/8] iio: light: si1133: remove unused macros
2026-04-30 15:04 ` [PATCH v4 3/8] iio: light: si1133: remove unused macros Joshua Crofts via B4 Relay
@ 2026-05-04 8:49 ` Andy Shevchenko
0 siblings, 0 replies; 17+ messages in thread
From: Andy Shevchenko @ 2026-05-04 8:49 UTC (permalink / raw)
To: joshua.crofts1
Cc: Jonathan Cameron, David Lechner, Nuno Sá, Andy Shevchenko,
linux-iio, linux-kernel
On Thu, Apr 30, 2026 at 05:04:23PM +0200, Joshua Crofts via B4 Relay wrote:
> Remove unused macros unrelated to hardware definition.
>
> No functional change.
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH v4 7/8] iio: light: si1133: add local variable for timeout
2026-04-30 15:04 ` [PATCH v4 7/8] iio: light: si1133: add local variable for timeout Joshua Crofts via B4 Relay
@ 2026-05-04 8:53 ` Andy Shevchenko
2026-05-04 8:59 ` Joshua Crofts
0 siblings, 1 reply; 17+ messages in thread
From: Andy Shevchenko @ 2026-05-04 8:53 UTC (permalink / raw)
To: joshua.crofts1
Cc: Jonathan Cameron, David Lechner, Nuno Sá, Andy Shevchenko,
linux-iio, linux-kernel
On Thu, Apr 30, 2026 at 05:04:27PM +0200, Joshua Crofts via B4 Relay wrote:
> Add local variable for timeout to improve readability.
>
> No functional change.
Hmm... I am not sure about this as previously it was one jump and now two jumps
over the code to get the actual value of the timeout. OTOH, I don't care much
in this case.
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH v4 0/8] iio: light: si1133: driver cleanup
2026-04-30 15:04 [PATCH v4 0/8] iio: light: si1133: driver cleanup Joshua Crofts via B4 Relay
` (7 preceding siblings ...)
2026-04-30 15:04 ` [PATCH v4 8/8] iio: light: si1133: use guard(mutex)() macro Joshua Crofts via B4 Relay
@ 2026-05-04 8:55 ` Andy Shevchenko
2026-05-04 9:09 ` Joshua Crofts
8 siblings, 1 reply; 17+ messages in thread
From: Andy Shevchenko @ 2026-05-04 8:55 UTC (permalink / raw)
To: joshua.crofts1
Cc: Jonathan Cameron, David Lechner, Nuno Sá, Andy Shevchenko,
linux-iio, linux-kernel, sashiko-bot
On Thu, Apr 30, 2026 at 05:04:20PM +0200, Joshua Crofts via B4 Relay wrote:
> This series deals with the cleanup and modernization of the Silicon
> Labs SI1133 UV/Ambient light sensor.
>
> What seemed like a simple checkpatch cleanup turned out to be more
> complex, therefore I've ended up doing a patch series instead.
>
> Changes include:
> - adding missing headers
> - removing unused macros
> - adding guard(mutex)() support
> - code style fixes
> - race condition fixes reported by Sashiko
I'm not sure about patches 1 & 2 without testing on HW (the reports sound good
and fixes look reasonable, but it might be some behaviour that relies on a
[buggy] implementation). Also not sure about patch 7, however don't care much.
For the rest feel free to add
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH v4 7/8] iio: light: si1133: add local variable for timeout
2026-05-04 8:53 ` Andy Shevchenko
@ 2026-05-04 8:59 ` Joshua Crofts
2026-05-04 9:03 ` Andy Shevchenko
0 siblings, 1 reply; 17+ messages in thread
From: Joshua Crofts @ 2026-05-04 8:59 UTC (permalink / raw)
To: Andy Shevchenko
Cc: Jonathan Cameron, David Lechner, Nuno Sá, Andy Shevchenko,
linux-iio, linux-kernel
On Mon, 4 May 2026 at 10:53, Andy Shevchenko
<andriy.shevchenko@intel.com> wrote:
>
> On Thu, Apr 30, 2026 at 05:04:27PM +0200, Joshua Crofts via B4 Relay wrote:
>
> > Add local variable for timeout to improve readability.
> >
> > No functional change.
>
> Hmm... I am not sure about this as previously it was one jump and now two jumps
> over the code to get the actual value of the timeout. OTOH, I don't care much
> in this case.
>
This was actually a suggestion by Jonathan, as the original indentation
of the function parameters was horrible, so it was better to just add it as
a variable to improve readability. Perhaps I should've added a suggested-by tag.
--
Kind regards
CJD
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH v4 7/8] iio: light: si1133: add local variable for timeout
2026-05-04 8:59 ` Joshua Crofts
@ 2026-05-04 9:03 ` Andy Shevchenko
2026-05-05 12:25 ` Jonathan Cameron
0 siblings, 1 reply; 17+ messages in thread
From: Andy Shevchenko @ 2026-05-04 9:03 UTC (permalink / raw)
To: Joshua Crofts
Cc: Jonathan Cameron, David Lechner, Nuno Sá, Andy Shevchenko,
linux-iio, linux-kernel
On Mon, May 04, 2026 at 10:59:21AM +0200, Joshua Crofts wrote:
> On Mon, 4 May 2026 at 10:53, Andy Shevchenko
> <andriy.shevchenko@intel.com> wrote:
> > On Thu, Apr 30, 2026 at 05:04:27PM +0200, Joshua Crofts via B4 Relay wrote:
> >
> > > Add local variable for timeout to improve readability.
> > >
> > > No functional change.
> >
> > Hmm... I am not sure about this as previously it was one jump and now two jumps
> > over the code to get the actual value of the timeout. OTOH, I don't care much
> > in this case.
>
> This was actually a suggestion by Jonathan, as the original indentation
> of the function parameters was horrible, so it was better to just add it as
> a variable to improve readability. Perhaps I should've added a suggested-by tag.
You added it, and I have seen that. Still my opinion stays. Of course, it's up to
Jonathan to make the final decision.
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH v4 0/8] iio: light: si1133: driver cleanup
2026-05-04 8:55 ` [PATCH v4 0/8] iio: light: si1133: driver cleanup Andy Shevchenko
@ 2026-05-04 9:09 ` Joshua Crofts
0 siblings, 0 replies; 17+ messages in thread
From: Joshua Crofts @ 2026-05-04 9:09 UTC (permalink / raw)
To: Andy Shevchenko
Cc: Jonathan Cameron, David Lechner, Nuno Sá, Andy Shevchenko,
linux-iio, linux-kernel, sashiko-bot
On Mon, 4 May 2026 at 10:55, Andy Shevchenko
<andriy.shevchenko@linux.intel.com> wrote:
>
> On Thu, Apr 30, 2026 at 05:04:20PM +0200, Joshua Crofts via B4 Relay wrote:
> > This series deals with the cleanup and modernization of the Silicon
> > Labs SI1133 UV/Ambient light sensor.
> >
> > What seemed like a simple checkpatch cleanup turned out to be more
> > complex, therefore I've ended up doing a patch series instead.
> >
> > Changes include:
> > - adding missing headers
> > - removing unused macros
> > - adding guard(mutex)() support
> > - code style fixes
> > - race condition fixes reported by Sashiko
>
> I'm not sure about patches 1 & 2 without testing on HW (the reports sound good
> and fixes look reasonable, but it might be some behaviour that relies on a
> [buggy] implementation). Also not sure about patch 7, however don't care much.
> For the rest feel free to add
> Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Hmm, yes, it would be better to test it on HW, too bad the chip is obsolete...
--
Kind regards
CJD
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH v4 7/8] iio: light: si1133: add local variable for timeout
2026-05-04 9:03 ` Andy Shevchenko
@ 2026-05-05 12:25 ` Jonathan Cameron
0 siblings, 0 replies; 17+ messages in thread
From: Jonathan Cameron @ 2026-05-05 12:25 UTC (permalink / raw)
To: Andy Shevchenko
Cc: Joshua Crofts, David Lechner, Nuno Sá, Andy Shevchenko,
linux-iio, linux-kernel
On Mon, 4 May 2026 12:03:08 +0300
Andy Shevchenko <andriy.shevchenko@intel.com> wrote:
> On Mon, May 04, 2026 at 10:59:21AM +0200, Joshua Crofts wrote:
> > On Mon, 4 May 2026 at 10:53, Andy Shevchenko
> > <andriy.shevchenko@intel.com> wrote:
> > > On Thu, Apr 30, 2026 at 05:04:27PM +0200, Joshua Crofts via B4 Relay wrote:
> > >
> > > > Add local variable for timeout to improve readability.
> > > >
> > > > No functional change.
> > >
> > > Hmm... I am not sure about this as previously it was one jump and now two jumps
> > > over the code to get the actual value of the timeout. OTOH, I don't care much
> > > in this case.
> >
> > This was actually a suggestion by Jonathan, as the original indentation
> > of the function parameters was horrible, so it was better to just add it as
> > a variable to improve readability. Perhaps I should've added a suggested-by tag.
>
> You added it, and I have seen that. Still my opinion stays. Of course, it's up to
> Jonathan to make the final decision.
>
No need to assign the value at declaration. If that's right next to the use
then I think everyone is happy.
^ permalink raw reply [flat|nested] 17+ messages in thread
end of thread, other threads:[~2026-05-05 12:25 UTC | newest]
Thread overview: 17+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-30 15:04 [PATCH v4 0/8] iio: light: si1133: driver cleanup Joshua Crofts via B4 Relay
2026-04-30 15:04 ` [PATCH v4 1/8] iio: light: si1133: reset counter to prevent race condition Joshua Crofts via B4 Relay
2026-04-30 15:04 ` [PATCH v4 2/8] iio: light: si1133: prevent race condition on timeout Joshua Crofts via B4 Relay
2026-04-30 15:04 ` [PATCH v4 3/8] iio: light: si1133: remove unused macros Joshua Crofts via B4 Relay
2026-05-04 8:49 ` Andy Shevchenko
2026-04-30 15:04 ` [PATCH v4 4/8] iio: light: si1133: prefer complex macros enclosed in parenthesis Joshua Crofts via B4 Relay
2026-04-30 15:04 ` [PATCH v4 5/8] iio: light: si1133: add missing include headers Joshua Crofts via B4 Relay
2026-04-30 19:42 ` Joshua Crofts
2026-04-30 15:04 ` [PATCH v4 6/8] iio: light: si1133: group generic <linux/*> headers Joshua Crofts via B4 Relay
2026-04-30 15:04 ` [PATCH v4 7/8] iio: light: si1133: add local variable for timeout Joshua Crofts via B4 Relay
2026-05-04 8:53 ` Andy Shevchenko
2026-05-04 8:59 ` Joshua Crofts
2026-05-04 9:03 ` Andy Shevchenko
2026-05-05 12:25 ` Jonathan Cameron
2026-04-30 15:04 ` [PATCH v4 8/8] iio: light: si1133: use guard(mutex)() macro Joshua Crofts via B4 Relay
2026-05-04 8:55 ` [PATCH v4 0/8] iio: light: si1133: driver cleanup Andy Shevchenko
2026-05-04 9:09 ` Joshua Crofts
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox