From nobody Mon Jun 8 23:56:53 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 2B9D7320CD9; Mon, 25 May 2026 08:20:26 +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=1779697226; cv=none; b=HyPbApfgTgU+Zw+DBNDeJ17ylHLwAuHKujBunDKhEl3uSYVHziEIEHnUS45rL9T3Y1JfyHuwi7ASI9som+77VT+4RcYf7iiMR3tMbJKwdxNfinhYM0Ucf7qRI3r8qlx3LS1J5GsZbGzHWrHG6VdTWzN5QT1ZoS4UTb4hSWyO3Ck= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779697226; c=relaxed/simple; bh=6i39pnD/3MQITgaP48uDJxtcF9y8dLaXP0Z/Qq08A9E=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=KhXf1haqtvszAk+eJM11hn8lQeiaqU/0LfwxxqMc77Yzgbyg+6tozKcmMJraPXTuDfo3d/62kibsTA+ViirBKYIhVC2tpn7HX+dzJZ6RgMugOyMF9anMeEnV+JfCnnRSFvy7843sYCGeNBuFiMPp768YTu3O2M90a1/wshoqdcY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=AHMyGngW; 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="AHMyGngW" Received: by smtp.kernel.org (Postfix) with ESMTPS id C9B31C2BCC7; Mon, 25 May 2026 08:20:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1779697225; bh=6i39pnD/3MQITgaP48uDJxtcF9y8dLaXP0Z/Qq08A9E=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=AHMyGngWVYFChKEV+6odpmgW7zKX9zQvq1LWqpPdO/pVoSFpILEptqKCzbg+eafC/ jRMo4jZZIHQakChfS8J+2MHV2mWtZ3BfwiYwOmcN55CnE3RqTi6Fxr8vKAcUH5q5+h y4glJVX/MeuAve8g8tHtvK6NWBidTMdoxFpemb6qJgp5oerwaTd/GFYCoS2zJ+Bl2p gyfLI1vN2i2FenoGJo7TaTtDx3lPKMlUHy1uYY0sZopzxthZU7bhsfjn8e3NqjFA5f k2SeQCjV1yPkTa/uWoAUw6GYDWMh6becTGC8DMqCS0GmOBg5MMXxs6Lq/aAiYlGRjt Lzgy4PbOfOgUA== 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 B8586CD5BCE; Mon, 25 May 2026 08:20:25 +0000 (UTC) From: Joshua Crofts via B4 Relay Date: Mon, 25 May 2026 10:20:15 +0200 Subject: [PATCH v4 1/8] 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: <20260525-opt3001-cleanup-v4-1-65b36a174f78@gmail.com> References: <20260525-opt3001-cleanup-v4-0-65b36a174f78@gmail.com> In-Reply-To: <20260525-opt3001-cleanup-v4-0-65b36a174f78@gmail.com> To: Jonathan Cameron , David Lechner , =?utf-8?q?Nuno_S=C3=A1?= , Andy Shevchenko 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=1779697227; l=1858; i=joshua.crofts1@gmail.com; s=20260422; h=from:subject:message-id; bh=oA51opJseD6tk2nABX482iviMQyyuKM5oZpLk6ZwbiU=; b=0mU+Q7a50F8VB2hs3UsYYa3wU9govCa5ia2cmCecoGcXjumHMCiiTnKUaT1hQrB/rlrlMZ4MZ Z60aEkhTLcABpaQuiKUq/dqrRicFPnU5uWCPcn7YirVrRw8c+Unr4Rb 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 follow standard driver teardown/setup ordering and improve driver logic. 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. Suggested-by: Jonathan Cameron Signed-off-by: Joshua Crofts --- drivers/iio/light/opt3001.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/drivers/iio/light/opt3001.c b/drivers/iio/light/opt3001.c index 03c7a87b4a8eef13bbdcf48dcaf969781aa76bd1..6a39f116f9312b6933e86d72aef= baaaf1769aca5 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,17 @@ static int opt3001_probe(struct i2c_client *client) dev_dbg(opt->dev, "enabling interrupt-less operation\n"); } =20 + ret =3D iio_device_register(iio); + if (ret) + goto free_irq; + return 0; + +free_irq: + if (irq > 0) + free_irq(irq, iio); + + return ret; } =20 static void opt3001_remove(struct i2c_client *client) @@ -904,6 +908,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 Mon Jun 8 23:56:53 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 2BD173D5C1E; Mon, 25 May 2026 08:20:26 +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=1779697226; cv=none; b=deAeym0iC1nSUTV3u7627apx9OqVnHuvDB+3s2xx/5vzyieLDjenbgc/WqIOKCq6wIGjFxsaMenGfDZgLoWmFW9kzCNR+6toFBarRehSms5IuQcJB0w1Q3yyYS4YtmYc8B0mdKGBZAJyos/5kQUOeUIkc5StE0vBXuWxoMwxGK4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779697226; c=relaxed/simple; bh=bmYUs3bz0IUC3XFMQX3Mbb92Z2JOmpd/zTjO5YweeuU=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=ECH5UK9nq5OlkmvroS2IcBCC2Qotg6sYN2f99fZLLS+VVttrtwozcM612ZN2DfZ/u97oHrl4txxTuwG9xREIa70YaGPs2DZrCSz5VmadBLg+OgFnPpd3a2Cu9j+hVL5auHpCDMLZ7TbASdbFQCfe8ADMvYuRbkHXirwer2x0pFI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=bRICZe8F; 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="bRICZe8F" Received: by smtp.kernel.org (Postfix) with ESMTPS id D8BE4C2BCB7; Mon, 25 May 2026 08:20:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1779697225; bh=bmYUs3bz0IUC3XFMQX3Mbb92Z2JOmpd/zTjO5YweeuU=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=bRICZe8FLzPlf8BceCcJwTJ8hg2Yv5YBPgUKNQgrK5cIik33T8ngeYFkQBRbyN61n 9jiThbkTXSbRtmNEVrVZQEcE8puSFjdq22ZE5RtfGaeD1r4dZfSGfCKotO+T87cM0h dG6/9RiKaR+ImK2ZP8+BZPM6jzZkFxNFP8EU54oFeXPQ1kpk0UcOYC/gH7zQ9rTu23 MiUZfvbxhq0eR0XpEFdjt4TK3ie3Xbfwmfa1KpkAD5SyM2sOrJSfoxNOEl0tIpXEVg ipM13Bd9jsEPPSzZj4NY19EouKnyWoTyTcBWDPZrlgVt1365wl7TeAUBwFx2Cu8hHh PC7MYYKrenQXA== 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 C6135CD5BD0; Mon, 25 May 2026 08:20:25 +0000 (UTC) From: Joshua Crofts via B4 Relay Date: Mon, 25 May 2026 10:20:16 +0200 Subject: [PATCH v4 2/8] 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: <20260525-opt3001-cleanup-v4-2-65b36a174f78@gmail.com> References: <20260525-opt3001-cleanup-v4-0-65b36a174f78@gmail.com> In-Reply-To: <20260525-opt3001-cleanup-v4-0-65b36a174f78@gmail.com> To: Jonathan Cameron , David Lechner , =?utf-8?q?Nuno_S=C3=A1?= , Andy Shevchenko 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=1779697227; l=13710; i=joshua.crofts1@gmail.com; s=20260422; h=from:subject:message-id; bh=rHGnFUEo59+54A5yrhF29Ma2H1uNwCWoLvNv+reenpM=; b=9reZBeQxwm0W8B8pFYKA22/wrUk0Qf7uK9qKdkl2c9mFINYiYlFqrpgjMKbtX62GNe3oX8o8E vkkU1hmfACgAoHenyVHtrRGn7y7vQkOmD5Ua9ByJey5nMpTaSV1tQ9O 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 Reviewed-by: Andy Shevchenko --- 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 6a39f116f9312b6933e86d72aefbaaaf1769aca5..efaad85dfaf3afc9199fd3124d8= 32ee2a297f0b3 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 ret =3D iio_device_register(iio); @@ -905,6 +912,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 @@ -913,21 +921,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 Mon Jun 8 23:56:53 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 2BDA93DB994; Mon, 25 May 2026 08:20:26 +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=1779697226; cv=none; b=UuQP/H4RZLeNBAly5r2VqBS1b3Ue/DNQ/qTmA17pKG7Dy/lGN8c7DPoSDZNTDAyBBpqesePoIU3zHf2uGKM10i8LcYk0j9Wy+IicTJAYs1lGIP3cC9P4/LA2c4XKPa2M6fzkESF14/9tpYI8+BDgK/pVIUYgHQh0uhbr5/gASP8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779697226; c=relaxed/simple; bh=brgozaoIhalDjcixDFFa4XwraRRV2OwL/iJ8f3gJTIY=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=crbDJGRyi6Y/VSRuiW11Z/MnlB86o1mRWAn0hEGa9nSl2sLxk58ouBl241vQmJXymmrOC7mUgE4qRbqtI8eKBQ30jAVvjCM9s8LeOjQ1deuQsWVX8uSpY08C1S7wmgtAGvZQRURMlaWqDMBKAJtDMw6pAynMDIXpVp0obN5y0zU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=CIJPNx7E; 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="CIJPNx7E" Received: by smtp.kernel.org (Postfix) with ESMTPS id E3F63C2BCC9; Mon, 25 May 2026 08:20:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1779697225; bh=brgozaoIhalDjcixDFFa4XwraRRV2OwL/iJ8f3gJTIY=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=CIJPNx7E7doDDJWJ0gJeeFFe+EORh1NwpJ8CdnASwQCZu7ocfAbR7w7eJgAe3RUmJ NFpKrRSVAswdiSl1+5ItkmddU+4iex0RXQqdWU4m+FjbcQnLuS3bPlKpOtqXoTGyKB 2JPxP8AjMmyD2OvaAzdnFb3ByapvDe4ECiCgyLgeCCA/YGJphKzUDufcG9XgVSCnOB p4pdocpPaj22Bx0mMYklCpoz/qukHcD9ocQoQlMk78EYN/Fm3hCzRvmDf/UNzl1srA evBfburMUlzJeETAezUs/HVlMun6mPttz5A5TZkFCrfPpoJ7ogL+ggYmq+Dc6XlWbQ S80L/1qUHzEtA== 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 D3B2DCD5BBF; Mon, 25 May 2026 08:20:25 +0000 (UTC) From: Joshua Crofts via B4 Relay Date: Mon, 25 May 2026 10:20:17 +0200 Subject: [PATCH v4 3/8] 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: <20260525-opt3001-cleanup-v4-3-65b36a174f78@gmail.com> References: <20260525-opt3001-cleanup-v4-0-65b36a174f78@gmail.com> In-Reply-To: <20260525-opt3001-cleanup-v4-0-65b36a174f78@gmail.com> To: Jonathan Cameron , David Lechner , =?utf-8?q?Nuno_S=C3=A1?= , Andy Shevchenko Cc: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, Joshua Crofts , Andy Shevchenko , Maxwell Doose X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1779697227; l=6484; i=joshua.crofts1@gmail.com; s=20260422; h=from:subject:message-id; bh=XcYPddxwQ5YRQuQYmj0mxVovELv4CpiABGttMCHtiOk=; b=ikYPWZZug+cctmUfGR2AXjmmj3ITWJMNMAa2Tzm6CsLaP+tGOMDJHlGZWdJ12ztg5IdgALGv2 niuF6EktXJLD+qsYaDvb/HVNGVkD5/d0Tu+IG7yiJVq5O6tdoZm5Ka1 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 Reviewed-by: Maxwell Doose Signed-off-by: Joshua Crofts --- 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 efaad85dfaf3afc9199fd3124d832ee2a297f0b3..532929e8fa8b4172eadc696e927= 315017a07dac1 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 Mon Jun 8 23:56:53 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 300D73E123E; Mon, 25 May 2026 08:20:26 +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=1779697226; cv=none; b=WfTC6mMQlqpg1KOx4ZJgukv5GVtM1sy1dBcTW9CSKNWgLALy9vLZzcoWIm0efFNuTBg84dcLKAamFgByoIxPhwvBnqUQWdO1ugDjZV4NawSYGCwLvikueYWdFCA+B+X91kFBII6bhFGRbQGfnHrwL21Mgd2JqvxkRf7C0ZD8X8E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779697226; c=relaxed/simple; bh=IPkVeA+IgQkAnOarSY2Gh6Pi86M2VA4Euc5JsqsdIpA=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=lUyCGMy33u9gIYUX5VGxevHdRe3qFUAJjN9zzexdN/NSw4FHQqmml7SfAllaGxAbQUMhNaC2JCQc75Zxuc2hdMIOn2ZmvP6bci2tfzma4XJoDaj/iAMNfPJQjSg5GbkG+whED4iwbXeP6CaASGTypNFtOnuG5FecUU1H/iyzmis= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=AbUfE+3A; 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="AbUfE+3A" Received: by smtp.kernel.org (Postfix) with ESMTPS id EA125C2BCF5; Mon, 25 May 2026 08:20:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1779697226; bh=IPkVeA+IgQkAnOarSY2Gh6Pi86M2VA4Euc5JsqsdIpA=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=AbUfE+3AZ5OGoYuwTLzbI7B8B8mowiaUm86oqOrMSbyIfcIlCOMlOcQcC+WZ0IeWw dtCoJhJApNVAVTzvY/rZnMufw56Pl5nn03iB0oXj3Yj0syGqD3a2ttcBGveoU888cX OFb1jvq2zaVc2WyAZggHq/2BHF4RB3T51lC0srILn7V7TCOnh++K322rNW7iZP0938 8PVJU7E35LrmdankeMEuQQyxorNqMiuMGLU8Ayw2uPva/rkpAt+Pr8HZsyILclbZ7p M2e8KkxZevApHac12Hv38IbSh24hsKaXxnotmHJOXOhIyufprVlKvlODaRibRejfEr 9fEfgiZB7EXhw== 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 E035DCD5BD2; Mon, 25 May 2026 08:20:25 +0000 (UTC) From: Joshua Crofts via B4 Relay Date: Mon, 25 May 2026 10:20:18 +0200 Subject: [PATCH v4 4/8] 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: <20260525-opt3001-cleanup-v4-4-65b36a174f78@gmail.com> References: <20260525-opt3001-cleanup-v4-0-65b36a174f78@gmail.com> In-Reply-To: <20260525-opt3001-cleanup-v4-0-65b36a174f78@gmail.com> To: Jonathan Cameron , David Lechner , =?utf-8?q?Nuno_S=C3=A1?= , Andy Shevchenko 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=1779697227; l=1002; i=joshua.crofts1@gmail.com; s=20260422; h=from:subject:message-id; bh=tpQWvMzLOXdTHcX1LxcT0aRdkJtE7TOkAhwdw+eYL50=; b=rEJWopHXR047UG34D8sbIWbnoJGBfBE/ybb2YquNqHemTOhR8qwO94kxt9HrGdlXb0WGVFETB ijMwIe4G+LKC8GjxhA35IhGnJclOY0x8lh5AFn6jH063r1a7km5vNz3 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 Reviewed-by: Maxwell Doose --- 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 532929e8fa8b4172eadc696e927315017a07dac1..777a54753b0c84dbee409801010= 19450fcd06af1 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 Mon Jun 8 23:56:53 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 67D8C3E1722; Mon, 25 May 2026 08:20:26 +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=1779697226; cv=none; b=YrMXZ3c8TDwlRrROb2wsPpDlhAkVTf0pVxvZQON5GVFxFU25CeVEbvbnkF5jbYHLwFFl6YKPOHpEL3Mg9y9jgvUZm1F5T1XQaqZZcruQb5LMh4TgloyleuVaMZru2yGEaSk5bHgY0vDpDMKCz1uEgVCbdXl1NAVMJBirce5vlkc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779697226; c=relaxed/simple; bh=xZ4U/N4xzF8KI+baT52FFw2A83cWXDtHkqOe3pBdEIU=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=eBmKk1rPiwRoHNPU7BOI/bU9GqLr5Z4z1wyAXTsXiG+8BXBLB/C7loOzrmeUJe2TIMcZVC6kjV6l0MQANBw7anTXR0nKRjPotjO+d9j9TCVv1cmQTSY151/tX1DmTen06z3HElb8BnaHzSys+KTzmNXdQFeAo6yovUsuDT4dQaA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=j6JgV/n2; 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="j6JgV/n2" Received: by smtp.kernel.org (Postfix) with ESMTPS id 02659C2BCF4; Mon, 25 May 2026 08:20:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1779697226; bh=xZ4U/N4xzF8KI+baT52FFw2A83cWXDtHkqOe3pBdEIU=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=j6JgV/n2cmpUxZzHS6IF0+SwpPoUQ3Rq8I16ngrDTDBlNJ5ZsXMJIUGuaY+fx7/Eh LAXXELlOYWrvuewbXZn2OTuH+NF3Dypb5D9SiuqvKsBKCQMtZAgrKgwq2U0RHAlZ5U sUA7A9qODJJrpP2IqWbKdonELWHe7+zDR3367QFKq4U2cS6ADQ9UQxlVDe0Zq0e+Hv eHXrBcTb+3FU6pjWxu8ZrUap8hlWbOZ7GeKR0dwrtDqGvDPwT7F8eJOO3VUzhGRlK1 RCGxocXAvbvT7YTCYpw4z9xCbFAsteYbZfjwLL5xTVmOzFoYslgOKOHWn1ry3Bx+/H ACrmK11lSOwFQ== 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 EE254CD5BD1; Mon, 25 May 2026 08:20:25 +0000 (UTC) From: Joshua Crofts via B4 Relay Date: Mon, 25 May 2026 10:20:19 +0200 Subject: [PATCH v4 5/8] 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: <20260525-opt3001-cleanup-v4-5-65b36a174f78@gmail.com> References: <20260525-opt3001-cleanup-v4-0-65b36a174f78@gmail.com> In-Reply-To: <20260525-opt3001-cleanup-v4-0-65b36a174f78@gmail.com> To: Jonathan Cameron , David Lechner , =?utf-8?q?Nuno_S=C3=A1?= , Andy Shevchenko 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=1779697227; l=3534; i=joshua.crofts1@gmail.com; s=20260422; h=from:subject:message-id; bh=JChmuY3Cry41DbF2evnRYkUtRADLx3EHBeJilNjXnDo=; b=2OA1LqlsRAGwtQYdT5Sa5D2gFOfdnOxFtQlprrms80K7eq46HIbtAbkunq59BCEkhizVY93U6 gGte1466a/pAwx/HZ9xaIgbvZ7ptivPyG/kZUmEEhGG7qSC/1BDntF6 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 Reviewed-by: Maxwell Doose --- 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 777a54753b0c84dbee40980101019450fcd06af1..fa799edd6a9ce7373400bb654ea= 4a1b9f17212a3 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 Mon Jun 8 23:56:53 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 56C8A3E16A2; Mon, 25 May 2026 08:20:26 +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=1779697226; cv=none; b=dYHnGqrFvfngsFg2wsHIgCFDESfT8uaybD2zgIBsDAzz21LElq3ZYGZGcKMpwITYzJxISJ6+g0saRgRktMxxefPFQvgrRs7Q3qhWfRfdqDauc3BTtgzdJ9CMzOCLxw2HTO0QIX72DwG26F9eM8jDmH1x4oGRImQETQCPhJgqL6o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779697226; c=relaxed/simple; bh=QhpC0LOJNu5pik6KT+yhn5u0M1YrqVbXNByZR68+Awc=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=haXOAXjKrTMYb7KiE8yxlYJt3GteP4bwDZJBvvXYbGjr/BmgrPm6jNAVAoh9Cq7D7JLefoIPZjxqv3keKZLBSt2ai1fru9phn9IFhZKrqnOCDvTeOcE9/WsLtxCPB/IlCTZobF04ZCrQJHoAaR87DFv+dVq0aerlBIojqXxNcgo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=m/NcCA1R; 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="m/NcCA1R" Received: by smtp.kernel.org (Postfix) with ESMTPS id 11037C4AF0C; Mon, 25 May 2026 08:20:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1779697226; bh=QhpC0LOJNu5pik6KT+yhn5u0M1YrqVbXNByZR68+Awc=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=m/NcCA1ReeW6Dh5ihN0HVPvsm5cpWguNkiNm7F6Is8lBsXvunO04iQA85URkaTuJF kdP5lubYUhEMCcXIQhmNUYhYXpWStIHUG8lUT2ShzKwQYLb6mYOKeDZsPgcYKjt2N7 1KSEjyF4boK/xjUpb/u9TUgz2vzc7UAUhE3eK/JNstrDgW84ABzFHiX627/u1nRwpL 3oJTx3IreCE6SlT2CvFMw8q41YBYCUBEex242W87FrNcRKtLjKhDAiRgE17ql7G/Lb XyD5xUEdWqEWpmf7NEmMtG3r0uolT/LOzOpBFxT/9yTMs8+NlkAW5c+dmR5SpEd3S1 h8eF+5sxABsHQ== 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 07B85CD5BCF; Mon, 25 May 2026 08:20:26 +0000 (UTC) From: Joshua Crofts via B4 Relay Date: Mon, 25 May 2026 10:20:20 +0200 Subject: [PATCH v4 6/8] 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: <20260525-opt3001-cleanup-v4-6-65b36a174f78@gmail.com> References: <20260525-opt3001-cleanup-v4-0-65b36a174f78@gmail.com> In-Reply-To: <20260525-opt3001-cleanup-v4-0-65b36a174f78@gmail.com> To: Jonathan Cameron , David Lechner , =?utf-8?q?Nuno_S=C3=A1?= , Andy Shevchenko 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=1779697227; l=5066; i=joshua.crofts1@gmail.com; s=20260422; h=from:subject:message-id; bh=k7RV8CJgC7cxMwnoTqnNl88vKb0HKNBwwuTVAnHr18w=; b=hxXLoZpoOMJ7MA1TTZdYgrGOuMCL6C70hBBjTKDQg8gWOaaQhy+h/roKCDCAoRe8P0LAE+JuA /MY9Cylo0SAAf0mF4t1qkodo7N73iT+LXOcfZuZIy+8D2np5x4tU2nR 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 | 61 +++++++++++++++--------------------------= ---- 1 file changed, 20 insertions(+), 41 deletions(-) diff --git a/drivers/iio/light/opt3001.c b/drivers/iio/light/opt3001.c index fa799edd6a9ce7373400bb654ea4a1b9f17212a3..14a0915330672209a8de60fc4f3= debdd6d6bba76 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 { --=20 2.47.3 From nobody Mon Jun 8 23:56:53 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 67CEF3E1721; Mon, 25 May 2026 08:20:26 +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=1779697226; cv=none; b=nEBUTVR3JvIqspVkUeD16vccfyA77P94/rCjAyRc9rbn/8+ytOdGKu98vc8UxaJPf8GOj/Wyxk8UABRlf/8maJ2vQAqkt3Qg0/IIHFZDa6GDTi1E1+mzrhmnUqH2qLbNSRgeAftXQ41RtjKgPOlwJFwWXUGHAYR6Z7JJ3HyYw7g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779697226; c=relaxed/simple; bh=no98pCXwLTZEou8kepLVLZlinZiUarSGnSWfn6IYj/Q=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=R18roCCgpQ0AMH8JN3cVHtBivooAK3VCtMfSDIcCwYSSEiXDsvXpcLV9dLxokijAE+Px+jbOzQ/OQ/HbUSJgDjEiaYiUmsHYxylhEFA6rYcyCWE9kz/PxuG7FDymitog3lPJrnloqQAkaIllATYbtT/RIFFv/i+CT/ygQ7gssMs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=bKWTxUFi; 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="bKWTxUFi" Received: by smtp.kernel.org (Postfix) with ESMTPS id 17C81C2BD00; Mon, 25 May 2026 08:20:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1779697226; bh=no98pCXwLTZEou8kepLVLZlinZiUarSGnSWfn6IYj/Q=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=bKWTxUFiiPiCuCUxvUHa/+EVJiNTMYXIxbdBmuciGo+tp7/FL8sAqn12Plf7PbRPD 1q6rjuCaBFdgISdeqpZKAfmcafuqgQL8P097YWZrXR1ov0tWmZo8a4TU5pXKzL4wVi kr3NKRhCGknMWydSxlzYKKwh6X79KdGWjiZWAj/mHu9nNlH8Jy7o3k8c1KcUq92rwW TNMAf7p3CHBQNj2AIPpX2iOcqM5gmPOqxk1hr/F+r+B1so1CNX0lAgniyg65Pela4A TXWAKr1q7/v9eiEW1RoxDcN4gnCLLo8yNx3AHToLss4lEXGgnEp9IkNeI21xi48lr1 Lyyf9BZnk9kfQ== 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 135A9CD5BD2; Mon, 25 May 2026 08:20:26 +0000 (UTC) From: Joshua Crofts via B4 Relay Date: Mon, 25 May 2026 10:20:21 +0200 Subject: [PATCH v4 7/8] iio: light: opt3001: switch driver to managed resources 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: <20260525-opt3001-cleanup-v4-7-65b36a174f78@gmail.com> References: <20260525-opt3001-cleanup-v4-0-65b36a174f78@gmail.com> In-Reply-To: <20260525-opt3001-cleanup-v4-0-65b36a174f78@gmail.com> To: Jonathan Cameron , David Lechner , =?utf-8?q?Nuno_S=C3=A1?= , Andy Shevchenko 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=1779697227; l=4208; i=joshua.crofts1@gmail.com; s=20260422; h=from:subject:message-id; bh=Ax4yn5eTBCQuhd8dscEiYEPm4u5j8WqMLN8lqGfUPW8=; b=ZBVjkHnu5W1oFl+Vi33mgKrEWOkwIyePP/vQB2OTkmhiWbZQPKmIaCt6tCEvmAohqvHyncV8j qY3DT1IJ/fHCM288nmziGz8rLC+O/iEsy7sW6T3qZZFTTDK7+kSJhgN 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 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 --- drivers/iio/light/opt3001.c | 88 ++++++++++++++++++++---------------------= ---- 1 file changed, 39 insertions(+), 49 deletions(-) diff --git a/drivers/iio/light/opt3001.c b/drivers/iio/light/opt3001.c index 14a0915330672209a8de60fc4f3debdd6d6bba76..e35b5cf665e2651e8b6a576aa34= fed5082f4ed19 100644 --- a/drivers/iio/light/opt3001.c +++ b/drivers/iio/light/opt3001.c @@ -705,6 +705,30 @@ 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 &client->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_v= al); + 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; @@ -743,6 +767,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", @@ -836,7 +865,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 @@ -858,59 +890,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 - ret =3D iio_device_register(iio); - if (ret) - goto free_irq; - - return 0; - -free_irq: - if (irq > 0) - free_irq(irq, iio); - - return ret; -} - -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 { @@ -951,7 +942,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 Mon Jun 8 23:56:53 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 571403E16A5; Mon, 25 May 2026 08:20:26 +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=1779697226; cv=none; b=rw8Mm+tEsMMZMULVd0+ACA4af4X2q0umEJ2vtc0Iq3w//zy/VxtYQY8e3s1z5FxWG50Rjne3puafOzJgIXSO4trvkApWgGJAXe9ZzWdVhWTPrVHfI489a3ngEZDO7rWW5OdTzOf578E7kyr/6yxp2ZdHxdn8YGZQNV2cVuf7Rz8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779697226; c=relaxed/simple; bh=PAmiiyvog4vMHDca2wkfy5RtYs+QyYpNTfZrmhnDoPo=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=uROSZmQ+u4ZSrBKYTsxxIFK9Pd2ifPi9sCdifAjP6jwnHNNfB3DT9ts5aWD0qlY2oDbsn2lbJSil1g6ppzykx5vEjVTskR5wmBPXHMdyY+7WDJxmUiPjO9DjTp7YKSliz8kWO3G2lv/uQJ3Z2635tYyyzUtUi4Su6pLv4FWVqjQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=dj4PaXPB; 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="dj4PaXPB" Received: by smtp.kernel.org (Postfix) with ESMTPS id 26C50C2BD01; Mon, 25 May 2026 08:20:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1779697226; bh=PAmiiyvog4vMHDca2wkfy5RtYs+QyYpNTfZrmhnDoPo=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=dj4PaXPBFWAqvbdW6r014jbpSxP8d01XpBPY4UeCi2rFU8M/yO+z+u+AXgVWvPDjt 4sUCsSw7SlZT/1lKLJCLu6GwaBXmWZGH9N3nBbwNw1b6M4LGRFHmgUNSvV9tQsF22b rcEnoBRroHdMZuv/ulNjV42keKc1wCN++yXUSLbj7z24CgBFwfJffvSqYFyTND9zlC lCULy89mQDR5RY7GCBC7RE0Q6zS7Ju1Kf3g1GGm2aoWISGhLBpsjdCEbt9XJ5mg0b6 tDId6KfPFXl2hRibWp81gED816vh/4y1hB63pt8D/9a0aejARvkDvl4wYTKbJC2v5z T43Fj86fkidYw== 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 20402CD5BBF; Mon, 25 May 2026 08:20:26 +0000 (UTC) From: Joshua Crofts via B4 Relay Date: Mon, 25 May 2026 10:20:22 +0200 Subject: [PATCH v4 8/8] 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: <20260525-opt3001-cleanup-v4-8-65b36a174f78@gmail.com> References: <20260525-opt3001-cleanup-v4-0-65b36a174f78@gmail.com> In-Reply-To: <20260525-opt3001-cleanup-v4-0-65b36a174f78@gmail.com> To: Jonathan Cameron , David Lechner , =?utf-8?q?Nuno_S=C3=A1?= , Andy Shevchenko 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=1779697227; l=901; i=joshua.crofts1@gmail.com; s=20260422; h=from:subject:message-id; bh=e0FEzpVldsPt7x0C57i9zGOxx0GFmKdZq9MhceXE7aU=; b=natZBCGqCGJr+RedNb8eCq03yq6sNn2h1dH7JA5kC/CwhsVslf7ed3xZWASskUTnrGfzNAApw Uxj186nVxVPBmc/zXLykJz5+hDOovWSqVxP/FE7vCHTxBf6z/fxbp1l 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. While we're at it, add a comment to bool ok_to_ignore_lock. No functional change. Signed-off-by: Joshua Crofts --- drivers/iio/light/opt3001.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/drivers/iio/light/opt3001.c b/drivers/iio/light/opt3001.c index e35b5cf665e2651e8b6a576aa34fed5082f4ed19..8d89d539b19b862ad7a33cfabd9= 22ddf8b826b2c 100644 --- a/drivers/iio/light/opt3001.c +++ b/drivers/iio/light/opt3001.c @@ -103,7 +103,13 @@ struct opt3001_chip_info { struct opt3001 { struct i2c_client *client; =20 + /* + * Ensure data capture and read-modify-write sequences are + * not interrupted. + */ struct mutex lock; + + /* Allows for IRQs to bypass locking mechanism */ bool ok_to_ignore_lock; bool result_ready; wait_queue_head_t result_ready_queue; --=20 2.47.3