Thread (66 messages) 66 messages, 15 authors, 1d ago

Re: [PATCH 01/42] of: reserved_mem: Introduce devres-managed initialization functions

From: Mukesh Ojha <hidden>
Date: 2026-07-17 15:38:19
Also in: dri-devel, imx, linux-arm-msm, linux-aspeed, linux-devicetree, linux-media, linux-mediatek, linux-mips, linux-mmc, linux-remoteproc, linux-sound, linux-staging, linux-sunxi, linux-tegra, lkml, openbmc

On Thu, Jul 16, 2026 at 03:00:48PM -0500, Rob Herring wrote:
On Sat, Jul 04, 2026 at 01:08:14AM +0530, Mukesh Ojha wrote:
quoted
From: Konrad Dybcio <redacted>

Introduce devres-based helpers for of_reserved_mem_device_init(_by_idx)
to help fight dangling references and ever so slightly reduce the
number of boilerplate deinitialization calls.

Signed-off-by: Konrad Dybcio <redacted>
Signed-off-by: Mukesh Ojha <redacted>
---
 drivers/of/of_reserved_mem.c    | 41 +++++++++++++++++++++++++++++++++
 include/linux/of_reserved_mem.h | 25 ++++++++++++++++++++
 2 files changed, 66 insertions(+)
diff --git a/drivers/of/of_reserved_mem.c b/drivers/of/of_reserved_mem.c
index 82222bd45ac6..b35541e9fbe8 100644
--- a/drivers/of/of_reserved_mem.c
+++ b/drivers/of/of_reserved_mem.c
@@ -787,6 +787,47 @@ void of_reserved_mem_device_release(struct device *dev)
 }
 EXPORT_SYMBOL_GPL(of_reserved_mem_device_release);
 
+static void devm_of_reserved_mem_device_release(struct device *dev, void *res)
+{
+	of_reserved_mem_device_release(*(struct device **)res);
+}
+
+/**
+ * devm_of_reserved_mem_device_init_by_idx() - Resource managed of_reserved_mem_device_init_by_idx()
+ * @dev: Pointer to the device to configure
+ * @np: Pointer to the device node with 'memory-region' property
+ * @idx: Index of selected region
+ *
+ * This is a resource managed version of of_reserved_mem_device_init_by_idx().
+ * The reserved memory region will be released automatically when the device
+ * is unbound.
+ *
+ * Returns: Negative errno on failure or zero on success.
+ */
+int devm_of_reserved_mem_device_init_by_idx(struct device *dev,
+					    struct device_node *np, int idx)
It looks to me like the only 2? users of this could be converted to 
devm_of_reserved_mem_device_init() instead. The mmc one obviously can. 
The imx one depends if np is dev->of_node. I'm not a fan of APIs with 
only a few users.
You are right, mmc can be but imx can't. I can make this static and drop
the API usage from imx but fix the leak by release function.

-- 
-Mukesh Ojha
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help