From: Aldo Conte <aldocontelk@gmail.com>
To: jic23@kernel.org
Cc: dlechner@baylibre.com, nuno.sa@analog.com, andy@kernel.org,
shuah@kernel.org, linux-iio@vger.kernel.org,
linux-kernel@vger.kernel.org,
linux-kernel-mentees@lists.linux.dev,
Joshua Crofts <joshua.crofts1@gmail.com>
Subject: Re: [PATCH v2 3/5] iio: light: tcs3472: use devm for resource management
Date: Wed, 13 May 2026 22:29:55 +0200 [thread overview]
Message-ID: <0de09560-6a79-46f0-8a63-3fb904a38231@gmail.com> (raw)
In-Reply-To: <20260512223215.25596-4-aldocontelk@gmail.com>
On 5/13/26 00:32, Aldo Conte wrote:
> Convert the driver to use device-managed resource allocation:
> - Add tcs3472_powerdown_action() and register it with
> devm_add_action_or_reset() to ensure the device is powered down on
> cleanup. Before this patch, the chip remained powered if probe
> failed after enabling it.
> - Replace iio_triggered_buffer_setup() with
> devm_iio_triggered_buffer_setup().
> - Replace request_threaded_irq() with devm_request_threaded_irq().
> - Replace iio_device_register() with devm_iio_device_register().
> - Remove tcs3472_remove() as all cleanup is now handled by devm.
>
> Rewrite the read-modify-write pattern in tcs3472_powerdown() and
> tcs3472_resume() so the new register value is computed first, written
> to the chip, and committed to data->enable only on success.
>
> Use a local 'dev = &client->dev' in tcs3472_probe() to keep the devm
> calls compact.
>
> Suggested-by: Andy Shevchenko <andy@kernel.org>
> Signed-off-by: Aldo Conte <aldocontelk@gmail.com>
> ---
> v2:
> (Suggested by Andy)
> - Rewrote read-modify-write in tcs3472_powerdown() and tcs3472_resume()
> - Use local 'struct device *dev = &client->dev' in probe.
> - Dropped "Compiled with W=1" and test details from the commit message.
>
> drivers/iio/light/tcs3472.c | 107 +++++++++++++++++-------------------
> 1 file changed, 51 insertions(+), 56 deletions(-)
>
> diff --git a/drivers/iio/light/tcs3472.c b/drivers/iio/light/tcs3472.c
> index 4fd4fd74d0d6..7a6dc8360326 100644
> --- a/drivers/iio/light/tcs3472.c
> +++ b/drivers/iio/light/tcs3472.c
> @@ -427,13 +427,38 @@ static const struct iio_info tcs3472_info = {
> .attrs = &tcs3472_attribute_group,
> };
>
> +static int tcs3472_powerdown(struct tcs3472_data *data)
> +{
> + u8 enable_mask = TCS3472_ENABLE_AEN | TCS3472_ENABLE_PON;
> + u8 value;
> + int ret;
> +
> + guard(mutex)(&data->lock);
> +
> + value = data->enable & ~enable_mask;
> +
> + ret = i2c_smbus_write_byte_data(data->client, TCS3472_ENABLE, value);
> + if (ret)
> + return ret;
> +
> + data->enable = value;
> +
> + return 0;
> +}
> +
> +static void tcs3472_powerdown_action(void *data)
> +{
> + tcs3472_powerdown(data);
> +}
> +
> static int tcs3472_probe(struct i2c_client *client)
> {
> + struct device *dev = &client->dev;
> struct tcs3472_data *data;
> struct iio_dev *indio_dev;
> int ret;
>
> - indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*data));
> + indio_dev = devm_iio_device_alloc(dev, sizeof(*data));
> if (indio_dev == NULL)
> return -ENOMEM;
>
Hi Jonathan,
In v3 I have a small style cleanup: replacing 'if (indio_dev == NULL)'
with 'if (!indio_dev)' in tcs3472_probe(). This was suggested by
Joshua Crofts in his v2 review.
What do you prefer it is a separate patch
or folded into the devm conversion patch (which already modifies the
context next to that line).
Either way works for me. Which do you prefer?
Thanks,
Aldo
...
next prev parent reply other threads:[~2026-05-13 20:29 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-12 22:32 [PATCH v2 0/5] devm conversion, wait time, locking cleanup Aldo Conte
2026-05-12 22:32 ` [PATCH v2 1/5] iio: light: tcs3472: sort headers alphabetically Aldo Conte
2026-05-13 8:15 ` Joshua Crofts
2026-05-12 22:32 ` [PATCH v2 2/5] iio: light: tcs3472: convert remaining locking to guard(mutex) Aldo Conte
2026-05-13 7:47 ` Joshua Crofts
2026-05-13 11:00 ` Andy Shevchenko
2026-05-13 10:58 ` Andy Shevchenko
2026-05-12 22:32 ` [PATCH v2 3/5] iio: light: tcs3472: use devm for resource management Aldo Conte
2026-05-13 8:07 ` Joshua Crofts
2026-05-13 11:02 ` Andy Shevchenko
2026-05-13 20:29 ` Aldo Conte [this message]
2026-05-12 22:32 ` [PATCH v2 4/5] iio: light: tcs3472: implement wait time and sampling frequency Aldo Conte
2026-05-13 11:17 ` Andy Shevchenko
2026-05-12 22:32 ` [PATCH v2 5/5] iio: light: tcs3472: move standalone return to default case Aldo Conte
2026-05-13 8:16 ` Joshua Crofts
2026-05-13 11:23 ` Andy Shevchenko
2026-05-13 16:12 ` Aldo Conte
2026-05-13 17:58 ` Andy Shevchenko
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=0de09560-6a79-46f0-8a63-3fb904a38231@gmail.com \
--to=aldocontelk@gmail.com \
--cc=andy@kernel.org \
--cc=dlechner@baylibre.com \
--cc=jic23@kernel.org \
--cc=joshua.crofts1@gmail.com \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel-mentees@lists.linux.dev \
--cc=linux-kernel@vger.kernel.org \
--cc=nuno.sa@analog.com \
--cc=shuah@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox