* [PATCH 1/2] nvmem: Drop OF node reference on nvmem_add_one_cell() failure
@ 2025-12-31 12:09 Krzysztof Kozlowski
2025-12-31 12:09 ` [PATCH 2/2] nvmem: Simplify with scoped for each OF child loop Krzysztof Kozlowski
2026-01-15 11:04 ` [PATCH 1/2] nvmem: Drop OF node reference on nvmem_add_one_cell() failure Srinivas Kandagatla
0 siblings, 2 replies; 3+ messages in thread
From: Krzysztof Kozlowski @ 2025-12-31 12:09 UTC (permalink / raw)
To: Srinivas Kandagatla, Michael Walle, Greg Kroah-Hartman, linux-kernel
Cc: Krzysztof Kozlowski, stable
If nvmem_add_one_cell() failed, the ownership of "child" (or "info.np"),
thus its OF reference, is not passed further and function should clean
up by putting the reference it got via earlier of_node_get(). Note that
this is independent of references obtained via for_each_child_of_node()
loop.
Fixes: 50014d659617 ("nvmem: core: use nvmem_add_one_cell() in nvmem_add_cells_from_of()")
Cc: <stable@vger.kernel.org>
Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@oss.qualcomm.com>
---
drivers/nvmem/core.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c
index 387c88c55259..ff68fd5ad3d6 100644
--- a/drivers/nvmem/core.c
+++ b/drivers/nvmem/core.c
@@ -831,6 +831,7 @@ static int nvmem_add_cells_from_dt(struct nvmem_device *nvmem, struct device_nod
kfree(info.name);
if (ret) {
of_node_put(child);
+ of_node_put(info.np);
return ret;
}
}
--
2.51.0
^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH 2/2] nvmem: Simplify with scoped for each OF child loop
2025-12-31 12:09 [PATCH 1/2] nvmem: Drop OF node reference on nvmem_add_one_cell() failure Krzysztof Kozlowski
@ 2025-12-31 12:09 ` Krzysztof Kozlowski
2026-01-15 11:04 ` [PATCH 1/2] nvmem: Drop OF node reference on nvmem_add_one_cell() failure Srinivas Kandagatla
1 sibling, 0 replies; 3+ messages in thread
From: Krzysztof Kozlowski @ 2025-12-31 12:09 UTC (permalink / raw)
To: Srinivas Kandagatla, Michael Walle, Greg Kroah-Hartman, linux-kernel
Cc: Krzysztof Kozlowski
Use scoped for-each loop when iterating over device nodes to make code a
bit simpler.
Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@oss.qualcomm.com>
---
drivers/nvmem/core.c | 6 +-----
1 file changed, 1 insertion(+), 5 deletions(-)
diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c
index ff68fd5ad3d6..c6180cf1dd91 100644
--- a/drivers/nvmem/core.c
+++ b/drivers/nvmem/core.c
@@ -789,11 +789,10 @@ static int nvmem_validate_keepouts(struct nvmem_device *nvmem)
static int nvmem_add_cells_from_dt(struct nvmem_device *nvmem, struct device_node *np)
{
struct device *dev = &nvmem->dev;
- struct device_node *child;
const __be32 *addr;
int len, ret;
- for_each_child_of_node(np, child) {
+ for_each_child_of_node_scoped(np, child) {
struct nvmem_cell_info info = {0};
addr = of_get_property(child, "reg", &len);
@@ -801,7 +800,6 @@ static int nvmem_add_cells_from_dt(struct nvmem_device *nvmem, struct device_nod
continue;
if (len < 2 * sizeof(u32)) {
dev_err(dev, "nvmem: invalid reg on %pOF\n", child);
- of_node_put(child);
return -EINVAL;
}
@@ -817,7 +815,6 @@ static int nvmem_add_cells_from_dt(struct nvmem_device *nvmem, struct device_nod
info.nbits < 1 ||
info.bit_offset + info.nbits > BITS_PER_BYTE * info.bytes) {
dev_err(dev, "nvmem: invalid bits on %pOF\n", child);
- of_node_put(child);
return -EINVAL;
}
}
@@ -830,7 +827,6 @@ static int nvmem_add_cells_from_dt(struct nvmem_device *nvmem, struct device_nod
ret = nvmem_add_one_cell(nvmem, &info);
kfree(info.name);
if (ret) {
- of_node_put(child);
of_node_put(info.np);
return ret;
}
--
2.51.0
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH 1/2] nvmem: Drop OF node reference on nvmem_add_one_cell() failure
2025-12-31 12:09 [PATCH 1/2] nvmem: Drop OF node reference on nvmem_add_one_cell() failure Krzysztof Kozlowski
2025-12-31 12:09 ` [PATCH 2/2] nvmem: Simplify with scoped for each OF child loop Krzysztof Kozlowski
@ 2026-01-15 11:04 ` Srinivas Kandagatla
1 sibling, 0 replies; 3+ messages in thread
From: Srinivas Kandagatla @ 2026-01-15 11:04 UTC (permalink / raw)
To: Michael Walle, Greg Kroah-Hartman, linux-kernel, Krzysztof Kozlowski
Cc: stable
On Wed, 31 Dec 2025 13:09:50 +0100, Krzysztof Kozlowski wrote:
> If nvmem_add_one_cell() failed, the ownership of "child" (or "info.np"),
> thus its OF reference, is not passed further and function should clean
> up by putting the reference it got via earlier of_node_get(). Note that
> this is independent of references obtained via for_each_child_of_node()
> loop.
>
>
> [...]
Applied, thanks!
[1/2] nvmem: Drop OF node reference on nvmem_add_one_cell() failure
commit: 3bc276e70c0cd66350a9a5d39bd3f638de362941
[2/2] nvmem: Simplify with scoped for each OF child loop
commit: f28a32e7a5c5eb27679236d0aa20979f0353f52e
Best regards,
--
Srinivas Kandagatla <srini@kernel.org>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-01-15 11:04 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-12-31 12:09 [PATCH 1/2] nvmem: Drop OF node reference on nvmem_add_one_cell() failure Krzysztof Kozlowski
2025-12-31 12:09 ` [PATCH 2/2] nvmem: Simplify with scoped for each OF child loop Krzysztof Kozlowski
2026-01-15 11:04 ` [PATCH 1/2] nvmem: Drop OF node reference on nvmem_add_one_cell() failure Srinivas Kandagatla
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®