From: Johan Hovold <johan@kernel.org>
To: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
Cc: Srinivas Kandagatla <srini@kernel.org>,
Bartosz Golaszewski <brgl@kernel.org>,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2 4/7] nvmem: simplify locking with guard()
Date: Mon, 23 Mar 2026 17:35:48 +0100 [thread overview]
Message-ID: <acFr5OItOcTNT2Oj@hovoldconsulting.com> (raw)
In-Reply-To: <20260223-nvmem-unbind-v2-4-0df33a933dca@oss.qualcomm.com>
On Mon, Feb 23, 2026 at 11:57:05AM +0100, Bartosz Golaszewski wrote:
> Use lock guards from cleanup.h to simplify locking. While at it: add the
> missing mutex.h include.
> @@ -1335,7 +1326,7 @@ nvmem_cell_get_from_lookup(struct device *dev, const char *con_id)
>
> dev_id = dev_name(dev);
>
> - mutex_lock(&nvmem_lookup_mutex);
> + guard(mutex)(&nvmem_mutex);
>
> list_for_each_entry(lookup, &nvmem_lookup_list, node) {
> if ((strcmp(lookup->dev_id, dev_id) == 0) &&
> @@ -1343,11 +1334,9 @@ nvmem_cell_get_from_lookup(struct device *dev, const char *con_id)
> /* This is the right entry. */
> nvmem = __nvmem_device_get((void *)lookup->nvmem_name,
> device_match_name);
> - if (IS_ERR(nvmem)) {
> + if (IS_ERR(nvmem))
> /* Provider may not be registered yet. */
> - cell = ERR_CAST(nvmem);
> - break;
> - }
> + return ERR_CAST(nvmem);
Please keep the brackets here for readability.
>
> cell_entry = nvmem_find_cell_entry_by_name(nvmem,
> lookup->cell_name);
> @@ -1363,7 +1352,6 @@ nvmem_cell_get_from_lookup(struct device *dev, const char *con_id)
> }
> }
>
> - mutex_unlock(&nvmem_lookup_mutex);
> return cell;
> }
>
> @@ -1379,14 +1367,14 @@ nvmem_find_cell_entry_by_node(struct nvmem_device *nvmem, struct device_node *np
> {
> struct nvmem_cell_entry *iter, *cell = NULL;
>
> - mutex_lock(&nvmem_mutex);
> + guard(mutex)(&nvmem_mutex);
> +
> list_for_each_entry(iter, &nvmem->cells, node) {
> if (np == iter->np) {
> cell = iter;
> break;
Shouldn't you return cell here now?
> }
> }
> - mutex_unlock(&nvmem_mutex);
>
> return cell;
> }
And explicit NULL here (dropping the initialisation above)?
Johan
next prev parent reply other threads:[~2026-03-23 16:35 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-02-23 10:57 [PATCH v2 0/7] nvmem: survive unbind with active consumers Bartosz Golaszewski
2026-02-23 10:57 ` [PATCH v2 1/7] nvmem: remove unused field from struct nvmem_device Bartosz Golaszewski
2026-03-23 16:00 ` Johan Hovold
2026-02-23 10:57 ` [PATCH v2 2/7] nvmem: return -EOPNOTSUPP to in-kernel users on missing callbacks Bartosz Golaszewski
2026-03-23 16:21 ` Johan Hovold
2026-02-23 10:57 ` [PATCH v2 3/7] nvmem: check the return value of gpiod_set_value_cansleep() Bartosz Golaszewski
2026-03-23 16:28 ` Johan Hovold
2026-02-23 10:57 ` [PATCH v2 4/7] nvmem: simplify locking with guard() Bartosz Golaszewski
2026-03-23 16:35 ` Johan Hovold [this message]
2026-02-23 10:57 ` [PATCH v2 5/7] nvmem: remove unneeded __nvmem_device_put() Bartosz Golaszewski
2026-03-23 16:44 ` Johan Hovold
2026-02-23 10:57 ` [PATCH v2 6/7] nvmem: split struct nvmem_device into refcounted and provider-owned data Bartosz Golaszewski
2026-03-17 10:44 ` Johan Hovold
2026-03-17 12:52 ` Bartosz Golaszewski
2026-03-23 16:45 ` Johan Hovold
2026-02-23 10:57 ` [PATCH v2 7/7] nvmem: synchronize nvmem device unregistering with SRCU Bartosz Golaszewski
2026-03-17 11:31 ` Johan Hovold
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=acFr5OItOcTNT2Oj@hovoldconsulting.com \
--to=johan@kernel.org \
--cc=bartosz.golaszewski@oss.qualcomm.com \
--cc=brgl@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=srini@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