From: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
To: Srinivas Kandagatla <srini@kernel.org>,
Bartosz Golaszewski <brgl@kernel.org>,
Johan Hovold <johan@kernel.org>,
Loic Poulain <loic.poulain@oss.qualcomm.com>
Cc: linux-kernel@vger.kernel.org, brgl@kernel.org,
Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
Subject: [PATCH v4 06/10] nvmem: remove unneeded __nvmem_device_put()
Date: Thu, 21 May 2026 16:25:39 +0200 [thread overview]
Message-ID: <20260521-nvmem-unbind-v4-6-7fa136759491@oss.qualcomm.com> (raw)
In-Reply-To: <20260521-nvmem-unbind-v4-0-7fa136759491@oss.qualcomm.com>
__nvmem_device_put() is wrapped by nvmem_device_put() but there's no
extra functionality offered by the latter so just fold one into the
other. There's still the corresponding __nvmem_device_get() so in order
to keep things symmetrical: rename it to nvmem_device_match() to better
reflect its functionality and not confuse users by its presence in the
absence of the similarly prefixed put() counterpart.
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
---
drivers/nvmem/core.c | 35 +++++++++++++++--------------------
1 file changed, 15 insertions(+), 20 deletions(-)
diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c
index 623aeb9533c0124bb893d0c229570e00cfa3c52a..24e079240ebbb0899d6d91f8147210a64d4414cb 100644
--- a/drivers/nvmem/core.c
+++ b/drivers/nvmem/core.c
@@ -1106,7 +1106,7 @@ struct nvmem_device *devm_nvmem_register(struct device *dev,
}
EXPORT_SYMBOL_GPL(devm_nvmem_register);
-static struct nvmem_device *__nvmem_device_get(void *data,
+static struct nvmem_device *nvmem_device_match(void *data,
int (*match)(struct device *dev, const void *data))
{
struct nvmem_device *nvmem = NULL;
@@ -1134,13 +1134,6 @@ static struct nvmem_device *__nvmem_device_get(void *data,
return nvmem;
}
-static void __nvmem_device_put(struct nvmem_device *nvmem)
-{
- put_device(&nvmem->dev);
- module_put(nvmem->owner);
- kref_put(&nvmem->refcnt, nvmem_device_release);
-}
-
#if IS_ENABLED(CONFIG_OF)
/**
* of_nvmem_device_get() - Get nvmem device from a given id
@@ -1165,7 +1158,7 @@ struct nvmem_device *of_nvmem_device_get(struct device_node *np, const char *id)
if (!nvmem_np)
return ERR_PTR(-ENOENT);
- nvmem = __nvmem_device_get(nvmem_np, device_match_of_node);
+ nvmem = nvmem_device_match(nvmem_np, device_match_of_node);
of_node_put(nvmem_np);
return nvmem;
}
@@ -1193,7 +1186,7 @@ struct nvmem_device *nvmem_device_get(struct device *dev, const char *dev_name)
}
- return __nvmem_device_get((void *)dev_name, device_match_name);
+ return nvmem_device_match((void *)dev_name, device_match_name);
}
EXPORT_SYMBOL_GPL(nvmem_device_get);
@@ -1209,7 +1202,7 @@ EXPORT_SYMBOL_GPL(nvmem_device_get);
struct nvmem_device *nvmem_device_find(void *data,
int (*match)(struct device *dev, const void *data))
{
- return __nvmem_device_get(data, match);
+ return nvmem_device_match(data, match);
}
EXPORT_SYMBOL_GPL(nvmem_device_find);
@@ -1253,7 +1246,9 @@ EXPORT_SYMBOL_GPL(devm_nvmem_device_put);
*/
void nvmem_device_put(struct nvmem_device *nvmem)
{
- __nvmem_device_put(nvmem);
+ put_device(&nvmem->dev);
+ module_put(nvmem->owner);
+ kref_put(&nvmem->refcnt, nvmem_device_release);
}
EXPORT_SYMBOL_GPL(nvmem_device_put);
@@ -1332,7 +1327,7 @@ nvmem_cell_get_from_lookup(struct device *dev, const char *con_id)
if ((strcmp(lookup->dev_id, dev_id) == 0) &&
(strcmp(lookup->con_id, con_id) == 0)) {
/* This is the right entry. */
- nvmem = __nvmem_device_get((void *)lookup->nvmem_name,
+ nvmem = nvmem_device_match((void *)lookup->nvmem_name,
device_match_name);
if (IS_ERR(nvmem))
/* Provider may not be registered yet. */
@@ -1341,12 +1336,12 @@ nvmem_cell_get_from_lookup(struct device *dev, const char *con_id)
cell_entry = nvmem_find_cell_entry_by_name(nvmem,
lookup->cell_name);
if (!cell_entry) {
- __nvmem_device_put(nvmem);
+ nvmem_device_put(nvmem);
cell = ERR_PTR(-ENOENT);
} else {
cell = nvmem_create_cell(cell_entry, con_id, 0);
if (IS_ERR(cell))
- __nvmem_device_put(nvmem);
+ nvmem_device_put(nvmem);
}
break;
}
@@ -1444,7 +1439,7 @@ struct nvmem_cell *of_nvmem_cell_get(struct device_node *np, const char *id)
}
}
- nvmem = __nvmem_device_get(nvmem_np, device_match_of_node);
+ nvmem = nvmem_device_match(nvmem_np, device_match_of_node);
of_node_put(nvmem_np);
if (IS_ERR(nvmem)) {
of_node_put(cell_np);
@@ -1454,7 +1449,7 @@ struct nvmem_cell *of_nvmem_cell_get(struct device_node *np, const char *id)
ret = nvmem_layout_module_get_optional(nvmem);
if (ret) {
of_node_put(cell_np);
- __nvmem_device_put(nvmem);
+ nvmem_device_put(nvmem);
return ERR_PTR(ret);
}
@@ -1463,14 +1458,14 @@ struct nvmem_cell *of_nvmem_cell_get(struct device_node *np, const char *id)
if (!cell_entry) {
nvmem_layout_module_put(nvmem);
ret = nvmem->layout ? -EPROBE_DEFER : -ENOENT;
- __nvmem_device_put(nvmem);
+ nvmem_device_put(nvmem);
return ERR_PTR(ret);
}
cell = nvmem_create_cell(cell_entry, id, cell_index);
if (IS_ERR(cell)) {
nvmem_layout_module_put(nvmem);
- __nvmem_device_put(nvmem);
+ nvmem_device_put(nvmem);
}
return cell;
@@ -1585,7 +1580,7 @@ void nvmem_cell_put(struct nvmem_cell *cell)
kfree(cell);
nvmem_layout_module_put(nvmem);
- __nvmem_device_put(nvmem);
+ nvmem_device_put(nvmem);
}
EXPORT_SYMBOL_GPL(nvmem_cell_put);
--
2.47.3
next prev parent reply other threads:[~2026-05-21 14:26 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-21 14:25 [PATCH v4 00/10] nvmem: rework nvmem core and allow unbinding with active consumers Bartosz Golaszewski
2026-05-21 14:25 ` [PATCH v4 01/10] nvmem: core: fix use-after-free bugs in error paths Bartosz Golaszewski
2026-05-21 14:25 ` [PATCH v4 02/10] nvmem: remove unused field from struct nvmem_device Bartosz Golaszewski
2026-05-21 14:25 ` [PATCH v4 03/10] nvmem: return -EOPNOTSUPP to in-kernel users on missing callbacks Bartosz Golaszewski
2026-05-21 14:25 ` [PATCH v4 04/10] nvmem: check the return value of gpiod_set_value_cansleep() Bartosz Golaszewski
2026-05-21 14:25 ` [PATCH v4 05/10] nvmem: simplify locking with guard() Bartosz Golaszewski
2026-05-21 14:25 ` Bartosz Golaszewski [this message]
2026-05-21 14:25 ` [PATCH v4 07/10] nvmem: split out the reg_read/write() callbacks out of struct nvmem_device Bartosz Golaszewski
2026-05-21 14:25 ` [PATCH v4 08/10] nvmem: simplify nvmem_sysfs_remove_compat() Bartosz Golaszewski
2026-05-21 14:25 ` [PATCH v4 09/10] nvmem: remove duplicated reference counting Bartosz Golaszewski
2026-05-21 14:25 ` [PATCH v4 10/10] nvmem: protect nvmem_device::ops with SRCU Bartosz Golaszewski
2026-05-30 20:40 ` (subset) [PATCH v4 00/10] nvmem: rework nvmem core and allow unbinding with active consumers Srinivas Kandagatla
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=20260521-nvmem-unbind-v4-6-7fa136759491@oss.qualcomm.com \
--to=bartosz.golaszewski@oss.qualcomm.com \
--cc=brgl@kernel.org \
--cc=johan@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=loic.poulain@oss.qualcomm.com \
--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
all inboxes | Powered by JetHome®