From nobody Sun May 24 21:38:36 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 279533822A7; Thu, 21 May 2026 09:55:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779357343; cv=none; b=Sgoo+A+xm4YP5sljrd71HLUW6ropESW1S9BIpB7/hKhNak5yni+68TNe9BJbD6rUl2/5q7d+PeZByRfaQ3U9PKJnuClBitiD/wTuWbt0hSaNGX7H1mlxKoxjJti93XvY1Hqp1kzm43j1oAnORtrSzYakEAWU5EdtuNdcvvd29do= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779357343; c=relaxed/simple; bh=KCRa3TW27Gjb+lOkL2E1dbv/STupXKkCrH3SSwUpCac=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=A7xOR5vmtCs0O2ClZjoeHsYMfPsUBOjAtq/I8N4yR40zuXg7BHSMjN2KIUXbnBHdgS8JQM/oKhPg7jp1Vk6xOBbK1+iRX/K/HVMzVwNTkVNJmZPZKVqk+NIAEtG9RgD7ReRYTly4qmIQCJ+PLUrGF2kD/waEdWPz2lMXgfQS69k= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=cnOgIdnv; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="cnOgIdnv" Received: by smtp.kernel.org (Postfix) with ESMTPS id D8F07C2BCB9; Thu, 21 May 2026 09:55:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1779357342; bh=KCRa3TW27Gjb+lOkL2E1dbv/STupXKkCrH3SSwUpCac=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=cnOgIdnvJuAN6S2Q8oP6puktcPZA/TYE0Hyv3wJpuxGc7aklOedj8QO93MkDzijP1 fMnY+XLvCl0N91W8WG4J2DbJ56Yuq7Au9UFk7SX7qW99TkzmU0TOBFaxfNagdLUBxt 8llWCyJoxxg1iK22vTq4j0GNuW9va1dTzVopnLU/xQppJMxNn/ikPg1PvUFRAO+N3h VUAAi/fMMpxKk8rTQXBuYtS7gnFt18UuvhsXWoNwBv19GiCe/qc1I3Y30AIwQqBouY qEkhwGnE6GJAL0Z1CFZYQJJx/V3paoC/O56uE/Re8/I2kYfcStzVx6oGRo4jWJAWTV /Y/Df8RtKVNRg== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id C2297CD5BA4; Thu, 21 May 2026 09:55:42 +0000 (UTC) From: Joshua Crofts via B4 Relay Date: Thu, 21 May 2026 11:55:38 +0200 Subject: [PATCH v3 1/7] iio: light: opt3001: move device registration to end of probe() Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260521-opt3001-cleanup-v3-1-820169dec8c3@gmail.com> References: <20260521-opt3001-cleanup-v3-0-820169dec8c3@gmail.com> In-Reply-To: <20260521-opt3001-cleanup-v3-0-820169dec8c3@gmail.com> To: Jonathan Cameron , David Lechner , =?utf-8?q?Nuno_S=C3=A1?= , Andy Shevchenko , Alexander Koch , Michael Hornung Cc: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, Joshua Crofts , Sashiko X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1779357341; l=1994; i=joshua.crofts1@gmail.com; s=20260422; h=from:subject:message-id; bh=ZczGFIQbqXOXLVlXU5uBirkleYkJeoHuapeGlc+EZuQ=; b=6EuN+QHD5HXCI+/JLhT3u5i9ocSVNtKKGc+Z1MIW6vDkxxv+2sbL/6Yn2gJnk5iqAQUNw6ZPj V71NdptTC1hCPp8lFO7IITMQQy1aoKNfPGLB7Na2wPAUDFwjbNm4hF0 X-Developer-Key: i=joshua.crofts1@gmail.com; a=ed25519; pk=Xd+UVoRPiiI0K3LHQ2XIcXmO0jvVuFTv9eTx3lgBphI= X-Endpoint-Received: by B4 Relay for joshua.crofts1@gmail.com/20260422 with auth_id=746 X-Original-From: Joshua Crofts Reply-To: joshua.crofts1@gmail.com From: Joshua Crofts Move IIO device registration to the end of the probe() function to prevent a potential race where userspace can interact with the device before IRQ is configured properly. Additionally, switch devm_iio_device_register() to its unmanaged counterpart as current driver implementation mixes managed and unmanaged resources, causing potential resource leaks. Also, add iio_device_unregister() to remove() function to correctly handle teardown. Fixes: ac663db3678a ("iio: light: opt3001: enable operation w/o IRQ") Reported-by: Jonathan Cameron Reported-by: Sashiko Closes: https://sashiko.dev/#/patchset/20260511-opt3001-cleanup-v1-0-f7879d= c3455c%40gmail.com?part=3D7 Signed-off-by: Joshua Crofts --- drivers/iio/light/opt3001.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/drivers/iio/light/opt3001.c b/drivers/iio/light/opt3001.c index dac3d3818d0a01b4ca53106fa38bb54b8c5373d4..fe53a072b21ddaa26a23c76e828= 97fdbc1e4d846 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 =3D INDIO_DIRECT_MODE; iio->info =3D &opt3001_info; =20 - ret =3D 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 =3D request_threaded_irq(irq, NULL, opt3001_irq, @@ -894,7 +888,7 @@ static int opt3001_probe(struct i2c_client *client) dev_dbg(opt->dev, "enabling interrupt-less operation\n"); } =20 - return 0; + return iio_device_register(iio); } =20 static void opt3001_remove(struct i2c_client *client) @@ -904,6 +898,8 @@ static void opt3001_remove(struct i2c_client *client) int ret; u16 reg; =20 + iio_device_unregister(iio); + if (opt->use_irq) free_irq(client->irq, iio); =20 --=20 2.47.3 From nobody Sun May 24 21:38:36 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 278993806AA; Thu, 21 May 2026 09:55:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779357343; cv=none; b=Dq8D/Yp5W2mbMAY67TRnlRONEmZZA/Lw56ZCvOnXC9Gv3cjtr0RleTGzH7DJqsskAJUG22/3pYVFEFbQJ722Mk4xUXsjN0kquoX19J4T4t3lflAanCm186wZNV2YNB9xWfYOZggaO73ajX3w6Zt3JH5/kvHRiFia9a6EuwPQTkE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779357343; c=relaxed/simple; bh=oh6kF0J1mgrhmC7s6E3k0lNkRzs7Y77EwtYGCUsvosc=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=ha170pi0EU0/gwcO9deb40trtN4/BaOGrwF+8vHhxNaioXxcMqo1T7+zr9yU5TVIdQtFPiOqHHK/we2FLGGWLIuviqgbGZlRFllQIJLFYFXYvbWZTUwbWktG/Lu0sdoGs2mSEldDQ97+zYt0+A/+0PcyxKyM+NyDSlfT+nfIl2o= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=QHxM8QsV; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="QHxM8QsV" Received: by smtp.kernel.org (Postfix) with ESMTPS id E6C27C2BCC6; Thu, 21 May 2026 09:55:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1779357342; bh=oh6kF0J1mgrhmC7s6E3k0lNkRzs7Y77EwtYGCUsvosc=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=QHxM8QsVOajrH3WU7iv6qC39Y53nfQ1idt0SdBUUcyM1WknoWXD799KjC1lgxEFGN cf8hNv74VOnipJj6T5/46UjUafNKRklSufybLpo7NyOSd68zTXWuGr1LWAPbKTH0eh nSERn4GorP9uvY0wG+EYbNmftr5TIo+JH6obXOVZlJ+T+PZR21qkXUbBRvV6757/QS NSzoacGdCNfSdGbuHwc93/uUF6gQFqH5HPiPTShnM9A8bAQ7dCEcz5zk7+g1lhPwzf ahUveuVetViMmPxovFRDcbPK4fXoLEVGrmTVnh16iMpfZ9vyLyCdEpi33+aGUM5CYw o3zifEJv23tng== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id D8805CD5BAC; Thu, 21 May 2026 09:55:42 +0000 (UTC) From: Joshua Crofts via B4 Relay Date: Thu, 21 May 2026 11:55:39 +0200 Subject: [PATCH v3 2/7] iio: light: opt3001: use local struct device and i2c_client variables Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260521-opt3001-cleanup-v3-2-820169dec8c3@gmail.com> References: <20260521-opt3001-cleanup-v3-0-820169dec8c3@gmail.com> In-Reply-To: <20260521-opt3001-cleanup-v3-0-820169dec8c3@gmail.com> To: Jonathan Cameron , David Lechner , =?utf-8?q?Nuno_S=C3=A1?= , Andy Shevchenko , Alexander Koch , Michael Hornung Cc: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, Joshua Crofts , Andy Shevchenko X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1779357341; l=13711; i=joshua.crofts1@gmail.com; s=20260422; h=from:subject:message-id; bh=KeQZYDuMseJbjGBQbnMphGWz8ys8FsC4yi93yHRm4cY=; b=re8AL/CBr4UimuLAxRX5Q+lcYtxROR9+fUkSQRBfnx6DUq5/GqB72ln3c5boYyJl1pELb02SY s3RZlCEF3JUAkIyVsNX0e1u/typY7XDuka432pzhZOcnGiSS03knwPr X-Developer-Key: i=joshua.crofts1@gmail.com; a=ed25519; pk=Xd+UVoRPiiI0K3LHQ2XIcXmO0jvVuFTv9eTx3lgBphI= X-Endpoint-Received: by B4 Relay for joshua.crofts1@gmail.com/20260422 with auth_id=746 X-Original-From: Joshua Crofts Reply-To: joshua.crofts1@gmail.com From: Joshua Crofts Switch the driver to use local variables for struct device and struct i2c_client and remove struct device member from struct opt3001, as the former can be derived from struct client. While at it, ensure that parentheses alignment is correct in functions that were changed in this patch. No functional change. Suggested-by: Andy Shevchenko Signed-off-by: Joshua Crofts --- drivers/iio/light/opt3001.c | 149 +++++++++++++++++++++++-----------------= ---- 1 file changed, 78 insertions(+), 71 deletions(-) diff --git a/drivers/iio/light/opt3001.c b/drivers/iio/light/opt3001.c index fe53a072b21ddaa26a23c76e82897fdbc1e4d846..5d88a697c245347bcb982544603= 08fc9a9f375f4 100644 --- a/drivers/iio/light/opt3001.c +++ b/drivers/iio/light/opt3001.c @@ -101,7 +101,6 @@ struct opt3001_chip_info { =20 struct opt3001 { struct i2c_client *client; - struct device *dev; =20 struct mutex lock; bool ok_to_ignore_lock; @@ -313,6 +312,8 @@ static const struct iio_chan_spec opt3002_channels[] = =3D { =20 static int opt3001_get_processed(struct opt3001 *opt, int *val, int *val2) { + struct i2c_client *client =3D opt->client; + struct device *dev =3D &client->dev; int ret; u16 mantissa; u16 reg; @@ -326,12 +327,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 =3D i2c_smbus_write_word_swapped(opt->client, - OPT3001_LOW_LIMIT, - OPT3001_LOW_LIMIT_EOC_ENABLE); + ret =3D 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; } =20 @@ -343,21 +344,20 @@ static int opt3001_get_processed(struct opt3001 *opt,= int *val, int *val2) opt->result_ready =3D false; =20 /* Configure for single-conversion mode and start a new conversion */ - ret =3D i2c_smbus_read_word_swapped(opt->client, OPT3001_CONFIGURATION); + ret =3D 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; } =20 reg =3D ret; opt3001_set_mode(opt, ®, OPT3001_CONFIGURATION_M_SINGLE); =20 - ret =3D i2c_smbus_write_word_swapped(opt->client, OPT3001_CONFIGURATION, - reg); + ret =3D 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; } =20 @@ -375,10 +375,9 @@ static int opt3001_get_processed(struct opt3001 *opt, = int *val, int *val2) msleep(timeout); =20 /* Check result ready flag */ - ret =3D i2c_smbus_read_word_swapped(opt->client, - OPT3001_CONFIGURATION); + ret =3D 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 +388,9 @@ static int opt3001_get_processed(struct opt3001 *opt, i= nt *val, int *val2) } =20 /* Obtain value */ - ret =3D i2c_smbus_read_word_swapped(opt->client, OPT3001_RESULT); + ret =3D 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 +415,12 @@ static int opt3001_get_processed(struct opt3001 *opt,= int *val, int *val2) * bit-overlap and therefore can't be done. */ value =3D (opt->low_thresh_exp << 12) | opt->low_thresh_mantissa; - ret =3D i2c_smbus_write_word_swapped(opt->client, + ret =3D 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 +443,15 @@ static int opt3001_get_int_time(struct opt3001 *opt, = int *val, int *val2) =20 static int opt3001_set_int_time(struct opt3001 *opt, int time) { + struct i2c_client *client =3D opt->client; + struct device *dev =3D &client->dev; int ret; u16 reg; =20 - ret =3D i2c_smbus_read_word_swapped(opt->client, OPT3001_CONFIGURATION); + ret =3D 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; } =20 @@ -469,8 +470,7 @@ static int opt3001_set_int_time(struct opt3001 *opt, in= t time) return -EINVAL; } =20 - return i2c_smbus_write_word_swapped(opt->client, OPT3001_CONFIGURATION, - reg); + return i2c_smbus_write_word_swapped(client, OPT3001_CONFIGURATION, reg); } =20 static int opt3001_read_raw(struct iio_dev *iio, @@ -565,6 +565,8 @@ static int opt3001_write_event_value(struct iio_dev *ii= o, int val, int val2) { struct opt3001 *opt =3D iio_priv(iio); + struct i2c_client *client =3D opt->client; + struct device *dev =3D &client->dev; int ret; int whole; int integer; @@ -583,7 +585,7 @@ static int opt3001_write_event_value(struct iio_dev *ii= o, =20 ret =3D 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; } =20 @@ -611,9 +613,9 @@ static int opt3001_write_event_value(struct iio_dev *ii= o, goto err; } =20 - ret =3D i2c_smbus_write_word_swapped(opt->client, reg, value); + ret =3D 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; } =20 @@ -637,6 +639,8 @@ static int opt3001_write_event_config(struct iio_dev *i= io, enum iio_event_direction dir, bool state) { struct opt3001 *opt =3D iio_priv(iio); + struct i2c_client *client =3D opt->client; + struct device *dev =3D &client->dev; int ret; u16 mode; u16 reg; @@ -652,21 +656,20 @@ static int opt3001_write_event_config(struct iio_dev = *iio, mode =3D state ? OPT3001_CONFIGURATION_M_CONTINUOUS : OPT3001_CONFIGURATION_M_SHUTDOWN; =20 - ret =3D i2c_smbus_read_word_swapped(opt->client, OPT3001_CONFIGURATION); + ret =3D 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; } =20 reg =3D ret; opt3001_set_mode(opt, ®, mode); =20 - ret =3D i2c_smbus_write_word_swapped(opt->client, OPT3001_CONFIGURATION, - reg); + ret =3D 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; } =20 @@ -688,44 +691,48 @@ static const struct iio_info opt3001_info =3D { =20 static int opt3001_read_id(struct opt3001 *opt) { + struct i2c_client *client =3D opt->client; + struct device *dev =3D &client->dev; char manufacturer[2]; u16 device_id; int ret; =20 - ret =3D i2c_smbus_read_word_swapped(opt->client, OPT3001_MANUFACTURER_ID); + ret =3D 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; } =20 manufacturer[0] =3D ret >> 8; manufacturer[1] =3D ret & 0xff; =20 - ret =3D i2c_smbus_read_word_swapped(opt->client, OPT3001_DEVICE_ID); + ret =3D 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; } =20 device_id =3D ret; =20 - 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); =20 return 0; } =20 static int opt3001_configure(struct opt3001 *opt) { + struct i2c_client *client =3D opt->client; + struct device *dev =3D &client->dev; int ret; u16 reg; =20 - ret =3D i2c_smbus_read_word_swapped(opt->client, OPT3001_CONFIGURATION); + ret =3D 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; } =20 @@ -750,28 +757,27 @@ static int opt3001_configure(struct opt3001 *opt) reg &=3D ~OPT3001_CONFIGURATION_ME; reg &=3D ~OPT3001_CONFIGURATION_FC_MASK; =20 - ret =3D i2c_smbus_write_word_swapped(opt->client, OPT3001_CONFIGURATION, - reg); + ret =3D 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; } =20 - ret =3D i2c_smbus_read_word_swapped(opt->client, OPT3001_LOW_LIMIT); + ret =3D 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; } =20 opt->low_thresh_mantissa =3D OPT3001_REG_MANTISSA(ret); opt->low_thresh_exp =3D OPT3001_REG_EXPONENT(ret); =20 - ret =3D i2c_smbus_read_word_swapped(opt->client, OPT3001_HIGH_LIMIT); + ret =3D 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; } =20 @@ -785,6 +791,8 @@ static irqreturn_t opt3001_irq(int irq, void *_iio) { struct iio_dev *iio =3D _iio; struct opt3001 *opt =3D iio_priv(iio); + struct i2c_client *client =3D opt->client; + struct device *dev =3D &client->dev; int ret; bool wake_result_ready_queue =3D false; enum iio_chan_type chan_type =3D opt->chip_info->chan_type; @@ -793,10 +801,10 @@ static irqreturn_t opt3001_irq(int irq, void *_iio) if (!ok_to_ignore_lock) mutex_lock(&opt->lock); =20 - ret =3D i2c_smbus_read_word_swapped(opt->client, OPT3001_CONFIGURATION); + ret =3D 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; } =20 @@ -815,10 +823,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 =3D i2c_smbus_read_word_swapped(opt->client, OPT3001_RESULT); + ret =3D 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 =3D ret; @@ -851,7 +859,6 @@ static int opt3001_probe(struct i2c_client *client) =20 opt =3D iio_priv(iio); opt->client =3D client; - opt->dev =3D dev; opt->chip_info =3D i2c_get_match_data(client); =20 mutex_init(&opt->lock); @@ -885,7 +892,7 @@ static int opt3001_probe(struct i2c_client *client) } opt->use_irq =3D true; } else { - dev_dbg(opt->dev, "enabling interrupt-less operation\n"); + dev_dbg(dev, "enabling interrupt-less operation\n"); } =20 return iio_device_register(iio); @@ -895,6 +902,7 @@ static void opt3001_remove(struct i2c_client *client) { struct iio_dev *iio =3D i2c_get_clientdata(client); struct opt3001 *opt =3D iio_priv(iio); + struct device *dev =3D &client->dev; int ret; u16 reg; =20 @@ -903,21 +911,20 @@ static void opt3001_remove(struct i2c_client *client) if (opt->use_irq) free_irq(client->irq, iio); =20 - ret =3D i2c_smbus_read_word_swapped(opt->client, OPT3001_CONFIGURATION); + ret =3D 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; } =20 reg =3D ret; opt3001_set_mode(opt, ®, OPT3001_CONFIGURATION_M_SHUTDOWN); =20 - ret =3D i2c_smbus_write_word_swapped(opt->client, OPT3001_CONFIGURATION, - reg); + ret =3D 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); } } =20 --=20 2.47.3 From nobody Sun May 24 21:38:36 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2C01F3822B1; Thu, 21 May 2026 09:55:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779357343; cv=none; b=Nmel8kjXAn643ns1DNz2qphahFxQDcMeUa+2ZSM4sYOztJfP5+fPxeFnMnPoHDpxuHZVU5eXBqGpoPLVECqZSQSM/u9HaeMbZ9+V3/5OGlONdKTOVLsjlh/154336O3lD8CuegvFdZtaciYI1tIiTA+Xov2yqjCbHtfSQTxKdVk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779357343; c=relaxed/simple; bh=o+1o/EQ7dZbjpAmwPQc57CtnsjDw0zwvAmz/0s35h+A=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=C/L8jy6A4I1DWMm7WKG0DRs/36Srq/EY64V13wC9TjTOlMNSqcP54K7F/oRYy3VkQq1iQnIQ7a9kECHhBbHkPYGElTLGpmR3Q2zzoddeh5uGnA/kN8o39aBvup9Qodqai0om62Aj2D72B7W04N2cDt/YORzuBgucvCHkIwlfP2k= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=NzZuGcXA; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="NzZuGcXA" Received: by smtp.kernel.org (Postfix) with ESMTPS id 09977C2BCB7; Thu, 21 May 2026 09:55:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1779357343; bh=o+1o/EQ7dZbjpAmwPQc57CtnsjDw0zwvAmz/0s35h+A=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=NzZuGcXAIDvCNrgWdeTqwvHFNjD4L+aUxPUyc5fqtJiUkHi71YrK1aTB6rUmuo/8Y YTGJiN+iTnEWAD0ZSDgvaN0OO+jlquAItOWYeT/zirCiHNgNBglzw1/BPurGTsnRlT FIfVvEUTF0+GmatrOh7oai4xIpEWZraZj7v5Eq5izxI8mxXc2yYIrFMZmZd/xkBGEs 7PXIh/KaMrnVoRHYASlE8O2NVOl1Gp1ewiwOW2S2a8OJgFKeo17kGPGSaQ4j0lWSp5 M7hVrcybBrKO3hTbYsc07QXcX91TByEkxBWS00zVnWUisFHO38qERkz+7QU3feliJ3 I9kZvxTPuWcDg== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id F08B9CD5BB1; Thu, 21 May 2026 09:55:42 +0000 (UTC) From: Joshua Crofts via B4 Relay Date: Thu, 21 May 2026 11:55:40 +0200 Subject: [PATCH v3 3/7] iio: light: opt3001: ensure correct parenthesis alignment Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260521-opt3001-cleanup-v3-3-820169dec8c3@gmail.com> References: <20260521-opt3001-cleanup-v3-0-820169dec8c3@gmail.com> In-Reply-To: <20260521-opt3001-cleanup-v3-0-820169dec8c3@gmail.com> To: Jonathan Cameron , David Lechner , =?utf-8?q?Nuno_S=C3=A1?= , Andy Shevchenko , Alexander Koch , Michael Hornung Cc: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, Joshua Crofts , Andy Shevchenko X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1779357341; l=6434; i=joshua.crofts1@gmail.com; s=20260422; h=from:subject:message-id; bh=U+yW+VfbRZj+LJxF7wHH+Fwrg9U/Vp39AaScfg2cxao=; b=yNJbxODt+XZGXtw5HFw8FU9gQ78v+FMaDXCQKsWrptOsGieGFu/fIynXUghRsrzdKhMrRgdAj pEbZfuj0WXqAskUe0tEw5qSlYErplKje8UlotFRkkvzVdlbO207yNYP X-Developer-Key: i=joshua.crofts1@gmail.com; a=ed25519; pk=Xd+UVoRPiiI0K3LHQ2XIcXmO0jvVuFTv9eTx3lgBphI= X-Endpoint-Received: by B4 Relay for joshua.crofts1@gmail.com/20260422 with auth_id=746 X-Original-From: Joshua Crofts Reply-To: joshua.crofts1@gmail.com From: Joshua Crofts Ensure correct parenthesis alignment per checkpatch.pl report. No functional change. Suggested-by: Andy Shevchenko Signed-off-by: Joshua Crofts Reviewed-by: Maxwell Doose --- 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 5d88a697c245347bcb98254460308fc9a9f375f4..09843c31516b4dcfb37e6f5e32c= 30aa75a03d4cf 100644 --- a/drivers/iio/light/opt3001.c +++ b/drivers/iio/light/opt3001.c @@ -223,8 +223,8 @@ static const struct opt3001_scale opt3002_scales[] =3D { }, }; =20 -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 =3D 0; i < ARRAY_SIZE(*opt->chip_info->scales); i++) { @@ -242,8 +242,8 @@ static int opt3001_find_scale(const struct opt3001 *opt= , int val, return -EINVAL; } =20 -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 manti= ssa, + int *val, int *val2) { int ret; int whole =3D opt->chip_info->factor_whole; @@ -364,8 +364,8 @@ static int opt3001_get_processed(struct opt3001 *opt, i= nt *val, int *val2) if (opt->use_irq) { /* Wait for the IRQ to indicate the conversion is complete */ ret =3D 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 =3D=3D 0) return -ETIMEDOUT; } else { @@ -474,8 +474,8 @@ static int opt3001_set_int_time(struct opt3001 *opt, in= t time) } =20 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 =3D iio_priv(iio); int ret; @@ -506,8 +506,8 @@ static int opt3001_read_raw(struct iio_dev *iio, } =20 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 =3D iio_priv(iio); int ret; @@ -532,9 +532,11 @@ static int opt3001_write_raw(struct iio_dev *iio, } =20 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 =3D iio_priv(iio); int ret =3D IIO_VAL_INT_PLUS_MICRO; @@ -544,11 +546,13 @@ static int opt3001_read_event_value(struct iio_dev *i= io, 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 =3D -EINVAL; @@ -560,9 +564,11 @@ static int opt3001_read_event_value(struct iio_dev *ii= o, } =20 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 =3D iio_priv(iio); struct i2c_client *client =3D opt->client; @@ -626,8 +632,9 @@ static int opt3001_write_event_value(struct iio_dev *ii= o, } =20 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 =3D iio_priv(iio); =20 @@ -635,8 +642,10 @@ static int opt3001_read_event_config(struct iio_dev *i= io, } =20 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 =3D iio_priv(iio); struct i2c_client *client =3D opt->client; @@ -812,16 +821,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 =3D i2c_smbus_read_word_swapped(client, OPT3001_RESULT); if (ret < 0) { @@ -884,8 +893,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 =3D 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; --=20 2.47.3 From nobody Sun May 24 21:38:36 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 37DCF37DEBB; Thu, 21 May 2026 09:55:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779357343; cv=none; b=KJEKp/Dt20Qi1klHrcn3ma2Wsbs7abZF/aU5jJkmdXg7sF+rQzZZx/YxTG2pAZjHVbG9S9GnCmDlgKBtRPvvjkUdV/UAk+i9klwG+yg7mhZ/dJTnPX6DSkWCBNYst5jilONMMF+OJxn1qeFjMwEgimzWPk+VbLC95wdKX579dqI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779357343; c=relaxed/simple; bh=zXF9JhxmxCFqBjgpvDElVmn2gwo7C6M0hFU6cRioKoA=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=tTlSSrAobeAGoG+iuwtVd0fu7TlKTU1BREdOXolC7EIUWCp6rrFPJX9XtRJlkS2rxdQJNrIp0cIGfwliWLX7H2909O0uAlYsnsZNAzWOQAFenuiqH0ck9A3t0+9o4fBdFgpw2q6lnBPt31EXgDCcffR9F1NpHc6bjj8HehN+x70= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=TCbjbBUS; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="TCbjbBUS" Received: by smtp.kernel.org (Postfix) with ESMTPS id 182BEC2BCC9; Thu, 21 May 2026 09:55:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1779357343; bh=zXF9JhxmxCFqBjgpvDElVmn2gwo7C6M0hFU6cRioKoA=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=TCbjbBUSxf2xWEXXEj2Lr+4I190zgEPorTN8LtTDUyLgnMBFBtwhS1QA8iJBjAsKS eopULLIXS5c7tng63o1bR5udWIM7BLnQdWBEyjHjgm4FrPnvCI8dSVpAfPNgBpEm2p Ft2RjY/OJ0boZad7syWC4NnfATulEtI7Sii8NGVXarjgnkvMBw9wLT7IzxnRMzuDzz NuTHyaTxyOncNU/6GZ/e2LYt7tNsFf1djcesMmFHENbhVZV9BaPguR69MV+TA8C2jx 3lBiZuEgjr9K9M1zLqsKob0ap0nOHnr78vH8F7GB89YawgK/552JfveHuSiqsnGVUr YczIFOFeswlVA== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0F328CD5BAC; Thu, 21 May 2026 09:55:43 +0000 (UTC) From: Joshua Crofts via B4 Relay Date: Thu, 21 May 2026 11:55:41 +0200 Subject: [PATCH v3 4/7] iio: light: opt3001: localize for loop iterator Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260521-opt3001-cleanup-v3-4-820169dec8c3@gmail.com> References: <20260521-opt3001-cleanup-v3-0-820169dec8c3@gmail.com> In-Reply-To: <20260521-opt3001-cleanup-v3-0-820169dec8c3@gmail.com> To: Jonathan Cameron , David Lechner , =?utf-8?q?Nuno_S=C3=A1?= , Andy Shevchenko , Alexander Koch , Michael Hornung Cc: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, Joshua Crofts X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1779357341; l=1002; i=joshua.crofts1@gmail.com; s=20260422; h=from:subject:message-id; bh=eLTKqoKDL5j3IrIvcKrS7OVJxPKTQ2BcNKIWwEDWqrM=; b=QWZ8vEr/3nMo2lOUxB/k2sj9ks2No4kxon1dIlh8v6sdYu7+kEpgXorwoR3V5H8NNBbm67Shj CwMgYlJs3uPACyk6KsGohUELvtoxsFh58IaYPTR8z0bKkUl92M/59rl X-Developer-Key: i=joshua.crofts1@gmail.com; a=ed25519; pk=Xd+UVoRPiiI0K3LHQ2XIcXmO0jvVuFTv9eTx3lgBphI= X-Endpoint-Received: by B4 Relay for joshua.crofts1@gmail.com/20260422 with auth_id=746 X-Original-From: Joshua Crofts Reply-To: joshua.crofts1@gmail.com From: Joshua Crofts Localize loop iterator to tighten scope and improve code style per checkpatch.pl report. No functional change. Signed-off-by: Joshua Crofts --- 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 09843c31516b4dcfb37e6f5e32c30aa75a03d4cf..22a73c1afa74988dabf9db10c3b= 55bd07529fb20 100644 --- a/drivers/iio/light/opt3001.c +++ b/drivers/iio/light/opt3001.c @@ -226,8 +226,7 @@ static const struct opt3001_scale opt3002_scales[] =3D { static int opt3001_find_scale(const struct opt3001 *opt, int val, int val2, u8 *exponent) { - int i; - for (i =3D 0; i < ARRAY_SIZE(*opt->chip_info->scales); i++) { + for (unsigned int i =3D 0; i < ARRAY_SIZE(*opt->chip_info->scales); i++) { const struct opt3001_scale *scale =3D &(*opt->chip_info->scales)[i]; /* * Compare the integer and micro parts to determine value scale. --=20 2.47.3 From nobody Sun May 24 21:38:36 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4FC05394797; Thu, 21 May 2026 09:55:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779357343; cv=none; b=ohiBsqkIADFyobVV5O0zzVEEq3AA/KXOYEgaI99mSCA+ch00VqReNbVR9gIiOyuqlPAkZcLxMQ9IC2fv6F7RkpS5r1fty893Z570+EwFkFCyROjcc2eRby26RussbarMEDGtipXKCt8UWJcFLXk2hVQkdPuEXHb10hdfLHrbaaU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779357343; c=relaxed/simple; bh=YDTOmsNMf9fU/jAbL6ARj7TZi6hplK0WfcjYEAuQsdg=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=gpQ0BsLkQnRu4eHJqo2AUhIEUGONnooJ9kPtDvXu1Di9dG6++n8ewZcclt1NUfaKNbLvDIfORHYYJViXUkrJ4kULRFOTx8KnNGGhx6ywl/WN7SBd+5PPUZRgZdCm/a16skd5pwfq5HFMoMs9YoUSl7jp4Y40DdBZydyrL5eGM9Q= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=CZYBHhDy; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="CZYBHhDy" Received: by smtp.kernel.org (Postfix) with ESMTPS id 2B58DC2BCF4; Thu, 21 May 2026 09:55:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1779357343; bh=YDTOmsNMf9fU/jAbL6ARj7TZi6hplK0WfcjYEAuQsdg=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=CZYBHhDy1TmSOOOtO0eKypuYmTQtC/VcN2DeBk+a2pesoZGCIDOg+90odAEZxgov6 v3uJTfjnyicpEw0LuXhltA/pIdrHgZz+qa18ntF4QsNqn8MhgrYLnIr3Qw6YE/clGX TRy0LoG5Ro0qeXYtgefx+CSleV6Q5hMT2NgoFRDcB8pwlTl7HZCGnR0hlEVSPndHBY PAbc20xx2m0W0o0nl2S6MZR0JvhjqoONM44CqbJGOS+0rYpxD+U50zF8575sj2s2BZ kKxvlUI7ZGuEqb5R8RFnWRMAT7vZyUFt7aJeHCe/aRczdNwERclKhwsnw8BWlRHWUR SuB1o6duqE6dg== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2253DCD5BB1; Thu, 21 May 2026 09:55:43 +0000 (UTC) From: Joshua Crofts via B4 Relay Date: Thu, 21 May 2026 11:55:42 +0200 Subject: [PATCH v3 5/7] iio: light: opt3001: prefer dev_err_probe() Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260521-opt3001-cleanup-v3-5-820169dec8c3@gmail.com> References: <20260521-opt3001-cleanup-v3-0-820169dec8c3@gmail.com> In-Reply-To: <20260521-opt3001-cleanup-v3-0-820169dec8c3@gmail.com> To: Jonathan Cameron , David Lechner , =?utf-8?q?Nuno_S=C3=A1?= , Andy Shevchenko , Alexander Koch , Michael Hornung Cc: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, Joshua Crofts X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1779357341; l=3534; i=joshua.crofts1@gmail.com; s=20260422; h=from:subject:message-id; bh=n6UK1FtuY/AoXkTO1stwerQ6zqA7TUslq0yf910Zmps=; b=MVmuiiT2wrZv0hCyktrq/y5Cxiw8ZGCs0Ka3wiy7NTj49V5THaf/Jf99u93j98pnJRnhtaNbo WxmPwDqkwLyDtNqJL8ps2UNXV6PVqaxP/oJKDUS7kKpuA5LlUsCWwux X-Developer-Key: i=joshua.crofts1@gmail.com; a=ed25519; pk=Xd+UVoRPiiI0K3LHQ2XIcXmO0jvVuFTv9eTx3lgBphI= X-Endpoint-Received: by B4 Relay for joshua.crofts1@gmail.com/20260422 with auth_id=746 X-Original-From: Joshua Crofts Reply-To: joshua.crofts1@gmail.com From: Joshua Crofts Switch driver to use dev_err_probe() to unify error messages generated in *_probe() and probe path functions. Signed-off-by: Joshua Crofts --- drivers/iio/light/opt3001.c | 56 ++++++++++++++++++-----------------------= ---- 1 file changed, 22 insertions(+), 34 deletions(-) diff --git a/drivers/iio/light/opt3001.c b/drivers/iio/light/opt3001.c index 22a73c1afa74988dabf9db10c3b55bd07529fb20..d5262488dac889066a53d323476= 2e0557f9e3cbc 100644 --- a/drivers/iio/light/opt3001.c +++ b/drivers/iio/light/opt3001.c @@ -706,21 +706,17 @@ static int opt3001_read_id(struct opt3001 *opt) int ret; =20 ret =3D 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); =20 manufacturer[0] =3D ret >> 8; manufacturer[1] =3D ret & 0xff; =20 ret =3D 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); =20 device_id =3D ret; =20 @@ -738,11 +734,9 @@ static int opt3001_configure(struct opt3001 *opt) u16 reg; =20 ret =3D 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); =20 reg =3D ret; =20 @@ -766,28 +760,22 @@ static int opt3001_configure(struct opt3001 *opt) reg &=3D ~OPT3001_CONFIGURATION_FC_MASK; =20 ret =3D 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); =20 ret =3D 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); =20 opt->low_thresh_mantissa =3D OPT3001_REG_MANTISSA(ret); opt->low_thresh_exp =3D OPT3001_REG_EXPONENT(ret); =20 ret =3D 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); =20 opt->high_thresh_mantissa =3D OPT3001_REG_MANTISSA(ret); opt->high_thresh_exp =3D OPT3001_REG_EXPONENT(ret); @@ -894,10 +882,10 @@ static int opt3001_probe(struct i2c_client *client) ret =3D 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 =3D true; } else { dev_dbg(dev, "enabling interrupt-less operation\n"); --=20 2.47.3 From nobody Sun May 24 21:38:36 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 60E6D395AE5; Thu, 21 May 2026 09:55:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779357343; cv=none; b=FcIUax9N5gTo1B1eqLfji5EgH9pzApw9t8WIBX5BsCxjrtZHlxA1ranoTwmdmGFolgpxyOZKE+g3WvgvTrObxpr5Vbv0vDpPdM08Aj57ypHi7Gc2i42T1Lg1fff+ZoQz5qNvRuIFs5uNjtBXnqdeNP+0Ghy0F20fHsv14uBpXzo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779357343; c=relaxed/simple; bh=kHjavIvRYPojEg5ff6Zb3TcXm2RgRsWl+Trr7dys/d8=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Ahluilevz7Y6X51fSsvEWCX2EZD8i2ukgcfHbL3es9SLrycJwK94h7ZVGJaZVOL9cF4y8BvmC2VFQrwOhXplujqpTLnEMMGAJjAzSxa8lZa7P2i6bJztqFo7drtaoVrfh8xYEldTKs3MToIIRmF4YbDGfUoHdwJ2c/smYKRnQCk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=kVKkRjhY; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="kVKkRjhY" Received: by smtp.kernel.org (Postfix) with ESMTPS id 42722C2BCC7; Thu, 21 May 2026 09:55:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1779357343; bh=kHjavIvRYPojEg5ff6Zb3TcXm2RgRsWl+Trr7dys/d8=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=kVKkRjhYLjZkesrwkLF2Wl1jpZPMaX40HDIpoXvkcQXRz3xxIdDxJnb/KKbQDy2Q4 xwKht/y9B49YV2782oZyYewFSGsvBEpcli75miEsuXA5bVi/RwF2fku/JMIrI9bbQg k4Aj5r62PPVxlGhI7XVMrB30YHCUQR3d0k5HxDjwX8m68UtQFBQUuEGfss5a4WESYR DhmVLOrCSPMFAqAmeyBedKvgl1yFm2b2Tof8VSNFKHBWhL/8SqH9zj3SKf3nT2d/8b 6A47DhNVkE2tDY+GmxS3/fvyVJ8nViehi1ONAe8EUSAR1a5smEcCt+Y1WU3P4tPILY +PombKK6C54Dg== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3B678CD5BAC; Thu, 21 May 2026 09:55:43 +0000 (UTC) From: Joshua Crofts via B4 Relay Date: Thu, 21 May 2026 11:55:43 +0200 Subject: [PATCH v3 6/7] iio: light: opt3001: move driver to guard(mutex)() use Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260521-opt3001-cleanup-v3-6-820169dec8c3@gmail.com> References: <20260521-opt3001-cleanup-v3-0-820169dec8c3@gmail.com> In-Reply-To: <20260521-opt3001-cleanup-v3-0-820169dec8c3@gmail.com> To: Jonathan Cameron , David Lechner , =?utf-8?q?Nuno_S=C3=A1?= , Andy Shevchenko , Alexander Koch , Michael Hornung Cc: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, Joshua Crofts , Andy Shevchenko X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1779357341; l=8545; i=joshua.crofts1@gmail.com; s=20260422; h=from:subject:message-id; bh=c33EqCJZjcvFNEIYTF2kQoi7fJsF7bXrq0aRp7HWQP4=; b=PtXLdcZfsI6oGvrQ1sf5w9nhHBaeZdcqpJFYjJHPw5KXd1FA4x4tDQHYmvKjMSEIw4qsQHHqg u+q9f9TSyFeBsm5+qMeDVBUNrxpE+hwrWBI0GhnZlujVOyp3L0aVW/h X-Developer-Key: i=joshua.crofts1@gmail.com; a=ed25519; pk=Xd+UVoRPiiI0K3LHQ2XIcXmO0jvVuFTv9eTx3lgBphI= X-Endpoint-Received: by B4 Relay for joshua.crofts1@gmail.com/20260422 with auth_id=746 X-Original-From: Joshua Crofts Reply-To: joshua.crofts1@gmail.com From: Joshua Crofts 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 Signed-off-by: Joshua Crofts --- drivers/iio/light/opt3001.c | 140 +++++++++++++++++++---------------------= ---- 1 file changed, 60 insertions(+), 80 deletions(-) diff --git a/drivers/iio/light/opt3001.c b/drivers/iio/light/opt3001.c index d5262488dac889066a53d3234762e0557f9e3cbc..ac1c7ba5679867f6b814894680e= 317615f2e373b 100644 --- a/drivers/iio/light/opt3001.c +++ b/drivers/iio/light/opt3001.c @@ -10,6 +10,7 @@ =20 #include #include +#include #include #include #include @@ -477,7 +478,6 @@ static int opt3001_read_raw(struct iio_dev *iio, int *val, int *val2, long mask) { struct opt3001 *opt =3D iio_priv(iio); - int ret; =20 if (opt->mode =3D=3D OPT3001_CONFIGURATION_M_CONTINUOUS) return -EBUSY; @@ -485,23 +485,17 @@ static int opt3001_read_raw(struct iio_dev *iio, if (chan->type !=3D opt->chip_info->chan_type) return -EINVAL; =20 - mutex_lock(&opt->lock); + guard(mutex)(&opt->lock); =20 switch (mask) { case IIO_CHAN_INFO_RAW: case IIO_CHAN_INFO_PROCESSED: - ret =3D opt3001_get_processed(opt, val, val2); - break; + return opt3001_get_processed(opt, val, val2); case IIO_CHAN_INFO_INT_TIME: - ret =3D opt3001_get_int_time(opt, val, val2); - break; + return opt3001_get_int_time(opt, val, val2); default: - ret =3D -EINVAL; + return -EINVAL; } - - mutex_unlock(&opt->lock); - - return ret; } =20 static int opt3001_write_raw(struct iio_dev *iio, @@ -509,7 +503,6 @@ static int opt3001_write_raw(struct iio_dev *iio, int val, int val2, long mask) { struct opt3001 *opt =3D iio_priv(iio); - int ret; =20 if (opt->mode =3D=3D OPT3001_CONFIGURATION_M_CONTINUOUS) return -EBUSY; @@ -523,11 +516,9 @@ static int opt3001_write_raw(struct iio_dev *iio, if (val !=3D 0) return -EINVAL; =20 - mutex_lock(&opt->lock); - ret =3D opt3001_set_int_time(opt, val2); - mutex_unlock(&opt->lock); + guard(mutex)(&opt->lock); =20 - return ret; + return opt3001_set_int_time(opt, val2); } =20 static int opt3001_read_event_value(struct iio_dev *iio, @@ -538,28 +529,23 @@ static int opt3001_read_event_value(struct iio_dev *i= io, int *val, int *val2) { struct opt3001 *opt =3D iio_priv(iio); - int ret =3D IIO_VAL_INT_PLUS_MICRO; =20 - mutex_lock(&opt->lock); + guard(mutex)(&opt->lock); =20 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 =3D -EINVAL; + return -EINVAL; } - - mutex_unlock(&opt->lock); - - return ret; } =20 static int opt3001_write_event_value(struct iio_dev *iio, @@ -586,12 +572,12 @@ static int opt3001_write_event_value(struct iio_dev *= iio, if (val < 0) return -EINVAL; =20 - mutex_lock(&opt->lock); + guard(mutex)(&opt->lock); =20 ret =3D 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; } =20 whole =3D opt->chip_info->factor_whole; @@ -614,20 +600,16 @@ static int opt3001_write_event_value(struct iio_dev *= iio, opt->low_thresh_exp =3D exponent; break; default: - ret =3D -EINVAL; - goto err; + return -EINVAL; } =20 ret =3D i2c_smbus_write_word_swapped(client, reg, value); if (ret < 0) { dev_err(dev, "failed to write register %02x\n", reg); - goto err; + return ret; } =20 -err: - mutex_unlock(&opt->lock); - - return ret; + return 0; } =20 static int opt3001_read_event_config(struct iio_dev *iio, @@ -659,7 +641,7 @@ static int opt3001_write_event_config(struct iio_dev *i= io, if (!state && opt->mode =3D=3D OPT3001_CONFIGURATION_M_SHUTDOWN) return 0; =20 - mutex_lock(&opt->lock); + guard(mutex)(&opt->lock); =20 mode =3D state ? OPT3001_CONFIGURATION_M_CONTINUOUS : OPT3001_CONFIGURATION_M_SHUTDOWN; @@ -668,7 +650,7 @@ static int opt3001_write_event_config(struct iio_dev *i= io, if (ret < 0) { dev_err(dev, "failed to read register %02x\n", OPT3001_CONFIGURATION); - goto err; + return ret; } =20 reg =3D ret; @@ -678,13 +660,10 @@ static int opt3001_write_event_config(struct iio_dev = *iio, if (ret < 0) { dev_err(dev, "failed to write register %02x\n", OPT3001_CONFIGURATION); - goto err; + return ret; } =20 -err: - mutex_unlock(&opt->lock); - - return ret; + return 0; } =20 static const struct iio_info opt3001_info =3D { @@ -726,6 +705,31 @@ static int opt3001_read_id(struct opt3001 *opt) return 0; } =20 +static void opt3001_power_off(void *data) +{ + struct opt3001 *opt =3D data; + struct i2c_client *client =3D opt->client; + struct device *dev =3D opt->dev; + u16 reg_val; + int ret; + + ret =3D i2c_smbus_read_word_swapped(client, OPT3001_CONFIGURATION); + if (ret < 0) { + dev_err(dev, "failed to read register %02x\n", + OPT3001_CONFIGURATION); + return; + } + + reg_val =3D ret; + opt3001_set_mode(opt, ®_val, OPT3001_CONFIGURATION_M_SHUTDOWN); + + ret =3D i2c_smbus_write_word_swapped(client, OPT3001_CONFIGURATION, + reg_val); + 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 =3D opt->client; @@ -764,6 +768,11 @@ static int opt3001_configure(struct opt3001 *opt) return dev_err_probe(dev, ret, "failed to write register %02x\n", OPT3001_CONFIGURATION); =20 + ret =3D 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 =3D i2c_smbus_read_word_swapped(client, OPT3001_LOW_LIMIT); if (ret < 0) return dev_err_probe(dev, ret, "failed to read register %02x\n", @@ -857,7 +866,10 @@ static int opt3001_probe(struct i2c_client *client) opt->client =3D client; opt->chip_info =3D i2c_get_match_data(client); =20 - mutex_init(&opt->lock); + ret =3D devm_mutex_init(dev, &opt->lock); + if (ret) + return ret; + init_waitqueue_head(&opt->result_ready_queue); i2c_set_clientdata(client, iio); =20 @@ -879,49 +891,18 @@ static int opt3001_probe(struct i2c_client *client) =20 /* Make use of INT pin only if valid IRQ no. is given */ if (irq > 0) { - ret =3D request_threaded_irq(irq, NULL, opt3001_irq, - IRQF_TRIGGER_FALLING | IRQF_ONESHOT, - "opt3001", iio); + ret =3D 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 =3D true; } else { dev_dbg(dev, "enabling interrupt-less operation\n"); } =20 - return iio_device_register(iio); -} - -static void opt3001_remove(struct i2c_client *client) -{ - struct iio_dev *iio =3D i2c_get_clientdata(client); - struct opt3001 *opt =3D iio_priv(iio); - struct device *dev =3D &client->dev; - int ret; - u16 reg; - - iio_device_unregister(iio); - - if (opt->use_irq) - free_irq(client->irq, iio); - - ret =3D i2c_smbus_read_word_swapped(client, OPT3001_CONFIGURATION); - if (ret < 0) { - dev_err(dev, "failed to read register %02x\n", - OPT3001_CONFIGURATION); - return; - } - - reg =3D ret; - opt3001_set_mode(opt, ®, OPT3001_CONFIGURATION_M_SHUTDOWN); - - ret =3D i2c_smbus_write_word_swapped(client, OPT3001_CONFIGURATION, reg); - if (ret < 0) { - dev_err(dev, "failed to write register %02x\n", - OPT3001_CONFIGURATION); - } + return devm_iio_device_register(dev, iio); } =20 static const struct opt3001_chip_info opt3001_chip_information =3D { @@ -962,7 +943,6 @@ MODULE_DEVICE_TABLE(of, opt3001_of_match); =20 static struct i2c_driver opt3001_driver =3D { .probe =3D opt3001_probe, - .remove =3D opt3001_remove, .id_table =3D opt3001_id, =20 .driver =3D { --=20 2.47.3 From nobody Sun May 24 21:38:36 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 72315396D2E; Thu, 21 May 2026 09:55:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779357343; cv=none; b=mm+we4k/rdVyYqosDGdLrnBII9Xb/5k5wXAvxsoCn81u42Hnh2UjCi57c4PnomXomSeTkrnUZ04rxqhZnffYCqN7AbGK0pRa4DTDGAdv/KDzBTjPt1O7wgutpjeEPdPibD+v1XapgRvrRxfCKEldmHoEyQCpbP2shaoxPb9/lHs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779357343; c=relaxed/simple; bh=0cZpIBG05oVG4VLhk+isfCPecoEYvj0aQBsmF1kKbDo=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=IsPRIDIXgv0BehKWsrvxkbMEirGrpoNVA3PyzvFmV73RlOPFKQE5+1mw5pR0Y9iUnGjjZ3k7O3YhiMlK+irG7pqbM13RsPciN6pod8MvDHc1Q+RbOf942132zg9JfAZjiofqKuBj9/IE8f44567RfdPNutakLsvg38i9gGqy58c= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=u88/EUvN; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="u88/EUvN" Received: by smtp.kernel.org (Postfix) with ESMTPS id 55EA1C2BCB4; Thu, 21 May 2026 09:55:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1779357343; bh=0cZpIBG05oVG4VLhk+isfCPecoEYvj0aQBsmF1kKbDo=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=u88/EUvNIxo3FpPBopnJ3D2OeRWS+7MdIzxIKKNkLuIrlJLlNi6a8C5x+pFfAktCr c9MHkjSsoUe2UbuR591/4yTywkLU5IOezkf277PlMd9/31LFOSvf3BrDHark9Cw6eU qewOxeRB6+dYaXSDlgeBmIgDeUWlvKLZAz1aLaQgqqOZ2azp7bC1v7Y4x+hn11IBCO EcPRRR2lXzT/k4B2gZdZ65yOs4R2vTicFO61MTS2uVRKAZAE6hh5uXYY4x7i7wbXgv iYFOINE0kf9Y2PKI/zgjF3jwNNBwtc2MN0sCVVemJ6iXOSLHcTT+/3q1d7fIhy2ylV bzKeOwZmQRyMA== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4F776CD4F5E; Thu, 21 May 2026 09:55:43 +0000 (UTC) From: Joshua Crofts via B4 Relay Date: Thu, 21 May 2026 11:55:44 +0200 Subject: [PATCH v3 7/7] iio: light: opt3001: add comment to mutex Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260521-opt3001-cleanup-v3-7-820169dec8c3@gmail.com> References: <20260521-opt3001-cleanup-v3-0-820169dec8c3@gmail.com> In-Reply-To: <20260521-opt3001-cleanup-v3-0-820169dec8c3@gmail.com> To: Jonathan Cameron , David Lechner , =?utf-8?q?Nuno_S=C3=A1?= , Andy Shevchenko , Alexander Koch , Michael Hornung Cc: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, Joshua Crofts , Maxwell Doose X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1779357341; l=747; i=joshua.crofts1@gmail.com; s=20260422; h=from:subject:message-id; bh=nPTHkMaVXMtfkGG3J9CutOPKt6djL0Q5K/PInamunpM=; b=tfZGJJQKv3e9OGXO8HACxP4MwXKSKOIZBIbPGD6yW/Wm2XKsmfVdV6Yy1sW/OvStrWEkhWzA8 MzBFt738c76DYYrIpEVgNQTtKBsw6k21iOAPQ0iyk5EJIzVhj9eeUAS X-Developer-Key: i=joshua.crofts1@gmail.com; a=ed25519; pk=Xd+UVoRPiiI0K3LHQ2XIcXmO0jvVuFTv9eTx3lgBphI= X-Endpoint-Received: by B4 Relay for joshua.crofts1@gmail.com/20260422 with auth_id=746 X-Original-From: Joshua Crofts Reply-To: joshua.crofts1@gmail.com From: Joshua Crofts Add comment to mutex per checkpatch.pl report. No functional change. Reviewed-by: Maxwell Doose Signed-off-by: Joshua Crofts --- 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 ac1c7ba5679867f6b814894680e317615f2e373b..9d24d7a23ef00d160fdae737b6e= a1943576a3fcf 100644 --- a/drivers/iio/light/opt3001.c +++ b/drivers/iio/light/opt3001.c @@ -103,6 +103,7 @@ struct opt3001_chip_info { struct opt3001 { struct i2c_client *client; =20 + /* Mutex for ensuring one executed command at a time */ struct mutex lock; bool ok_to_ignore_lock; bool result_ready; --=20 2.47.3