From: Jonathan Cameron <jic23@kernel.org>
To: Erikas Bitovtas <xerikasxx@gmail.com>
Cc: "David Lechner" <dlechner@baylibre.com>,
"Nuno Sá" <nuno.sa@analog.com>,
"Andy Shevchenko" <andy@kernel.org>,
"Rob Herring" <robh@kernel.org>,
"Krzysztof Kozlowski" <krzk+dt@kernel.org>,
"Conor Dooley" <conor+dt@kernel.org>,
"Peter Meerwald" <pmeerw@pmeerw.net>,
linux-iio@vger.kernel.org, devicetree@vger.kernel.org,
linux-kernel@vger.kernel.org,
~postmarketos/upstreaming@lists.sr.ht,
phone-devel@vger.kernel.org
Subject: Re: [PATCH v3 3/6] iio: light: vcnl4000: replace mutex_init with devm_mutex_init
Date: Sun, 15 Mar 2026 18:26:42 +0000 [thread overview]
Message-ID: <20260315182642.5c6918ad@jic23-huawei> (raw)
In-Reply-To: <20260314-vcnl4000-regulators-v3-3-3c4a48d30676@gmail.com>
On Sat, 14 Mar 2026 18:06:32 +0200
Erikas Bitovtas <xerikasxx@gmail.com> wrote:
> Replace mutex_init used across driver with its device-managed
> counterpart, so all assigned mutexes get destroyed.
>
> Signed-off-by: Erikas Bitovtas <xerikasxx@gmail.com>
Hi Erikas,
One related area that I noticed whilst checking this patch was
safe wrt to ordering. I think cleaning that up before this
patch would make this one more obviously correct.
Jonathan
> ---
> drivers/iio/light/vcnl4000.c | 17 ++++++++++++++---
> 1 file changed, 14 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/iio/light/vcnl4000.c b/drivers/iio/light/vcnl4000.c
> index 939ff2d65105..0ee307fc5ab7 100644
> --- a/drivers/iio/light/vcnl4000.c
> +++ b/drivers/iio/light/vcnl4000.c
> @@ -356,6 +356,8 @@ static int vcnl4200_set_power_state(struct vcnl4000_data *data, bool on)
>
> static int vcnl4200_init(struct vcnl4000_data *data)
> {
> + struct i2c_client *client = data->client;
> + struct device *dev = &client->dev;
> int ret, id;
> u16 regval;
>
> @@ -400,8 +402,14 @@ static int vcnl4200_init(struct vcnl4000_data *data)
> }
> data->al_scale = data->chip_spec->ulux_step;
> data->ps_scale = 16;
> - mutex_init(&data->vcnl4200_al.lock);
> - mutex_init(&data->vcnl4200_ps.lock);
> +
> + ret = devm_mutex_init(dev, &data->vcnl4200_al.lock);
> + if (ret < 0)
> + return ret;
> +
> + ret = devm_mutex_init(dev, &data->vcnl4200_ps.lock);
> + if (ret < 0)
> + return ret;
I think this is ok because the only thing undone in remove is the power state
setting that is the last call in this function but the mixture of non
devm and devm calls in init is less than helpful for readability.
Given both init() callbacks end with
return data->chip_spec->set_power_state(data, true) and the remove
just calls that callback without any wrapping up in different init functions
I'm thinking it would make it all more readable if we didn't consider
turning on the power as part of the _init() but instead called it
directly from probe().
That would perhaps give more readable code and avoid mix of devm cleanup
and other cleanup in those callbacks.
>
> /* Use 16 bits proximity sensor readings */
> ret = i2c_smbus_read_word_data(data->client, VCNL4200_PS_CONF1);
> @@ -1985,6 +1993,7 @@ static int vcnl4000_probe(struct i2c_client *client)
> const struct i2c_device_id *id = i2c_client_get_device_id(client);
> struct vcnl4000_data *data;
> struct iio_dev *indio_dev;
> + struct device *dev = &client->dev;
> int ret;
>
> indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*data));
> @@ -1997,7 +2006,9 @@ static int vcnl4000_probe(struct i2c_client *client)
> data->id = id->driver_data;
> data->chip_spec = &vcnl4000_chip_spec_cfg[data->id];
>
> - mutex_init(&data->vcnl4000_lock);
> + ret = devm_mutex_init(dev, &data->vcnl4000_lock);
> + if (ret < 0)
> + return ret;
>
> ret = data->chip_spec->init(data);
> if (ret < 0)
>
next prev parent reply other threads:[~2026-03-15 18:26 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-14 16:06 [PATCH v3 0/6] iio: light: vcnl4000: add regulator support Erikas Bitovtas
2026-03-14 16:06 ` [PATCH v3 1/6] dt-bindings: iio: light: vcnl4000: add regulators Erikas Bitovtas
2026-03-15 8:49 ` Krzysztof Kozlowski
2026-03-15 17:07 ` Erikas Bitovtas
2026-03-14 16:06 ` [PATCH v3 2/6] iio: light: vcnl4000: sort includes by their name Erikas Bitovtas
2026-03-14 16:06 ` [PATCH v3 3/6] iio: light: vcnl4000: replace mutex_init with devm_mutex_init Erikas Bitovtas
2026-03-14 19:51 ` David Lechner
2026-03-15 18:26 ` Jonathan Cameron [this message]
2026-03-16 10:24 ` Andy Shevchenko
2026-03-14 16:06 ` [PATCH v3 4/6] iio: light: vcnl4000: add support for regulators Erikas Bitovtas
2026-03-15 18:27 ` Jonathan Cameron
2026-03-16 10:27 ` Andy Shevchenko
2026-03-14 16:06 ` [PATCH v3 5/6] iio: light: vcnl4000: remove error messages for trigger and irq Erikas Bitovtas
2026-03-15 18:31 ` Jonathan Cameron
2026-03-15 19:15 ` Erikas Bitovtas
2026-03-15 21:24 ` Jonathan Cameron
2026-03-14 16:06 ` [PATCH v3 6/6] iio: light: vcnl4000: use variables for I2C client and device instances Erikas Bitovtas
2026-03-16 10:39 ` Andy Shevchenko
2026-03-16 10:50 ` Erikas Bitovtas
2026-03-16 11:10 ` Andy Shevchenko
2026-03-14 19:53 ` [PATCH v3 0/6] iio: light: vcnl4000: add regulator support David Lechner
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=20260315182642.5c6918ad@jic23-huawei \
--to=jic23@kernel.org \
--cc=andy@kernel.org \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=dlechner@baylibre.com \
--cc=krzk+dt@kernel.org \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=nuno.sa@analog.com \
--cc=phone-devel@vger.kernel.org \
--cc=pmeerw@pmeerw.net \
--cc=robh@kernel.org \
--cc=xerikasxx@gmail.com \
--cc=~postmarketos/upstreaming@lists.sr.ht \
/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