Linux IIO development
 help / color / mirror / Atom feed
* [PATCH v2 00/10] iio: light: opt3001: driver cleanup
@ 2026-05-12 10:57 Joshua Crofts via B4 Relay
  2026-05-12 10:57 ` [PATCH v2 01/10] iio: light: opt3001: move device registration to end of probe() Joshua Crofts via B4 Relay
                   ` (9 more replies)
  0 siblings, 10 replies; 18+ messages in thread
From: Joshua Crofts via B4 Relay @ 2026-05-12 10:57 UTC (permalink / raw)
  To: Jonathan Cameron, David Lechner, Nuno Sá, Andy Shevchenko,
	Alexander Koch, Michael Hornung
  Cc: linux-iio, linux-kernel, Joshua Crofts, Sashiko, Andy Shevchenko,
	Andy Shevchenko

This series deals with cleaning up the TI OPT3001 sensor driver,
moving it to more modern kernel practices and improving the code style.

While reviewing, Jonathan Cameron (and eventually Sashiko) found a race
condition where userspace could start interacting with the device
before the hardware IRQ was set up.

Changes include:
- moving the driver to use devm_* functions
- IWYU cleanups
- removal of unnecessary macros and comments
- using dev_err_probe() in probe and probe path functions
- checkpatch.pl warning cleanups
- fixing a race condition found in opt3001_probe() function

Signed-off-by: Joshua Crofts <joshua.crofts1@gmail.com>
---
Changes in v2:
- PATCH 1: added patch that fixes race condition
- PATCH 3: remove wrong usage of GENMASK()
- PATCH 4: add patch that moves driver to use local structs
- PATCH 5: add patch that ensures correct parenthesis alignment
- PATCH 6: change int to unsigned int
- PATCH 7: moved opt3001_read_id() function to use dev_err_probe()
- PATCH 9: removed unnecessary dev_err_probe() calls, reordering
- PATCH 10: added patch that adds a comment to mutex declaration
- Link to v1: https://lore.kernel.org/r/20260511-opt3001-cleanup-v1-0-f7879dc3455c@gmail.com

---
Joshua Crofts (10):
      iio: light: opt3001: move device registration to end of probe()
      iio: light: opt3001: make headers conform to iwyu
      iio: light: opt3001: use macros from bits.h header
      iio: light: opt3001: use local struct device and i2c_client variables
      iio: light: opt3001: ensure correct parenthesis alignment
      iio: light: opt3001: localize for loop iterator
      iio: light: opt3001: prefer dev_err_probe()
      iio: light: opt3001: move driver to guard(mutex)() use
      iio: light: opt3001: switch driver to managed resources
      iio: light: opt3001: add comment to mutex

 drivers/iio/light/opt3001.c | 397 +++++++++++++++++++++-----------------------
 1 file changed, 190 insertions(+), 207 deletions(-)
---
base-commit: 74d173f29572951629d1e0b7456b424006e51b87
change-id: 20260511-opt3001-cleanup-c1411de14392

Best regards,
-- 
Joshua Crofts <joshua.crofts1@gmail.com>



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

* [PATCH v2 01/10] iio: light: opt3001: move device registration to end of probe()
  2026-05-12 10:57 [PATCH v2 00/10] iio: light: opt3001: driver cleanup Joshua Crofts via B4 Relay
@ 2026-05-12 10:57 ` Joshua Crofts via B4 Relay
  2026-05-12 10:57 ` [PATCH v2 02/10] iio: light: opt3001: make headers conform to iwyu Joshua Crofts via B4 Relay
                   ` (8 subsequent siblings)
  9 siblings, 0 replies; 18+ messages in thread
From: Joshua Crofts via B4 Relay @ 2026-05-12 10:57 UTC (permalink / raw)
  To: Jonathan Cameron, David Lechner, Nuno Sá, Andy Shevchenko,
	Alexander Koch, Michael Hornung
  Cc: linux-iio, linux-kernel, Joshua Crofts, Sashiko

From: Joshua Crofts <joshua.crofts1@gmail.com>

Move devm_iio_device_register() to end of the opt3001_probe() function
to prevent a race condition where userspace could interact with the
device before the hardware IRQ was set up.

Fixes: ac663db3678a ("iio: light: opt3001: enable operation w/o IRQ")
Reported-by: Jonathan Cameron <jic23@kernel.org>
Reported-by: Sashiko <sashiko-bot@kernel.org>
Closes: https://sashiko.dev/#/patchset/20260511-opt3001-cleanup-v1-0-f7879dc3455c%40gmail.com?part=7
Signed-off-by: Joshua Crofts <joshua.crofts1@gmail.com>
---
 drivers/iio/light/opt3001.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)

diff --git a/drivers/iio/light/opt3001.c b/drivers/iio/light/opt3001.c
index 53bc455b7bad142695d9fecc6cabb934fb3ace0c..3c79e0c4ca32fedf33e318d047d6ab3f62b6c03b 100644
--- a/drivers/iio/light/opt3001.c
+++ b/drivers/iio/light/opt3001.c
@@ -874,12 +874,6 @@ static int opt3001_probe(struct i2c_client *client)
 	iio->modes = INDIO_DIRECT_MODE;
 	iio->info = &opt3001_info;
 
-	ret = devm_iio_device_register(dev, iio);
-	if (ret) {
-		dev_err(dev, "failed to register IIO device\n");
-		return ret;
-	}
-
 	/* Make use of INT pin only if valid IRQ no. is given */
 	if (irq > 0) {
 		ret = request_threaded_irq(irq, NULL, opt3001_irq,
@@ -894,6 +888,10 @@ static int opt3001_probe(struct i2c_client *client)
 		dev_dbg(opt->dev, "enabling interrupt-less operation\n");
 	}
 
+	ret = devm_iio_device_register(dev, iio);
+	if (ret)
+		return dev_err(dev, "failed to register IIO device\n");
+
 	return 0;
 }
 

-- 
2.47.3



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

* [PATCH v2 02/10] iio: light: opt3001: make headers conform to iwyu
  2026-05-12 10:57 [PATCH v2 00/10] iio: light: opt3001: driver cleanup Joshua Crofts via B4 Relay
  2026-05-12 10:57 ` [PATCH v2 01/10] iio: light: opt3001: move device registration to end of probe() Joshua Crofts via B4 Relay
@ 2026-05-12 10:57 ` Joshua Crofts via B4 Relay
  2026-05-12 10:57 ` [PATCH v2 03/10] iio: light: opt3001: use macros from bits.h header Joshua Crofts via B4 Relay
                   ` (7 subsequent siblings)
  9 siblings, 0 replies; 18+ messages in thread
From: Joshua Crofts via B4 Relay @ 2026-05-12 10:57 UTC (permalink / raw)
  To: Jonathan Cameron, David Lechner, Nuno Sá, Andy Shevchenko,
	Alexander Koch, Michael Hornung
  Cc: linux-iio, linux-kernel, Joshua Crofts

From: Joshua Crofts <joshua.crofts1@gmail.com>

Remove kernel.h proxy header, device.h, irq.h, slab.h as they are
unnecessary and add missing headers (array_size.h, dev_printk.h,
errno.h, jiffies.h, wait.h) to enforce IWYU principle and reduce
transitive dependencies. Also, replace bitops.h with bits.h as only
the BIT() macro is used.

Signed-off-by: Joshua Crofts <joshua.crofts1@gmail.com>
---
 drivers/iio/light/opt3001.c | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/drivers/iio/light/opt3001.c b/drivers/iio/light/opt3001.c
index 3c79e0c4ca32fedf33e318d047d6ab3f62b6c03b..7efd92875c3f8c86b00a8aff8fab664457399983 100644
--- a/drivers/iio/light/opt3001.c
+++ b/drivers/iio/light/opt3001.c
@@ -8,18 +8,19 @@
  * Based on previous work from: Felipe Balbi <balbi@ti.com>
  */
 
-#include <linux/bitops.h>
+#include <linux/array_size.h>
+#include <linux/bits.h>
 #include <linux/delay.h>
-#include <linux/device.h>
+#include <linux/dev_printk.h>
+#include <linux/errno.h>
 #include <linux/i2c.h>
 #include <linux/interrupt.h>
-#include <linux/irq.h>
-#include <linux/kernel.h>
-#include <linux/module.h>
+#include <linux/jiffies.h>
 #include <linux/mod_devicetable.h>
+#include <linux/module.h>
 #include <linux/mutex.h>
-#include <linux/slab.h>
 #include <linux/types.h>
+#include <linux/wait.h>
 
 #include <linux/iio/events.h>
 #include <linux/iio/iio.h>

-- 
2.47.3



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

* [PATCH v2 03/10] iio: light: opt3001: use macros from bits.h header
  2026-05-12 10:57 [PATCH v2 00/10] iio: light: opt3001: driver cleanup Joshua Crofts via B4 Relay
  2026-05-12 10:57 ` [PATCH v2 01/10] iio: light: opt3001: move device registration to end of probe() Joshua Crofts via B4 Relay
  2026-05-12 10:57 ` [PATCH v2 02/10] iio: light: opt3001: make headers conform to iwyu Joshua Crofts via B4 Relay
@ 2026-05-12 10:57 ` Joshua Crofts via B4 Relay
  2026-05-12 10:57 ` [PATCH v2 04/10] iio: light: opt3001: use local struct device and i2c_client variables Joshua Crofts via B4 Relay
                   ` (6 subsequent siblings)
  9 siblings, 0 replies; 18+ messages in thread
From: Joshua Crofts via B4 Relay @ 2026-05-12 10:57 UTC (permalink / raw)
  To: Jonathan Cameron, David Lechner, Nuno Sá, Andy Shevchenko,
	Alexander Koch, Michael Hornung
  Cc: linux-iio, linux-kernel, Joshua Crofts

From: Joshua Crofts <joshua.crofts1@gmail.com>

Use GENMASK() and BIT() macros from bits.h header where it makes
sense. While at it, remove unused macro.

No functional change.

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

diff --git a/drivers/iio/light/opt3001.c b/drivers/iio/light/opt3001.c
index 7efd92875c3f8c86b00a8aff8fab664457399983..6ce1a2d7647a3b9cd8964a276878630d31f61794 100644
--- a/drivers/iio/light/opt3001.c
+++ b/drivers/iio/light/opt3001.c
@@ -33,17 +33,16 @@
 #define OPT3001_MANUFACTURER_ID	0x7e
 #define OPT3001_DEVICE_ID	0x7f
 
-#define OPT3001_CONFIGURATION_RN_MASK	(0xf << 12)
+#define OPT3001_CONFIGURATION_RN_MASK	GENMASK(15, 12)
 #define OPT3001_CONFIGURATION_RN_AUTO	(0xc << 12)
 
 #define OPT3001_CONFIGURATION_CT	BIT(11)
 
-#define OPT3001_CONFIGURATION_M_MASK	(3 << 9)
+#define OPT3001_CONFIGURATION_M_MASK	GENMASK(10, 9)
 #define OPT3001_CONFIGURATION_M_SHUTDOWN (0 << 9)
 #define OPT3001_CONFIGURATION_M_SINGLE	(1 << 9)
 #define OPT3001_CONFIGURATION_M_CONTINUOUS (2 << 9) /* also 3 << 9 */
 
-#define OPT3001_CONFIGURATION_OVF	BIT(8)
 #define OPT3001_CONFIGURATION_CRF	BIT(7)
 #define OPT3001_CONFIGURATION_FH	BIT(6)
 #define OPT3001_CONFIGURATION_FL	BIT(5)
@@ -51,7 +50,7 @@
 #define OPT3001_CONFIGURATION_POL	BIT(3)
 #define OPT3001_CONFIGURATION_ME	BIT(2)
 
-#define OPT3001_CONFIGURATION_FC_MASK	(3 << 0)
+#define OPT3001_CONFIGURATION_FC_MASK	GENMASK(1, 0)
 
 /* The end-of-conversion enable is located in the low-limit register */
 #define OPT3001_LOW_LIMIT_EOC_ENABLE	0xc000

-- 
2.47.3



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

* [PATCH v2 04/10] iio: light: opt3001: use local struct device and i2c_client variables
  2026-05-12 10:57 [PATCH v2 00/10] iio: light: opt3001: driver cleanup Joshua Crofts via B4 Relay
                   ` (2 preceding siblings ...)
  2026-05-12 10:57 ` [PATCH v2 03/10] iio: light: opt3001: use macros from bits.h header Joshua Crofts via B4 Relay
@ 2026-05-12 10:57 ` Joshua Crofts via B4 Relay
  2026-05-12 11:09   ` Andy Shevchenko
  2026-05-12 10:57 ` [PATCH v2 05/10] iio: light: opt3001: ensure correct parenthesis alignment Joshua Crofts via B4 Relay
                   ` (5 subsequent siblings)
  9 siblings, 1 reply; 18+ messages in thread
From: Joshua Crofts via B4 Relay @ 2026-05-12 10:57 UTC (permalink / raw)
  To: Jonathan Cameron, David Lechner, Nuno Sá, Andy Shevchenko,
	Alexander Koch, Michael Hornung
  Cc: linux-iio, linux-kernel, Joshua Crofts, Andy Shevchenko

From: Joshua Crofts <joshua.crofts1@gmail.com>

Switch the driver to use local variables for struct device and struct
i2c_client to improve code style.

While at it, ensure that parentheses alignment is correct in functions
that were changed in this patch.

No functional change.

Suggested-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Joshua Crofts <joshua.crofts1@gmail.com>
---
 drivers/iio/light/opt3001.c | 147 +++++++++++++++++++++++---------------------
 1 file changed, 78 insertions(+), 69 deletions(-)

diff --git a/drivers/iio/light/opt3001.c b/drivers/iio/light/opt3001.c
index 6ce1a2d7647a3b9cd8964a276878630d31f61794..0de8ef4f3e68e6380b47d27e35882c604563377c 100644
--- a/drivers/iio/light/opt3001.c
+++ b/drivers/iio/light/opt3001.c
@@ -313,6 +313,8 @@ static const struct iio_chan_spec opt3002_channels[] = {
 
 static int opt3001_get_processed(struct opt3001 *opt, int *val, int *val2)
 {
+	struct i2c_client *client = opt->client;
+	struct device *dev = opt->dev;
 	int ret;
 	u16 mantissa;
 	u16 reg;
@@ -326,12 +328,12 @@ static int opt3001_get_processed(struct opt3001 *opt, int *val, int *val2)
 		 * doing so will overwrite the low-level limit value however we
 		 * will restore this value later on.
 		 */
-		ret = i2c_smbus_write_word_swapped(opt->client,
-					OPT3001_LOW_LIMIT,
-					OPT3001_LOW_LIMIT_EOC_ENABLE);
+		ret = i2c_smbus_write_word_swapped(client,
+						   OPT3001_LOW_LIMIT,
+						   OPT3001_LOW_LIMIT_EOC_ENABLE);
 		if (ret < 0) {
-			dev_err(opt->dev, "failed to write register %02x\n",
-					OPT3001_LOW_LIMIT);
+			dev_err(dev, "failed to write register %02x\n",
+				OPT3001_LOW_LIMIT);
 			return ret;
 		}
 
@@ -343,21 +345,20 @@ static int opt3001_get_processed(struct opt3001 *opt, int *val, int *val2)
 	opt->result_ready = false;
 
 	/* Configure for single-conversion mode and start a new conversion */
-	ret = i2c_smbus_read_word_swapped(opt->client, OPT3001_CONFIGURATION);
+	ret = i2c_smbus_read_word_swapped(client, OPT3001_CONFIGURATION);
 	if (ret < 0) {
-		dev_err(opt->dev, "failed to read register %02x\n",
-				OPT3001_CONFIGURATION);
+		dev_err(dev, "failed to read register %02x\n",
+			OPT3001_CONFIGURATION);
 		goto err;
 	}
 
 	reg = ret;
 	opt3001_set_mode(opt, &reg, OPT3001_CONFIGURATION_M_SINGLE);
 
-	ret = i2c_smbus_write_word_swapped(opt->client, OPT3001_CONFIGURATION,
-			reg);
+	ret = i2c_smbus_write_word_swapped(client, OPT3001_CONFIGURATION, reg);
 	if (ret < 0) {
-		dev_err(opt->dev, "failed to write register %02x\n",
-				OPT3001_CONFIGURATION);
+		dev_err(dev, "failed to write register %02x\n",
+			OPT3001_CONFIGURATION);
 		goto err;
 	}
 
@@ -375,10 +376,9 @@ static int opt3001_get_processed(struct opt3001 *opt, int *val, int *val2)
 		msleep(timeout);
 
 		/* Check result ready flag */
-		ret = i2c_smbus_read_word_swapped(opt->client,
-						  OPT3001_CONFIGURATION);
+		ret = i2c_smbus_read_word_swapped(client, OPT3001_CONFIGURATION);
 		if (ret < 0) {
-			dev_err(opt->dev, "failed to read register %02x\n",
+			dev_err(dev, "failed to read register %02x\n",
 				OPT3001_CONFIGURATION);
 			goto err;
 		}
@@ -389,9 +389,9 @@ static int opt3001_get_processed(struct opt3001 *opt, int *val, int *val2)
 		}
 
 		/* Obtain value */
-		ret = i2c_smbus_read_word_swapped(opt->client, OPT3001_RESULT);
+		ret = i2c_smbus_read_word_swapped(client, OPT3001_RESULT);
 		if (ret < 0) {
-			dev_err(opt->dev, "failed to read register %02x\n",
+			dev_err(dev, "failed to read register %02x\n",
 				OPT3001_RESULT);
 			goto err;
 		}
@@ -416,12 +416,12 @@ static int opt3001_get_processed(struct opt3001 *opt, int *val, int *val2)
 		 * bit-overlap and therefore can't be done.
 		 */
 		value = (opt->low_thresh_exp << 12) | opt->low_thresh_mantissa;
-		ret = i2c_smbus_write_word_swapped(opt->client,
+		ret = i2c_smbus_write_word_swapped(client,
 						   OPT3001_LOW_LIMIT,
 						   value);
 		if (ret < 0) {
-			dev_err(opt->dev, "failed to write register %02x\n",
-					OPT3001_LOW_LIMIT);
+			dev_err(dev, "failed to write register %02x\n",
+				OPT3001_LOW_LIMIT);
 			return ret;
 		}
 	}
@@ -444,13 +444,15 @@ static int opt3001_get_int_time(struct opt3001 *opt, int *val, int *val2)
 
 static int opt3001_set_int_time(struct opt3001 *opt, int time)
 {
+	struct i2c_client *client = opt->client;
+	struct device *dev = opt->dev;
 	int ret;
 	u16 reg;
 
-	ret = i2c_smbus_read_word_swapped(opt->client, OPT3001_CONFIGURATION);
+	ret = i2c_smbus_read_word_swapped(client, OPT3001_CONFIGURATION);
 	if (ret < 0) {
-		dev_err(opt->dev, "failed to read register %02x\n",
-				OPT3001_CONFIGURATION);
+		dev_err(dev, "failed to read register %02x\n",
+			OPT3001_CONFIGURATION);
 		return ret;
 	}
 
@@ -469,8 +471,7 @@ static int opt3001_set_int_time(struct opt3001 *opt, int time)
 		return -EINVAL;
 	}
 
-	return i2c_smbus_write_word_swapped(opt->client, OPT3001_CONFIGURATION,
-			reg);
+	return i2c_smbus_write_word_swapped(client, OPT3001_CONFIGURATION, reg);
 }
 
 static int opt3001_read_raw(struct iio_dev *iio,
@@ -565,6 +566,8 @@ static int opt3001_write_event_value(struct iio_dev *iio,
 		int val, int val2)
 {
 	struct opt3001 *opt = iio_priv(iio);
+	struct i2c_client *client = opt->client;
+	struct device *dev = opt->dev;
 	int ret;
 	int whole;
 	int integer;
@@ -583,7 +586,7 @@ static int opt3001_write_event_value(struct iio_dev *iio,
 
 	ret = opt3001_find_scale(opt, val, val2, &exponent);
 	if (ret < 0) {
-		dev_err(opt->dev, "can't find scale for %d.%06u\n", val, val2);
+		dev_err(dev, "can't find scale for %d.%06u\n", val, val2);
 		goto err;
 	}
 
@@ -611,9 +614,9 @@ static int opt3001_write_event_value(struct iio_dev *iio,
 		goto err;
 	}
 
-	ret = i2c_smbus_write_word_swapped(opt->client, reg, value);
+	ret = i2c_smbus_write_word_swapped(client, reg, value);
 	if (ret < 0) {
-		dev_err(opt->dev, "failed to write register %02x\n", reg);
+		dev_err(dev, "failed to write register %02x\n", reg);
 		goto err;
 	}
 
@@ -637,6 +640,8 @@ static int opt3001_write_event_config(struct iio_dev *iio,
 		enum iio_event_direction dir, bool state)
 {
 	struct opt3001 *opt = iio_priv(iio);
+	struct i2c_client *client = opt->client;
+	struct device *dev = opt->dev;
 	int ret;
 	u16 mode;
 	u16 reg;
@@ -652,21 +657,20 @@ static int opt3001_write_event_config(struct iio_dev *iio,
 	mode = state ? OPT3001_CONFIGURATION_M_CONTINUOUS
 		: OPT3001_CONFIGURATION_M_SHUTDOWN;
 
-	ret = i2c_smbus_read_word_swapped(opt->client, OPT3001_CONFIGURATION);
+	ret = i2c_smbus_read_word_swapped(client, OPT3001_CONFIGURATION);
 	if (ret < 0) {
-		dev_err(opt->dev, "failed to read register %02x\n",
-				OPT3001_CONFIGURATION);
+		dev_err(dev, "failed to read register %02x\n",
+			OPT3001_CONFIGURATION);
 		goto err;
 	}
 
 	reg = ret;
 	opt3001_set_mode(opt, &reg, mode);
 
-	ret = i2c_smbus_write_word_swapped(opt->client, OPT3001_CONFIGURATION,
-			reg);
+	ret = i2c_smbus_write_word_swapped(client, OPT3001_CONFIGURATION, reg);
 	if (ret < 0) {
-		dev_err(opt->dev, "failed to write register %02x\n",
-				OPT3001_CONFIGURATION);
+		dev_err(dev, "failed to write register %02x\n",
+			OPT3001_CONFIGURATION);
 		goto err;
 	}
 
@@ -688,44 +692,48 @@ static const struct iio_info opt3001_info = {
 
 static int opt3001_read_id(struct opt3001 *opt)
 {
+	struct i2c_client *client = opt->client;
+	struct device *dev = opt->dev;
 	char manufacturer[2];
 	u16 device_id;
 	int ret;
 
-	ret = i2c_smbus_read_word_swapped(opt->client, OPT3001_MANUFACTURER_ID);
+	ret = i2c_smbus_read_word_swapped(client, OPT3001_MANUFACTURER_ID);
 	if (ret < 0) {
-		dev_err(opt->dev, "failed to read register %02x\n",
-				OPT3001_MANUFACTURER_ID);
+		dev_err(dev, "failed to read register %02x\n",
+			OPT3001_MANUFACTURER_ID);
 		return ret;
 	}
 
 	manufacturer[0] = ret >> 8;
 	manufacturer[1] = ret & 0xff;
 
-	ret = i2c_smbus_read_word_swapped(opt->client, OPT3001_DEVICE_ID);
+	ret = i2c_smbus_read_word_swapped(client, OPT3001_DEVICE_ID);
 	if (ret < 0) {
-		dev_err(opt->dev, "failed to read register %02x\n",
+		dev_err(dev, "failed to read register %02x\n",
 			OPT3001_DEVICE_ID);
 		return ret;
 	}
 
 	device_id = ret;
 
-	dev_info(opt->dev, "Found %c%c OPT%04x\n", manufacturer[0],
-			manufacturer[1], device_id);
+	dev_info(dev, "Found %c%c OPT%04x\n", manufacturer[0], manufacturer[1],
+		 device_id);
 
 	return 0;
 }
 
 static int opt3001_configure(struct opt3001 *opt)
 {
+	struct i2c_client *client = opt->client;
+	struct device *dev = opt->dev;
 	int ret;
 	u16 reg;
 
-	ret = i2c_smbus_read_word_swapped(opt->client, OPT3001_CONFIGURATION);
+	ret = i2c_smbus_read_word_swapped(client, OPT3001_CONFIGURATION);
 	if (ret < 0) {
-		dev_err(opt->dev, "failed to read register %02x\n",
-				OPT3001_CONFIGURATION);
+		dev_err(dev, "failed to read register %02x\n",
+			OPT3001_CONFIGURATION);
 		return ret;
 	}
 
@@ -750,28 +758,27 @@ static int opt3001_configure(struct opt3001 *opt)
 	reg &= ~OPT3001_CONFIGURATION_ME;
 	reg &= ~OPT3001_CONFIGURATION_FC_MASK;
 
-	ret = i2c_smbus_write_word_swapped(opt->client, OPT3001_CONFIGURATION,
-			reg);
+	ret = i2c_smbus_write_word_swapped(client, OPT3001_CONFIGURATION, reg);
 	if (ret < 0) {
-		dev_err(opt->dev, "failed to write register %02x\n",
-				OPT3001_CONFIGURATION);
+		dev_err(dev, "failed to write register %02x\n",
+			OPT3001_CONFIGURATION);
 		return ret;
 	}
 
-	ret = i2c_smbus_read_word_swapped(opt->client, OPT3001_LOW_LIMIT);
+	ret = i2c_smbus_read_word_swapped(client, OPT3001_LOW_LIMIT);
 	if (ret < 0) {
-		dev_err(opt->dev, "failed to read register %02x\n",
-				OPT3001_LOW_LIMIT);
+		dev_err(dev, "failed to read register %02x\n",
+			OPT3001_LOW_LIMIT);
 		return ret;
 	}
 
 	opt->low_thresh_mantissa = OPT3001_REG_MANTISSA(ret);
 	opt->low_thresh_exp = OPT3001_REG_EXPONENT(ret);
 
-	ret = i2c_smbus_read_word_swapped(opt->client, OPT3001_HIGH_LIMIT);
+	ret = i2c_smbus_read_word_swapped(client, OPT3001_HIGH_LIMIT);
 	if (ret < 0) {
-		dev_err(opt->dev, "failed to read register %02x\n",
-				OPT3001_HIGH_LIMIT);
+		dev_err(dev, "failed to read register %02x\n",
+			OPT3001_HIGH_LIMIT);
 		return ret;
 	}
 
@@ -785,6 +792,8 @@ static irqreturn_t opt3001_irq(int irq, void *_iio)
 {
 	struct iio_dev *iio = _iio;
 	struct opt3001 *opt = iio_priv(iio);
+	struct i2c_client *client = opt->client;
+	struct device *dev = opt->dev;
 	int ret;
 	bool wake_result_ready_queue = false;
 	enum iio_chan_type chan_type = opt->chip_info->chan_type;
@@ -793,10 +802,10 @@ static irqreturn_t opt3001_irq(int irq, void *_iio)
 	if (!ok_to_ignore_lock)
 		mutex_lock(&opt->lock);
 
-	ret = i2c_smbus_read_word_swapped(opt->client, OPT3001_CONFIGURATION);
+	ret = i2c_smbus_read_word_swapped(client, OPT3001_CONFIGURATION);
 	if (ret < 0) {
-		dev_err(opt->dev, "failed to read register %02x\n",
-				OPT3001_CONFIGURATION);
+		dev_err(dev, "failed to read register %02x\n",
+			OPT3001_CONFIGURATION);
 		goto out;
 	}
 
@@ -815,10 +824,10 @@ static irqreturn_t opt3001_irq(int irq, void *_iio)
 							IIO_EV_DIR_FALLING),
 					iio_get_time_ns(iio));
 	} else if (ret & OPT3001_CONFIGURATION_CRF) {
-		ret = i2c_smbus_read_word_swapped(opt->client, OPT3001_RESULT);
+		ret = i2c_smbus_read_word_swapped(client, OPT3001_RESULT);
 		if (ret < 0) {
-			dev_err(opt->dev, "failed to read register %02x\n",
-					OPT3001_RESULT);
+			dev_err(dev, "failed to read register %02x\n",
+				OPT3001_RESULT);
 			goto out;
 		}
 		opt->result = ret;
@@ -885,7 +894,7 @@ static int opt3001_probe(struct i2c_client *client)
 		}
 		opt->use_irq = true;
 	} else {
-		dev_dbg(opt->dev, "enabling interrupt-less operation\n");
+		dev_dbg(dev, "enabling interrupt-less operation\n");
 	}
 
 	ret = devm_iio_device_register(dev, iio);
@@ -899,27 +908,27 @@ static void opt3001_remove(struct i2c_client *client)
 {
 	struct iio_dev *iio = i2c_get_clientdata(client);
 	struct opt3001 *opt = iio_priv(iio);
+	struct device *dev = opt->dev;
 	int ret;
 	u16 reg;
 
 	if (opt->use_irq)
 		free_irq(client->irq, iio);
 
-	ret = i2c_smbus_read_word_swapped(opt->client, OPT3001_CONFIGURATION);
+	ret = i2c_smbus_read_word_swapped(client, OPT3001_CONFIGURATION);
 	if (ret < 0) {
-		dev_err(opt->dev, "failed to read register %02x\n",
-				OPT3001_CONFIGURATION);
+		dev_err(dev, "failed to read register %02x\n",
+			OPT3001_CONFIGURATION);
 		return;
 	}
 
 	reg = ret;
 	opt3001_set_mode(opt, &reg, OPT3001_CONFIGURATION_M_SHUTDOWN);
 
-	ret = i2c_smbus_write_word_swapped(opt->client, OPT3001_CONFIGURATION,
-			reg);
+	ret = i2c_smbus_write_word_swapped(client, OPT3001_CONFIGURATION, reg);
 	if (ret < 0) {
-		dev_err(opt->dev, "failed to write register %02x\n",
-				OPT3001_CONFIGURATION);
+		dev_err(dev, "failed to write register %02x\n",
+			OPT3001_CONFIGURATION);
 	}
 }
 

-- 
2.47.3



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

* [PATCH v2 05/10] iio: light: opt3001: ensure correct parenthesis alignment
  2026-05-12 10:57 [PATCH v2 00/10] iio: light: opt3001: driver cleanup Joshua Crofts via B4 Relay
                   ` (3 preceding siblings ...)
  2026-05-12 10:57 ` [PATCH v2 04/10] iio: light: opt3001: use local struct device and i2c_client variables Joshua Crofts via B4 Relay
@ 2026-05-12 10:57 ` Joshua Crofts via B4 Relay
  2026-05-12 10:57 ` [PATCH v2 06/10] iio: light: opt3001: localize for loop iterator Joshua Crofts via B4 Relay
                   ` (4 subsequent siblings)
  9 siblings, 0 replies; 18+ messages in thread
From: Joshua Crofts via B4 Relay @ 2026-05-12 10:57 UTC (permalink / raw)
  To: Jonathan Cameron, David Lechner, Nuno Sá, Andy Shevchenko,
	Alexander Koch, Michael Hornung
  Cc: linux-iio, linux-kernel, Joshua Crofts, Andy Shevchenko

From: Joshua Crofts <joshua.crofts1@gmail.com>

Ensure correct parenthesis alignment per checkpatch.pl report.

No functional change.

Suggested-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Joshua Crofts <joshua.crofts1@gmail.com>
---
 drivers/iio/light/opt3001.c | 73 +++++++++++++++++++++++++--------------------
 1 file changed, 41 insertions(+), 32 deletions(-)

diff --git a/drivers/iio/light/opt3001.c b/drivers/iio/light/opt3001.c
index 0de8ef4f3e68e6380b47d27e35882c604563377c..ad729152bb9266a35919e3abe576e792dbc08730 100644
--- a/drivers/iio/light/opt3001.c
+++ b/drivers/iio/light/opt3001.c
@@ -224,8 +224,8 @@ static const struct opt3001_scale opt3002_scales[] = {
 	},
 };
 
-static int opt3001_find_scale(const struct opt3001 *opt, int val,
-		int val2, u8 *exponent)
+static int opt3001_find_scale(const struct opt3001 *opt, int val, int val2,
+			      u8 *exponent)
 {
 	int i;
 	for (i = 0; i < ARRAY_SIZE(*opt->chip_info->scales); i++) {
@@ -243,8 +243,8 @@ static int opt3001_find_scale(const struct opt3001 *opt, int val,
 	return -EINVAL;
 }
 
-static void opt3001_to_iio_ret(struct opt3001 *opt, u8 exponent,
-		u16 mantissa, int *val, int *val2)
+static void opt3001_to_iio_ret(struct opt3001 *opt, u8 exponent, u16 mantissa,
+			       int *val, int *val2)
 {
 	int ret;
 	int whole = opt->chip_info->factor_whole;
@@ -365,8 +365,8 @@ static int opt3001_get_processed(struct opt3001 *opt, int *val, int *val2)
 	if (opt->use_irq) {
 		/* Wait for the IRQ to indicate the conversion is complete */
 		ret = wait_event_timeout(opt->result_ready_queue,
-				opt->result_ready,
-				msecs_to_jiffies(OPT3001_RESULT_READY_LONG));
+					 opt->result_ready,
+					 msecs_to_jiffies(OPT3001_RESULT_READY_LONG));
 		if (ret == 0)
 			return -ETIMEDOUT;
 	} else {
@@ -475,8 +475,8 @@ static int opt3001_set_int_time(struct opt3001 *opt, int time)
 }
 
 static int opt3001_read_raw(struct iio_dev *iio,
-		struct iio_chan_spec const *chan, int *val, int *val2,
-		long mask)
+			    struct iio_chan_spec const *chan,
+			    int *val, int *val2, long mask)
 {
 	struct opt3001 *opt = iio_priv(iio);
 	int ret;
@@ -507,8 +507,8 @@ static int opt3001_read_raw(struct iio_dev *iio,
 }
 
 static int opt3001_write_raw(struct iio_dev *iio,
-		struct iio_chan_spec const *chan, int val, int val2,
-		long mask)
+			     struct iio_chan_spec const *chan,
+			     int val, int val2, long mask)
 {
 	struct opt3001 *opt = iio_priv(iio);
 	int ret;
@@ -533,9 +533,11 @@ static int opt3001_write_raw(struct iio_dev *iio,
 }
 
 static int opt3001_read_event_value(struct iio_dev *iio,
-		const struct iio_chan_spec *chan, enum iio_event_type type,
-		enum iio_event_direction dir, enum iio_event_info info,
-		int *val, int *val2)
+				    const struct iio_chan_spec *chan,
+				    enum iio_event_type type,
+				    enum iio_event_direction dir,
+				    enum iio_event_info info,
+				    int *val, int *val2)
 {
 	struct opt3001 *opt = iio_priv(iio);
 	int ret = IIO_VAL_INT_PLUS_MICRO;
@@ -545,11 +547,13 @@ static int opt3001_read_event_value(struct iio_dev *iio,
 	switch (dir) {
 	case IIO_EV_DIR_RISING:
 		opt3001_to_iio_ret(opt, opt->high_thresh_exp,
-				opt->high_thresh_mantissa, val, val2);
+				   opt->high_thresh_mantissa,
+				   val, val2);
 		break;
 	case IIO_EV_DIR_FALLING:
 		opt3001_to_iio_ret(opt, opt->low_thresh_exp,
-				opt->low_thresh_mantissa, val, val2);
+				   opt->low_thresh_mantissa,
+				   val, val2);
 		break;
 	default:
 		ret = -EINVAL;
@@ -561,9 +565,11 @@ static int opt3001_read_event_value(struct iio_dev *iio,
 }
 
 static int opt3001_write_event_value(struct iio_dev *iio,
-		const struct iio_chan_spec *chan, enum iio_event_type type,
-		enum iio_event_direction dir, enum iio_event_info info,
-		int val, int val2)
+				     const struct iio_chan_spec *chan,
+				     enum iio_event_type type,
+				     enum iio_event_direction dir,
+				     enum iio_event_info info,
+				     int val, int val2)
 {
 	struct opt3001 *opt = iio_priv(iio);
 	struct i2c_client *client = opt->client;
@@ -627,8 +633,9 @@ static int opt3001_write_event_value(struct iio_dev *iio,
 }
 
 static int opt3001_read_event_config(struct iio_dev *iio,
-		const struct iio_chan_spec *chan, enum iio_event_type type,
-		enum iio_event_direction dir)
+				     const struct iio_chan_spec *chan,
+				     enum iio_event_type type,
+				     enum iio_event_direction dir)
 {
 	struct opt3001 *opt = iio_priv(iio);
 
@@ -636,8 +643,10 @@ static int opt3001_read_event_config(struct iio_dev *iio,
 }
 
 static int opt3001_write_event_config(struct iio_dev *iio,
-		const struct iio_chan_spec *chan, enum iio_event_type type,
-		enum iio_event_direction dir, bool state)
+				      const struct iio_chan_spec *chan,
+				      enum iio_event_type type,
+				      enum iio_event_direction dir,
+				      bool state)
 {
 	struct opt3001 *opt = iio_priv(iio);
 	struct i2c_client *client = opt->client;
@@ -813,16 +822,16 @@ static irqreturn_t opt3001_irq(int irq, void *_iio)
 			OPT3001_CONFIGURATION_M_CONTINUOUS) {
 		if (ret & OPT3001_CONFIGURATION_FH)
 			iio_push_event(iio,
-					IIO_UNMOD_EVENT_CODE(chan_type, 0,
-							IIO_EV_TYPE_THRESH,
-							IIO_EV_DIR_RISING),
-					iio_get_time_ns(iio));
+				       IIO_UNMOD_EVENT_CODE(chan_type, 0,
+							    IIO_EV_TYPE_THRESH,
+							    IIO_EV_DIR_RISING),
+				       iio_get_time_ns(iio));
 		if (ret & OPT3001_CONFIGURATION_FL)
 			iio_push_event(iio,
-					IIO_UNMOD_EVENT_CODE(chan_type, 0,
-							IIO_EV_TYPE_THRESH,
-							IIO_EV_DIR_FALLING),
-					iio_get_time_ns(iio));
+				       IIO_UNMOD_EVENT_CODE(chan_type, 0,
+							    IIO_EV_TYPE_THRESH,
+							    IIO_EV_DIR_FALLING),
+				       iio_get_time_ns(iio));
 	} else if (ret & OPT3001_CONFIGURATION_CRF) {
 		ret = i2c_smbus_read_word_swapped(client, OPT3001_RESULT);
 		if (ret < 0) {
@@ -886,8 +895,8 @@ static int opt3001_probe(struct i2c_client *client)
 	/* Make use of INT pin only if valid IRQ no. is given */
 	if (irq > 0) {
 		ret = request_threaded_irq(irq, NULL, opt3001_irq,
-				IRQF_TRIGGER_FALLING | IRQF_ONESHOT,
-				"opt3001", iio);
+					   IRQF_TRIGGER_FALLING | IRQF_ONESHOT,
+					   "opt3001", iio);
 		if (ret) {
 			dev_err(dev, "failed to request IRQ #%d\n", irq);
 			return ret;

-- 
2.47.3



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

* [PATCH v2 06/10] iio: light: opt3001: localize for loop iterator
  2026-05-12 10:57 [PATCH v2 00/10] iio: light: opt3001: driver cleanup Joshua Crofts via B4 Relay
                   ` (4 preceding siblings ...)
  2026-05-12 10:57 ` [PATCH v2 05/10] iio: light: opt3001: ensure correct parenthesis alignment Joshua Crofts via B4 Relay
@ 2026-05-12 10:57 ` Joshua Crofts via B4 Relay
  2026-05-12 15:40   ` Andy Shevchenko
  2026-05-12 10:57 ` [PATCH v2 07/10] iio: light: opt3001: prefer dev_err_probe() Joshua Crofts via B4 Relay
                   ` (3 subsequent siblings)
  9 siblings, 1 reply; 18+ messages in thread
From: Joshua Crofts via B4 Relay @ 2026-05-12 10:57 UTC (permalink / raw)
  To: Jonathan Cameron, David Lechner, Nuno Sá, Andy Shevchenko,
	Alexander Koch, Michael Hornung
  Cc: linux-iio, linux-kernel, Joshua Crofts

From: Joshua Crofts <joshua.crofts1@gmail.com>

Localize loop iterator to tighten scope and improve code style
per checkpatch.pl report.

No functional change.

Signed-off-by: Joshua Crofts <joshua.crofts1@gmail.com>
---
 drivers/iio/light/opt3001.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/iio/light/opt3001.c b/drivers/iio/light/opt3001.c
index ad729152bb9266a35919e3abe576e792dbc08730..8eaa2cb6b5b044afdc405f19cd2499abb7e4d7a3 100644
--- a/drivers/iio/light/opt3001.c
+++ b/drivers/iio/light/opt3001.c
@@ -227,8 +227,7 @@ static const struct opt3001_scale opt3002_scales[] = {
 static int opt3001_find_scale(const struct opt3001 *opt, int val, int val2,
 			      u8 *exponent)
 {
-	int i;
-	for (i = 0; i < ARRAY_SIZE(*opt->chip_info->scales); i++) {
+	for (unsigned int i = 0; i < ARRAY_SIZE(*opt->chip_info->scales); i++) {
 		const struct opt3001_scale *scale = &(*opt->chip_info->scales)[i];
 		/*
 		 * Compare the integer and micro parts to determine value scale.

-- 
2.47.3



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

* [PATCH v2 07/10] iio: light: opt3001: prefer dev_err_probe()
  2026-05-12 10:57 [PATCH v2 00/10] iio: light: opt3001: driver cleanup Joshua Crofts via B4 Relay
                   ` (5 preceding siblings ...)
  2026-05-12 10:57 ` [PATCH v2 06/10] iio: light: opt3001: localize for loop iterator Joshua Crofts via B4 Relay
@ 2026-05-12 10:57 ` Joshua Crofts via B4 Relay
  2026-05-12 15:43   ` Andy Shevchenko
  2026-05-12 10:57 ` [PATCH v2 08/10] iio: light: opt3001: move driver to guard(mutex)() use Joshua Crofts via B4 Relay
                   ` (2 subsequent siblings)
  9 siblings, 1 reply; 18+ messages in thread
From: Joshua Crofts via B4 Relay @ 2026-05-12 10:57 UTC (permalink / raw)
  To: Jonathan Cameron, David Lechner, Nuno Sá, Andy Shevchenko,
	Alexander Koch, Michael Hornung
  Cc: linux-iio, linux-kernel, Joshua Crofts

From: Joshua Crofts <joshua.crofts1@gmail.com>

Switch driver to use dev_err_probe() to unify
error messages generated in *_probe() and probe path functions.

Signed-off-by: Joshua Crofts <joshua.crofts1@gmail.com>
---
 drivers/iio/light/opt3001.c | 59 ++++++++++++++++++---------------------------
 1 file changed, 24 insertions(+), 35 deletions(-)

diff --git a/drivers/iio/light/opt3001.c b/drivers/iio/light/opt3001.c
index 8eaa2cb6b5b044afdc405f19cd2499abb7e4d7a3..6f7c524d3a7a41c5177c9b02ebe1b7858294a0b4 100644
--- a/drivers/iio/light/opt3001.c
+++ b/drivers/iio/light/opt3001.c
@@ -707,21 +707,17 @@ static int opt3001_read_id(struct opt3001 *opt)
 	int ret;
 
 	ret = i2c_smbus_read_word_swapped(client, OPT3001_MANUFACTURER_ID);
-	if (ret < 0) {
-		dev_err(dev, "failed to read register %02x\n",
-			OPT3001_MANUFACTURER_ID);
-		return ret;
-	}
+	if (ret < 0)
+		return dev_err_probe(dev, ret, "failed to read register %02x\n",
+				     OPT3001_MANUFACTURER_ID);
 
 	manufacturer[0] = ret >> 8;
 	manufacturer[1] = ret & 0xff;
 
 	ret = i2c_smbus_read_word_swapped(client, OPT3001_DEVICE_ID);
-	if (ret < 0) {
-		dev_err(dev, "failed to read register %02x\n",
-			OPT3001_DEVICE_ID);
-		return ret;
-	}
+	if (ret < 0)
+		return dev_err_probe(dev, ret, "failed to read register %02x\n",
+				     OPT3001_DEVICE_ID);
 
 	device_id = ret;
 
@@ -739,11 +735,9 @@ static int opt3001_configure(struct opt3001 *opt)
 	u16 reg;
 
 	ret = i2c_smbus_read_word_swapped(client, OPT3001_CONFIGURATION);
-	if (ret < 0) {
-		dev_err(dev, "failed to read register %02x\n",
-			OPT3001_CONFIGURATION);
-		return ret;
-	}
+	if (ret < 0)
+		return dev_err_probe(dev, ret, "failed to read register %02x\n",
+				     OPT3001_CONFIGURATION);
 
 	reg = ret;
 
@@ -767,28 +761,22 @@ static int opt3001_configure(struct opt3001 *opt)
 	reg &= ~OPT3001_CONFIGURATION_FC_MASK;
 
 	ret = i2c_smbus_write_word_swapped(client, OPT3001_CONFIGURATION, reg);
-	if (ret < 0) {
-		dev_err(dev, "failed to write register %02x\n",
-			OPT3001_CONFIGURATION);
-		return ret;
-	}
+	if (ret < 0)
+		return dev_err_probe(dev, ret, "failed to write register %02x\n",
+				     OPT3001_CONFIGURATION);
 
 	ret = i2c_smbus_read_word_swapped(client, OPT3001_LOW_LIMIT);
-	if (ret < 0) {
-		dev_err(dev, "failed to read register %02x\n",
-			OPT3001_LOW_LIMIT);
-		return ret;
-	}
+	if (ret < 0)
+		return dev_err_probe(dev, ret, "failed to read register %02x\n",
+				     OPT3001_LOW_LIMIT);
 
 	opt->low_thresh_mantissa = OPT3001_REG_MANTISSA(ret);
 	opt->low_thresh_exp = OPT3001_REG_EXPONENT(ret);
 
 	ret = i2c_smbus_read_word_swapped(client, OPT3001_HIGH_LIMIT);
-	if (ret < 0) {
-		dev_err(dev, "failed to read register %02x\n",
-			OPT3001_HIGH_LIMIT);
-		return ret;
-	}
+	if (ret < 0)
+		return dev_err_probe(dev, ret, "failed to read register %02x\n",
+				     OPT3001_HIGH_LIMIT);
 
 	opt->high_thresh_mantissa = OPT3001_REG_MANTISSA(ret);
 	opt->high_thresh_exp = OPT3001_REG_EXPONENT(ret);
@@ -896,10 +884,10 @@ static int opt3001_probe(struct i2c_client *client)
 		ret = request_threaded_irq(irq, NULL, opt3001_irq,
 					   IRQF_TRIGGER_FALLING | IRQF_ONESHOT,
 					   "opt3001", iio);
-		if (ret) {
-			dev_err(dev, "failed to request IRQ #%d\n", irq);
-			return ret;
-		}
+		if (ret)
+			return dev_err_probe(dev, ret,
+					     "failed to request IRQ #%d\n",
+					     irq);
 		opt->use_irq = true;
 	} else {
 		dev_dbg(dev, "enabling interrupt-less operation\n");
@@ -907,7 +895,8 @@ static int opt3001_probe(struct i2c_client *client)
 
 	ret = devm_iio_device_register(dev, iio);
 	if (ret)
-		return dev_err(dev, "failed to register IIO device\n");
+		return dev_err_probe(dev, ret,
+				     "failed to register IIO device\n");
 
 	return 0;
 }

-- 
2.47.3



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

* [PATCH v2 08/10] iio: light: opt3001: move driver to guard(mutex)() use
  2026-05-12 10:57 [PATCH v2 00/10] iio: light: opt3001: driver cleanup Joshua Crofts via B4 Relay
                   ` (6 preceding siblings ...)
  2026-05-12 10:57 ` [PATCH v2 07/10] iio: light: opt3001: prefer dev_err_probe() Joshua Crofts via B4 Relay
@ 2026-05-12 10:57 ` Joshua Crofts via B4 Relay
  2026-05-12 10:57 ` [PATCH v2 09/10] iio: light: opt3001: switch driver to managed resources Joshua Crofts via B4 Relay
  2026-05-12 10:57 ` [PATCH v2 10/10] iio: light: opt3001: add comment to mutex Joshua Crofts via B4 Relay
  9 siblings, 0 replies; 18+ messages in thread
From: Joshua Crofts via B4 Relay @ 2026-05-12 10:57 UTC (permalink / raw)
  To: Jonathan Cameron, David Lechner, Nuno Sá, Andy Shevchenko,
	Alexander Koch, Michael Hornung
  Cc: linux-iio, linux-kernel, Joshua Crofts, Andy Shevchenko

From: Joshua Crofts <joshua.crofts1@gmail.com>

Move driver to use guard(mutex)() macro, to facilitate automatic
locking/unlocking of resources. This modernizes the driver and
improves code style.

While at it, remove unnecessary gotos and return variables.

Reviewed-by: Andy Shevchenko <andriy.shevchenko@intel.com>
Signed-off-by: Joshua Crofts <joshua.crofts1@gmail.com>
---
 drivers/iio/light/opt3001.c | 61 +++++++++++++--------------------------------
 1 file changed, 18 insertions(+), 43 deletions(-)

diff --git a/drivers/iio/light/opt3001.c b/drivers/iio/light/opt3001.c
index 6f7c524d3a7a41c5177c9b02ebe1b7858294a0b4..39ea60c0af2c1ec7473d49b73778cac1f9bb6086 100644
--- a/drivers/iio/light/opt3001.c
+++ b/drivers/iio/light/opt3001.c
@@ -10,6 +10,7 @@
 
 #include <linux/array_size.h>
 #include <linux/bits.h>
+#include <linux/cleanup.h>
 #include <linux/delay.h>
 #include <linux/dev_printk.h>
 #include <linux/errno.h>
@@ -478,7 +479,6 @@ static int opt3001_read_raw(struct iio_dev *iio,
 			    int *val, int *val2, long mask)
 {
 	struct opt3001 *opt = iio_priv(iio);
-	int ret;
 
 	if (opt->mode == OPT3001_CONFIGURATION_M_CONTINUOUS)
 		return -EBUSY;
@@ -486,23 +486,17 @@ static int opt3001_read_raw(struct iio_dev *iio,
 	if (chan->type != opt->chip_info->chan_type)
 		return -EINVAL;
 
-	mutex_lock(&opt->lock);
+	guard(mutex)(&opt->lock);
 
 	switch (mask) {
 	case IIO_CHAN_INFO_RAW:
 	case IIO_CHAN_INFO_PROCESSED:
-		ret = opt3001_get_processed(opt, val, val2);
-		break;
+		return opt3001_get_processed(opt, val, val2);
 	case IIO_CHAN_INFO_INT_TIME:
-		ret = opt3001_get_int_time(opt, val, val2);
-		break;
+		return opt3001_get_int_time(opt, val, val2);
 	default:
-		ret = -EINVAL;
+		return -EINVAL;
 	}
-
-	mutex_unlock(&opt->lock);
-
-	return ret;
 }
 
 static int opt3001_write_raw(struct iio_dev *iio,
@@ -510,7 +504,6 @@ static int opt3001_write_raw(struct iio_dev *iio,
 			     int val, int val2, long mask)
 {
 	struct opt3001 *opt = iio_priv(iio);
-	int ret;
 
 	if (opt->mode == OPT3001_CONFIGURATION_M_CONTINUOUS)
 		return -EBUSY;
@@ -524,11 +517,9 @@ static int opt3001_write_raw(struct iio_dev *iio,
 	if (val != 0)
 		return -EINVAL;
 
-	mutex_lock(&opt->lock);
-	ret = opt3001_set_int_time(opt, val2);
-	mutex_unlock(&opt->lock);
+	guard(mutex)(&opt->lock);
 
-	return ret;
+	return opt3001_set_int_time(opt, val2);
 }
 
 static int opt3001_read_event_value(struct iio_dev *iio,
@@ -539,28 +530,23 @@ static int opt3001_read_event_value(struct iio_dev *iio,
 				    int *val, int *val2)
 {
 	struct opt3001 *opt = iio_priv(iio);
-	int ret = IIO_VAL_INT_PLUS_MICRO;
 
-	mutex_lock(&opt->lock);
+	guard(mutex)(&opt->lock);
 
 	switch (dir) {
 	case IIO_EV_DIR_RISING:
 		opt3001_to_iio_ret(opt, opt->high_thresh_exp,
 				   opt->high_thresh_mantissa,
 				   val, val2);
-		break;
+		return IIO_VAL_INT_PLUS_MICRO;
 	case IIO_EV_DIR_FALLING:
 		opt3001_to_iio_ret(opt, opt->low_thresh_exp,
 				   opt->low_thresh_mantissa,
 				   val, val2);
-		break;
+		return IIO_VAL_INT_PLUS_MICRO;
 	default:
-		ret = -EINVAL;
+		return -EINVAL;
 	}
-
-	mutex_unlock(&opt->lock);
-
-	return ret;
 }
 
 static int opt3001_write_event_value(struct iio_dev *iio,
@@ -587,12 +573,12 @@ static int opt3001_write_event_value(struct iio_dev *iio,
 	if (val < 0)
 		return -EINVAL;
 
-	mutex_lock(&opt->lock);
+	guard(mutex)(&opt->lock);
 
 	ret = opt3001_find_scale(opt, val, val2, &exponent);
 	if (ret < 0) {
 		dev_err(dev, "can't find scale for %d.%06u\n", val, val2);
-		goto err;
+		return ret;
 	}
 
 	whole = opt->chip_info->factor_whole;
@@ -615,18 +601,12 @@ static int opt3001_write_event_value(struct iio_dev *iio,
 		opt->low_thresh_exp = exponent;
 		break;
 	default:
-		ret = -EINVAL;
-		goto err;
+		return -EINVAL;
 	}
 
 	ret = i2c_smbus_write_word_swapped(client, reg, value);
-	if (ret < 0) {
+	if (ret < 0)
 		dev_err(dev, "failed to write register %02x\n", reg);
-		goto err;
-	}
-
-err:
-	mutex_unlock(&opt->lock);
 
 	return ret;
 }
@@ -660,7 +640,7 @@ static int opt3001_write_event_config(struct iio_dev *iio,
 	if (!state && opt->mode == OPT3001_CONFIGURATION_M_SHUTDOWN)
 		return 0;
 
-	mutex_lock(&opt->lock);
+	guard(mutex)(&opt->lock);
 
 	mode = state ? OPT3001_CONFIGURATION_M_CONTINUOUS
 		: OPT3001_CONFIGURATION_M_SHUTDOWN;
@@ -669,21 +649,16 @@ static int opt3001_write_event_config(struct iio_dev *iio,
 	if (ret < 0) {
 		dev_err(dev, "failed to read register %02x\n",
 			OPT3001_CONFIGURATION);
-		goto err;
+		return ret;
 	}
 
 	reg = ret;
 	opt3001_set_mode(opt, &reg, mode);
 
 	ret = i2c_smbus_write_word_swapped(client, OPT3001_CONFIGURATION, reg);
-	if (ret < 0) {
+	if (ret < 0)
 		dev_err(dev, "failed to write register %02x\n",
 			OPT3001_CONFIGURATION);
-		goto err;
-	}
-
-err:
-	mutex_unlock(&opt->lock);
 
 	return ret;
 }

-- 
2.47.3



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

* [PATCH v2 09/10] iio: light: opt3001: switch driver to managed resources
  2026-05-12 10:57 [PATCH v2 00/10] iio: light: opt3001: driver cleanup Joshua Crofts via B4 Relay
                   ` (7 preceding siblings ...)
  2026-05-12 10:57 ` [PATCH v2 08/10] iio: light: opt3001: move driver to guard(mutex)() use Joshua Crofts via B4 Relay
@ 2026-05-12 10:57 ` Joshua Crofts via B4 Relay
  2026-05-12 14:26   ` Jonathan Cameron
  2026-05-12 10:57 ` [PATCH v2 10/10] iio: light: opt3001: add comment to mutex Joshua Crofts via B4 Relay
  9 siblings, 1 reply; 18+ messages in thread
From: Joshua Crofts via B4 Relay @ 2026-05-12 10:57 UTC (permalink / raw)
  To: Jonathan Cameron, David Lechner, Nuno Sá, Andy Shevchenko,
	Alexander Koch, Michael Hornung
  Cc: linux-iio, linux-kernel, Joshua Crofts

From: Joshua Crofts <joshua.crofts1@gmail.com>

Move the driver to use devm_* functions to automate resource
management and simplify error handling. This also allows removal
of the opt3001_remove() function.

Signed-off-by: Joshua Crofts <joshua.crofts1@gmail.com>
---
 drivers/iio/light/opt3001.c | 75 +++++++++++++++++++++++----------------------
 1 file changed, 39 insertions(+), 36 deletions(-)

diff --git a/drivers/iio/light/opt3001.c b/drivers/iio/light/opt3001.c
index 39ea60c0af2c1ec7473d49b73778cac1f9bb6086..1319e5941b66bd82e4dc2badf5ea27cacbcfd54a 100644
--- a/drivers/iio/light/opt3001.c
+++ b/drivers/iio/light/opt3001.c
@@ -702,6 +702,31 @@ static int opt3001_read_id(struct opt3001 *opt)
 	return 0;
 }
 
+static void opt3001_power_off(void *data)
+{
+	struct opt3001 *opt = data;
+	struct i2c_client *client = opt->client;
+	struct device *dev = opt->dev;
+
+	int ret;
+	u16 reg;
+
+	ret = i2c_smbus_read_word_swapped(client, OPT3001_CONFIGURATION);
+	if (ret < 0) {
+		dev_err(dev, "failed to read register %02x\n",
+			OPT3001_CONFIGURATION);
+		return;
+	}
+
+	reg = ret;
+	opt3001_set_mode(opt, &reg, OPT3001_CONFIGURATION_M_SHUTDOWN);
+
+	ret = i2c_smbus_write_word_swapped(client, OPT3001_CONFIGURATION, reg);
+	if (ret < 0)
+		dev_err(dev, "failed to write to register %02x\n",
+			OPT3001_CONFIGURATION);
+}
+
 static int opt3001_configure(struct opt3001 *opt)
 {
 	struct i2c_client *client = opt->client;
@@ -740,6 +765,11 @@ static int opt3001_configure(struct opt3001 *opt)
 		return dev_err_probe(dev, ret, "failed to write register %02x\n",
 				     OPT3001_CONFIGURATION);
 
+	ret = devm_add_action_or_reset(dev, opt3001_power_off, opt);
+	if (ret)
+		return dev_err_probe(dev, ret,
+				     "failed to register power off function\n");
+
 	ret = i2c_smbus_read_word_swapped(client, OPT3001_LOW_LIMIT);
 	if (ret < 0)
 		return dev_err_probe(dev, ret, "failed to read register %02x\n",
@@ -834,7 +864,10 @@ static int opt3001_probe(struct i2c_client *client)
 	opt->dev = dev;
 	opt->chip_info = i2c_get_match_data(client);
 
-	mutex_init(&opt->lock);
+	ret = devm_mutex_init(dev, &opt->lock);
+	if (ret)
+		return ret;
+
 	init_waitqueue_head(&opt->result_ready_queue);
 	i2c_set_clientdata(client, iio);
 
@@ -856,13 +889,12 @@ static int opt3001_probe(struct i2c_client *client)
 
 	/* Make use of INT pin only if valid IRQ no. is given */
 	if (irq > 0) {
-		ret = request_threaded_irq(irq, NULL, opt3001_irq,
-					   IRQF_TRIGGER_FALLING | IRQF_ONESHOT,
-					   "opt3001", iio);
+		ret = devm_request_threaded_irq(dev, irq, NULL, opt3001_irq,
+						IRQF_TRIGGER_FALLING | IRQF_ONESHOT,
+						"opt3001", iio);
 		if (ret)
-			return dev_err_probe(dev, ret,
-					     "failed to request IRQ #%d\n",
-					     irq);
+			return ret;
+
 		opt->use_irq = true;
 	} else {
 		dev_dbg(dev, "enabling interrupt-less operation\n");
@@ -876,34 +908,6 @@ static int opt3001_probe(struct i2c_client *client)
 	return 0;
 }
 
-static void opt3001_remove(struct i2c_client *client)
-{
-	struct iio_dev *iio = i2c_get_clientdata(client);
-	struct opt3001 *opt = iio_priv(iio);
-	struct device *dev = opt->dev;
-	int ret;
-	u16 reg;
-
-	if (opt->use_irq)
-		free_irq(client->irq, iio);
-
-	ret = i2c_smbus_read_word_swapped(client, OPT3001_CONFIGURATION);
-	if (ret < 0) {
-		dev_err(dev, "failed to read register %02x\n",
-			OPT3001_CONFIGURATION);
-		return;
-	}
-
-	reg = ret;
-	opt3001_set_mode(opt, &reg, OPT3001_CONFIGURATION_M_SHUTDOWN);
-
-	ret = i2c_smbus_write_word_swapped(client, OPT3001_CONFIGURATION, reg);
-	if (ret < 0) {
-		dev_err(dev, "failed to write register %02x\n",
-			OPT3001_CONFIGURATION);
-	}
-}
-
 static const struct opt3001_chip_info opt3001_chip_information = {
 	.channels = &opt3001_channels,
 	.chan_type = IIO_LIGHT,
@@ -942,7 +946,6 @@ MODULE_DEVICE_TABLE(of, opt3001_of_match);
 
 static struct i2c_driver opt3001_driver = {
 	.probe = opt3001_probe,
-	.remove = opt3001_remove,
 	.id_table = opt3001_id,
 
 	.driver = {

-- 
2.47.3



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

* [PATCH v2 10/10] iio: light: opt3001: add comment to mutex
  2026-05-12 10:57 [PATCH v2 00/10] iio: light: opt3001: driver cleanup Joshua Crofts via B4 Relay
                   ` (8 preceding siblings ...)
  2026-05-12 10:57 ` [PATCH v2 09/10] iio: light: opt3001: switch driver to managed resources Joshua Crofts via B4 Relay
@ 2026-05-12 10:57 ` Joshua Crofts via B4 Relay
  9 siblings, 0 replies; 18+ messages in thread
From: Joshua Crofts via B4 Relay @ 2026-05-12 10:57 UTC (permalink / raw)
  To: Jonathan Cameron, David Lechner, Nuno Sá, Andy Shevchenko,
	Alexander Koch, Michael Hornung
  Cc: linux-iio, linux-kernel, Joshua Crofts

From: Joshua Crofts <joshua.crofts1@gmail.com>

Add comment to mutex per checkpatch.pl report.

No functional change.

Signed-off-by: Joshua Crofts <joshua.crofts1@gmail.com>
---
 drivers/iio/light/opt3001.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/iio/light/opt3001.c b/drivers/iio/light/opt3001.c
index 1319e5941b66bd82e4dc2badf5ea27cacbcfd54a..81afee6993d08b1126f07b1c63c3d3496d8b380c 100644
--- a/drivers/iio/light/opt3001.c
+++ b/drivers/iio/light/opt3001.c
@@ -104,6 +104,7 @@ struct opt3001 {
 	struct i2c_client	*client;
 	struct device		*dev;
 
+	/* Mutex for ensuring one executed command at a time */
 	struct mutex		lock;
 	bool			ok_to_ignore_lock;
 	bool			result_ready;

-- 
2.47.3



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

* Re: [PATCH v2 04/10] iio: light: opt3001: use local struct device and i2c_client variables
  2026-05-12 10:57 ` [PATCH v2 04/10] iio: light: opt3001: use local struct device and i2c_client variables Joshua Crofts via B4 Relay
@ 2026-05-12 11:09   ` Andy Shevchenko
  2026-05-12 11:13     ` Joshua Crofts
  0 siblings, 1 reply; 18+ messages in thread
From: Andy Shevchenko @ 2026-05-12 11:09 UTC (permalink / raw)
  To: joshua.crofts1
  Cc: Jonathan Cameron, David Lechner, Nuno Sá, Andy Shevchenko,
	Alexander Koch, Michael Hornung, linux-iio, linux-kernel

On Tue, May 12, 2026 at 12:57:24PM +0200, Joshua Crofts via B4 Relay wrote:

> Switch the driver to use local variables for struct device and struct
> i2c_client to improve code style.
> 
> While at it, ensure that parentheses alignment is correct in functions
> that were changed in this patch.

> No functional change.

Right, but what I meant is to drop dev member from struct opt3001 completely
and derive it from client. Maybe it's done in the following patches? Haven't
seen them yet.

...

> +	dev_info(dev, "Found %c%c OPT%04x\n", manufacturer[0], manufacturer[1],
> +		 device_id);

Ideally this %c%c needs to be replaced with %2pE (this is not in the scope of
the patch, though).

-- 
With Best Regards,
Andy Shevchenko



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

* Re: [PATCH v2 04/10] iio: light: opt3001: use local struct device and i2c_client variables
  2026-05-12 11:09   ` Andy Shevchenko
@ 2026-05-12 11:13     ` Joshua Crofts
  2026-05-12 11:27       ` Andy Shevchenko
  0 siblings, 1 reply; 18+ messages in thread
From: Joshua Crofts @ 2026-05-12 11:13 UTC (permalink / raw)
  To: Andy Shevchenko
  Cc: Jonathan Cameron, David Lechner, Nuno Sá, Andy Shevchenko,
	Alexander Koch, Michael Hornung, linux-iio, linux-kernel

On Tue, 12 May 2026 at 13:09, Andy Shevchenko
<andriy.shevchenko@linux.intel.com> wrote:
>
> On Tue, May 12, 2026 at 12:57:24PM +0200, Joshua Crofts via B4 Relay wrote:
>
> > Switch the driver to use local variables for struct device and struct
> > i2c_client to improve code style.
> >
> > While at it, ensure that parentheses alignment is correct in functions
> > that were changed in this patch.
>
> > No functional change.
>
> Right, but what I meant is to drop dev member from struct opt3001 completely
> and derive it from client. Maybe it's done in the following patches? Haven't

Ohhh, now I understand. Unfortunately you'll be disappointed, my patches don't
deal with this...

-- 
Kind regards

CJD

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

* Re: [PATCH v2 04/10] iio: light: opt3001: use local struct device and i2c_client variables
  2026-05-12 11:13     ` Joshua Crofts
@ 2026-05-12 11:27       ` Andy Shevchenko
  0 siblings, 0 replies; 18+ messages in thread
From: Andy Shevchenko @ 2026-05-12 11:27 UTC (permalink / raw)
  To: Joshua Crofts
  Cc: Jonathan Cameron, David Lechner, Nuno Sá, Andy Shevchenko,
	Alexander Koch, Michael Hornung, linux-iio, linux-kernel

On Tue, May 12, 2026 at 01:13:32PM +0200, Joshua Crofts wrote:
> On Tue, 12 May 2026 at 13:09, Andy Shevchenko
> <andriy.shevchenko@linux.intel.com> wrote:
> >
> > On Tue, May 12, 2026 at 12:57:24PM +0200, Joshua Crofts via B4 Relay wrote:
> >
> > > Switch the driver to use local variables for struct device and struct
> > > i2c_client to improve code style.
> > >
> > > While at it, ensure that parentheses alignment is correct in functions
> > > that were changed in this patch.
> >
> > > No functional change.
> >
> > Right, but what I meant is to drop dev member from struct opt3001 completely
> > and derive it from client. Maybe it's done in the following patches? Haven't
> 
> Ohhh, now I understand. Unfortunately you'll be disappointed, my patches don't
> deal with this...

No problem, you can do it in a followup (or next version, let's see how review
will go).

-- 
With Best Regards,
Andy Shevchenko



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

* Re: [PATCH v2 09/10] iio: light: opt3001: switch driver to managed resources
  2026-05-12 10:57 ` [PATCH v2 09/10] iio: light: opt3001: switch driver to managed resources Joshua Crofts via B4 Relay
@ 2026-05-12 14:26   ` Jonathan Cameron
  2026-05-12 14:32     ` Joshua Crofts
  0 siblings, 1 reply; 18+ messages in thread
From: Jonathan Cameron @ 2026-05-12 14:26 UTC (permalink / raw)
  To: Joshua Crofts via B4 Relay
  Cc: joshua.crofts1, David Lechner, Nuno Sá, Andy Shevchenko,
	Alexander Koch, Michael Hornung, linux-iio, linux-kernel

On Tue, 12 May 2026 12:57:29 +0200
Joshua Crofts via B4 Relay <devnull+joshua.crofts1.gmail.com@kernel.org> wrote:

> From: Joshua Crofts <joshua.crofts1@gmail.com>
> 
> Move the driver to use devm_* functions to automate resource
> management and simplify error handling. This also allows removal
> of the opt3001_remove() function.
> 
> Signed-off-by: Joshua Crofts <joshua.crofts1@gmail.com>
Some trivial stuff inline.  I'll probably wait for sashiko to catch up with
it's backlog and get to this one.  If nothing comes up there or in other reviews
I'm fine tweaking the stuff below whilst applying the series.

Jonathan

> ---
>  drivers/iio/light/opt3001.c | 75 +++++++++++++++++++++++----------------------
>  1 file changed, 39 insertions(+), 36 deletions(-)
> 
> diff --git a/drivers/iio/light/opt3001.c b/drivers/iio/light/opt3001.c
> index 39ea60c0af2c1ec7473d49b73778cac1f9bb6086..1319e5941b66bd82e4dc2badf5ea27cacbcfd54a 100644
> --- a/drivers/iio/light/opt3001.c
> +++ b/drivers/iio/light/opt3001.c
> @@ -702,6 +702,31 @@ static int opt3001_read_id(struct opt3001 *opt)
>  	return 0;
>  }
>  
> +static void opt3001_power_off(void *data)
> +{
> +	struct opt3001 *opt = data;
> +	struct i2c_client *client = opt->client;
> +	struct device *dev = opt->dev;
> +
Really trivial but why the blank line here?  If nothing else comes up
I might bother dropping it whilst picking up the series.

> +	int ret;
> +	u16 reg;
Obviously not a change you made - but none the less reg is a bad name.
It is often used for register address rather than value.  So better as
regval.  Again maybe I'll tweak this if nothing comes up but if you
do another version for other reasons nice to change it.

> +
> +	ret = i2c_smbus_read_word_swapped(client, OPT3001_CONFIGURATION);
> +	if (ret < 0) {
> +		dev_err(dev, "failed to read register %02x\n",
> +			OPT3001_CONFIGURATION);
> +		return;
> +	}
> +
> +	reg = ret;
> +	opt3001_set_mode(opt, &reg, OPT3001_CONFIGURATION_M_SHUTDOWN);
> +
> +	ret = i2c_smbus_write_word_swapped(client, OPT3001_CONFIGURATION, reg);
> +	if (ret < 0)
> +		dev_err(dev, "failed to write to register %02x\n",
> +			OPT3001_CONFIGURATION);
> +}
> +
>  static int opt3001_configure(struct opt3001 *opt)
>  {
>  	struct i2c_client *client = opt->client;
> @@ -740,6 +765,11 @@ static int opt3001_configure(struct opt3001 *opt)
>  		return dev_err_probe(dev, ret, "failed to write register %02x\n",
>  				     OPT3001_CONFIGURATION);
>  
> +	ret = devm_add_action_or_reset(dev, opt3001_power_off, opt);
> +	if (ret)
> +		return dev_err_probe(dev, ret,
> +				     "failed to register power off function\n");
> +
>  	ret = i2c_smbus_read_word_swapped(client, OPT3001_LOW_LIMIT);
>  	if (ret < 0)
>  		return dev_err_probe(dev, ret, "failed to read register %02x\n",
> @@ -834,7 +864,10 @@ static int opt3001_probe(struct i2c_client *client)
>  	opt->dev = dev;
>  	opt->chip_info = i2c_get_match_data(client);
>  
> -	mutex_init(&opt->lock);
> +	ret = devm_mutex_init(dev, &opt->lock);
> +	if (ret)
> +		return ret;
> +
>  	init_waitqueue_head(&opt->result_ready_queue);
>  	i2c_set_clientdata(client, iio);
>  
> @@ -856,13 +889,12 @@ static int opt3001_probe(struct i2c_client *client)
>  
>  	/* Make use of INT pin only if valid IRQ no. is given */
>  	if (irq > 0) {
> -		ret = request_threaded_irq(irq, NULL, opt3001_irq,
> -					   IRQF_TRIGGER_FALLING | IRQF_ONESHOT,
> -					   "opt3001", iio);
> +		ret = devm_request_threaded_irq(dev, irq, NULL, opt3001_irq,
> +						IRQF_TRIGGER_FALLING | IRQF_ONESHOT,
> +						"opt3001", iio);
>  		if (ret)
> -			return dev_err_probe(dev, ret,
> -					     "failed to request IRQ #%d\n",
> -					     irq);
> +			return ret;
> +
>  		opt->use_irq = true;
>  	} else {
>  		dev_dbg(dev, "enabling interrupt-less operation\n");
> @@ -876,34 +908,6 @@ static int opt3001_probe(struct i2c_client *client)
>  	return 0;
>  }
>  
> -static void opt3001_remove(struct i2c_client *client)
> -{
> -	struct iio_dev *iio = i2c_get_clientdata(client);
> -	struct opt3001 *opt = iio_priv(iio);
> -	struct device *dev = opt->dev;
> -	int ret;
> -	u16 reg;
> -
> -	if (opt->use_irq)
> -		free_irq(client->irq, iio);
> -
> -	ret = i2c_smbus_read_word_swapped(client, OPT3001_CONFIGURATION);
> -	if (ret < 0) {
> -		dev_err(dev, "failed to read register %02x\n",
> -			OPT3001_CONFIGURATION);
> -		return;
> -	}
> -
> -	reg = ret;
> -	opt3001_set_mode(opt, &reg, OPT3001_CONFIGURATION_M_SHUTDOWN);
> -
> -	ret = i2c_smbus_write_word_swapped(client, OPT3001_CONFIGURATION, reg);
> -	if (ret < 0) {
> -		dev_err(dev, "failed to write register %02x\n",
> -			OPT3001_CONFIGURATION);
> -	}
> -}
> -
>  static const struct opt3001_chip_info opt3001_chip_information = {
>  	.channels = &opt3001_channels,
>  	.chan_type = IIO_LIGHT,
> @@ -942,7 +946,6 @@ MODULE_DEVICE_TABLE(of, opt3001_of_match);
>  
>  static struct i2c_driver opt3001_driver = {
>  	.probe = opt3001_probe,
> -	.remove = opt3001_remove,
>  	.id_table = opt3001_id,
>  
>  	.driver = {
> 


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

* Re: [PATCH v2 09/10] iio: light: opt3001: switch driver to managed resources
  2026-05-12 14:26   ` Jonathan Cameron
@ 2026-05-12 14:32     ` Joshua Crofts
  0 siblings, 0 replies; 18+ messages in thread
From: Joshua Crofts @ 2026-05-12 14:32 UTC (permalink / raw)
  To: Jonathan Cameron
  Cc: Joshua Crofts via B4 Relay, David Lechner, Nuno Sá,
	Andy Shevchenko, Alexander Koch, Michael Hornung, linux-iio,
	linux-kernel

On Tue, 12 May 2026 at 16:26, Jonathan Cameron <jic23@kernel.org> wrote:
>
> On Tue, 12 May 2026 12:57:29 +0200
> Joshua Crofts via B4 Relay <devnull+joshua.crofts1.gmail.com@kernel.org> wrote:
>
> > From: Joshua Crofts <joshua.crofts1@gmail.com>
> >
> > Move the driver to use devm_* functions to automate resource
> > management and simplify error handling. This also allows removal
> > of the opt3001_remove() function.
> >
> > Signed-off-by: Joshua Crofts <joshua.crofts1@gmail.com>
> Some trivial stuff inline.  I'll probably wait for sashiko to catch up with
> it's backlog and get to this one.  If nothing comes up there or in other reviews
> I'm fine tweaking the stuff below whilst applying the series.
>
> Jonathan
>
> > ---
> >  drivers/iio/light/opt3001.c | 75 +++++++++++++++++++++++----------------------
> >  1 file changed, 39 insertions(+), 36 deletions(-)
> >
> > diff --git a/drivers/iio/light/opt3001.c b/drivers/iio/light/opt3001.c
> > index 39ea60c0af2c1ec7473d49b73778cac1f9bb6086..1319e5941b66bd82e4dc2badf5ea27cacbcfd54a 100644
> > --- a/drivers/iio/light/opt3001.c
> > +++ b/drivers/iio/light/opt3001.c
> > @@ -702,6 +702,31 @@ static int opt3001_read_id(struct opt3001 *opt)
> >       return 0;
> >  }
> >
> > +static void opt3001_power_off(void *data)
> > +{
> > +     struct opt3001 *opt = data;
> > +     struct i2c_client *client = opt->client;
> > +     struct device *dev = opt->dev;
> > +
> Really trivial but why the blank line here?  If nothing else comes up
> I might bother dropping it whilst picking up the series.

Oh, that must've been an accident.

> > +     int ret;
> > +     u16 reg;
> Obviously not a change you made - but none the less reg is a bad name.
> It is often used for register address rather than value.  So better as
> regval.  Again maybe I'll tweak this if nothing comes up but if you
> do another version for other reasons nice to change it.

Fair enough, reg is a bit of a bad name for a variable. As per Sashiko
catching up - it has 10 pages of entries to go, so here's hoping it goes
fast.

-- 
Kind regards

CJD

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

* Re: [PATCH v2 06/10] iio: light: opt3001: localize for loop iterator
  2026-05-12 10:57 ` [PATCH v2 06/10] iio: light: opt3001: localize for loop iterator Joshua Crofts via B4 Relay
@ 2026-05-12 15:40   ` Andy Shevchenko
  0 siblings, 0 replies; 18+ messages in thread
From: Andy Shevchenko @ 2026-05-12 15:40 UTC (permalink / raw)
  To: joshua.crofts1
  Cc: Jonathan Cameron, David Lechner, Nuno Sá, Andy Shevchenko,
	Alexander Koch, Michael Hornung, linux-iio, linux-kernel

On Tue, May 12, 2026 at 12:57:26PM +0200, Joshua Crofts via B4 Relay wrote:

> Localize loop iterator to tighten scope and improve code style
> per checkpatch.pl report.
> 
> No functional change.

...

>  		const struct opt3001_scale *scale = &(*opt->chip_info->scales)[i];


This is an interesting way of writing &opt->chip_info->scales[i] ?

-- 
With Best Regards,
Andy Shevchenko



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

* Re: [PATCH v2 07/10] iio: light: opt3001: prefer dev_err_probe()
  2026-05-12 10:57 ` [PATCH v2 07/10] iio: light: opt3001: prefer dev_err_probe() Joshua Crofts via B4 Relay
@ 2026-05-12 15:43   ` Andy Shevchenko
  0 siblings, 0 replies; 18+ messages in thread
From: Andy Shevchenko @ 2026-05-12 15:43 UTC (permalink / raw)
  To: joshua.crofts1
  Cc: Jonathan Cameron, David Lechner, Nuno Sá, Andy Shevchenko,
	Alexander Koch, Michael Hornung, linux-iio, linux-kernel

On Tue, May 12, 2026 at 12:57:27PM +0200, Joshua Crofts via B4 Relay wrote:

> Switch driver to use dev_err_probe() to unify
> error messages generated in *_probe() and probe path functions.

These lines are not balanced in length...


...

> -		return dev_err(dev, "failed to register IIO device\n");
> +		return dev_err_probe(dev, ret,
> +				     "failed to register IIO device\n");


I believe a single line in this and similar cases is fine

		return dev_err_probe(dev, ret, "failed to register IIO device\n");

(it's only 82 characters).

-- 
With Best Regards,
Andy Shevchenko



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

end of thread, other threads:[~2026-05-12 15:46 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-05-12 10:57 [PATCH v2 00/10] iio: light: opt3001: driver cleanup Joshua Crofts via B4 Relay
2026-05-12 10:57 ` [PATCH v2 01/10] iio: light: opt3001: move device registration to end of probe() Joshua Crofts via B4 Relay
2026-05-12 10:57 ` [PATCH v2 02/10] iio: light: opt3001: make headers conform to iwyu Joshua Crofts via B4 Relay
2026-05-12 10:57 ` [PATCH v2 03/10] iio: light: opt3001: use macros from bits.h header Joshua Crofts via B4 Relay
2026-05-12 10:57 ` [PATCH v2 04/10] iio: light: opt3001: use local struct device and i2c_client variables Joshua Crofts via B4 Relay
2026-05-12 11:09   ` Andy Shevchenko
2026-05-12 11:13     ` Joshua Crofts
2026-05-12 11:27       ` Andy Shevchenko
2026-05-12 10:57 ` [PATCH v2 05/10] iio: light: opt3001: ensure correct parenthesis alignment Joshua Crofts via B4 Relay
2026-05-12 10:57 ` [PATCH v2 06/10] iio: light: opt3001: localize for loop iterator Joshua Crofts via B4 Relay
2026-05-12 15:40   ` Andy Shevchenko
2026-05-12 10:57 ` [PATCH v2 07/10] iio: light: opt3001: prefer dev_err_probe() Joshua Crofts via B4 Relay
2026-05-12 15:43   ` Andy Shevchenko
2026-05-12 10:57 ` [PATCH v2 08/10] iio: light: opt3001: move driver to guard(mutex)() use Joshua Crofts via B4 Relay
2026-05-12 10:57 ` [PATCH v2 09/10] iio: light: opt3001: switch driver to managed resources Joshua Crofts via B4 Relay
2026-05-12 14:26   ` Jonathan Cameron
2026-05-12 14:32     ` Joshua Crofts
2026-05-12 10:57 ` [PATCH v2 10/10] iio: light: opt3001: add comment to mutex Joshua Crofts via B4 Relay

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