From: Mukesh Ojha <mukesh.ojha@oss.qualcomm.com>
To: Bjorn Andersson <andersson@kernel.org>,
Konrad Dybcio <konradybcio@kernel.org>,
Liviu Dudau <liviu.dudau@arm.com>,
Maarten Lankhorst <maarten.lankhorst@linux.intel.com>,
Maxime Ripard <mripard@kernel.org>,
Thomas Zimmermann <tzimmermann@suse.de>,
David Airlie <airlied@gmail.com>, Simona Vetter <simona@ffwll.ch>,
Joel Stanley <joel@jms.id.au>,
Andrew Jeffery <andrew@codeconstruct.com.au>,
Paul Cercueil <paul@crapouillou.net>,
Anitha Chrisanthus <anitha.chrisanthus@intel.com>,
Paul Kocialkowski <paulk@sys-base.io>,
Linus Walleij <linusw@kernel.org>, Chen-Yu Tsai <wens@kernel.org>,
Jernej Skrabec <jernej.skrabec@gmail.com>,
Samuel Holland <samuel@sholland.org>,
Alexey Brodkin <abrodkin@synopsys.com>,
Laurent Pinchart <laurent.pinchart@ideasonboard.com>,
Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>,
Michal Simek <michal.simek@amd.com>,
Daniel Scally <dan.scally@ideasonboard.com>,
Jacopo Mondi <jacopo.mondi@ideasonboard.com>,
Mauro Carvalho Chehab <mchehab@kernel.org>,
Eddie James <eajames@linux.ibm.com>,
Tiffany Lin <tiffany.lin@mediatek.com>,
Andrew-CT Chen <andrew-ct.chen@mediatek.com>,
Yunfei Dong <yunfei.dong@mediatek.com>,
Minghsiu Tsai <minghsiu.tsai@mediatek.com>,
Houlong Wei <houlong.wei@mediatek.com>,
Matthias Brugger <matthias.bgg@gmail.com>,
AngeloGioacchino Del Regno
<angelogioacchino.delregno@collabora.com>,
Joseph Liu <kwliu@nuvoton.com>, Marvin Lin <kflin@nuvoton.com>,
Dmitry Osipenko <dmitry.osipenko@collabora.com>,
Krzysztof Kozlowski <krzk@kernel.org>,
Thierry Reding <thierry.reding@kernel.org>,
Jonathan Hunter <jonathanh@nvidia.com>,
Srinivas Kandagatla <srini@kernel.org>,
Arnd Bergmann <arnd@arndb.de>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Ge Gordon <gordon.ge@bst.ai>,
Adrian Hunter <adrian.hunter@intel.com>,
Ulf Hansson <ulfh@kernel.org>, Rob Herring <robh@kernel.org>,
Saravana Kannan <saravanak@kernel.org>,
Mathieu Poirier <mathieu.poirier@linaro.org>,
Jaroslav Kysela <perex@perex.cz>, Takashi Iwai <tiwai@suse.com>,
Shengjiu Wang <shengjiu.wang@gmail.com>,
Xiubo Li <Xiubo.Lee@gmail.com>,
Liam Girdwood <lgirdwood@gmail.com>,
Mark Brown <broonie@kernel.org>, Frank Li <Frank.Li@nxp.com>,
Sascha Hauer <s.hauer@pengutronix.de>,
Peter Ujfalusi <peter.ujfalusi@linux.intel.com>,
Bard Liao <yung-chuan.liao@linux.intel.com>,
Daniel Baluta <daniel.baluta@nxp.com>,
Orson Zhai <orsonzhai@gmail.com>,
Baolin Wang <baolin.wang@linux.alibaba.com>,
Peter Chen <peter.chen@cixtech.com>,
Fugang Duan <fugang.duan@cixtech.com>
Cc: Ekansh Gupta <ekansh.gupta@oss.qualcomm.com>,
BST Linux Kernel Upstream Group <bst-upstream@bstai.top>,
Fabio Estevam <festevam@gmail.com>,
Nicolin Chen <nicoleotsuka@gmail.com>,
Pengutronix Kernel Team <kernel@pengutronix.de>,
Kai Vehmanen <kai.vehmanen@linux.intel.com>,
Pierre-Louis Bossart <pierre-louis.bossart@linux.dev>,
Vijendar Mukunda <Vijendar.Mukunda@amd.com>,
Chunyan Zhang <zhang.lyra@gmail.com>,
CIX Linux Kernel Upstream Group <cix-kernel-upstream@cixtech.com>,
linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org,
dri-devel@lists.freedesktop.org, linux-aspeed@lists.ozlabs.org,
linux-arm-kernel@lists.infradead.org, linux-mips@vger.kernel.org,
linux-sunxi@lists.linux.dev, linux-media@vger.kernel.org,
openbmc@lists.ozlabs.org, linux-mediatek@lists.infradead.org,
kernel@collabora.com, linux-tegra@vger.kernel.org,
linux-mmc@vger.kernel.org, devicetree@vger.kernel.org,
linux-remoteproc@vger.kernel.org, linux-staging@lists.linux.dev,
linux-sound@vger.kernel.org, linuxppc-dev@lists.ozlabs.org,
imx@lists.linux.dev, sound-open-firmware@alsa-project.org,
Konrad Dybcio <konrad.dybcio@oss.qualcomm.com>,
Mukesh Ojha <mukesh.ojha@oss.qualcomm.com>
Subject: [PATCH 01/42] of: reserved_mem: Introduce devres-managed initialization functions
Date: Sat, 4 Jul 2026 01:08:14 +0530 [thread overview]
Message-ID: <20260703193855.110619-2-mukesh.ojha@oss.qualcomm.com> (raw)
In-Reply-To: <20260703193855.110619-1-mukesh.ojha@oss.qualcomm.com>
From: Konrad Dybcio <konrad.dybcio@oss.qualcomm.com>
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 <konrad.dybcio@oss.qualcomm.com>
Signed-off-by: Mukesh Ojha <mukesh.ojha@oss.qualcomm.com>
---
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)
+{
+ struct device **ptr;
+ int ret;
+
+ ptr = devres_alloc(devm_of_reserved_mem_device_release, sizeof(*ptr),
+ GFP_KERNEL);
+ if (!ptr)
+ return -ENOMEM;
+
+ ret = of_reserved_mem_device_init_by_idx(dev, np, idx);
+ if (ret) {
+ devres_free(ptr);
+ return ret;
+ }
+
+ *ptr = dev;
+ devres_add(dev, ptr);
+
+ return 0;
+}
+EXPORT_SYMBOL_GPL(devm_of_reserved_mem_device_init_by_idx);
+
/**
* of_reserved_mem_lookup() - acquire reserved_mem from a device node
* @np: node pointer of the desired reserved-memory region
diff --git a/include/linux/of_reserved_mem.h b/include/linux/of_reserved_mem.h
index e8b20b29fa68..b9fd78123d77 100644
--- a/include/linux/of_reserved_mem.h
+++ b/include/linux/of_reserved_mem.h
@@ -40,6 +40,9 @@ int of_reserved_mem_device_init_by_name(struct device *dev,
const char *name);
void of_reserved_mem_device_release(struct device *dev);
+int devm_of_reserved_mem_device_init_by_idx(struct device *dev,
+ struct device_node *np, int idx);
+
struct reserved_mem *of_reserved_mem_lookup(struct device_node *np);
int of_reserved_mem_region_to_resource(const struct device_node *np,
unsigned int idx, struct resource *res);
@@ -68,6 +71,13 @@ static inline int of_reserved_mem_device_init_by_name(struct device *dev,
static inline void of_reserved_mem_device_release(struct device *pdev) { }
+static inline int devm_of_reserved_mem_device_init_by_idx(struct device *dev,
+ struct device_node *np,
+ int idx)
+{
+ return -EOPNOTSUPP;
+}
+
static inline struct reserved_mem *of_reserved_mem_lookup(struct device_node *np)
{
return NULL;
@@ -108,4 +118,19 @@ static inline int of_reserved_mem_device_init(struct device *dev)
return of_reserved_mem_device_init_by_idx(dev, dev->of_node, 0);
}
+/**
+ * devm_of_reserved_mem_device_init() - Resource managed version of of_reserved_mem_device_init()
+ * @dev: Pointer to the device to configure
+ *
+ * This is a resource managed version of of_reserved_mem_device_init().
+ * The reserved memory region will be released automatically when the device
+ * is unbound.
+ *
+ * Returns error code or zero on success.
+ */
+static inline int devm_of_reserved_mem_device_init(struct device *dev)
+{
+ return devm_of_reserved_mem_device_init_by_idx(dev, dev->of_node, 0);
+}
+
#endif /* __OF_RESERVED_MEM_H */
--
2.53.0
next prev parent reply other threads:[~2026-07-03 19:39 UTC|newest]
Thread overview: 58+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-03 19:38 [PATCH 00/42] of: reserved_mem: Introduce devres helpers and convert drivers Mukesh Ojha
2026-07-03 19:38 ` Mukesh Ojha [this message]
2026-07-03 19:38 ` [PATCH 02/42] of: reserved_mem: Add devm_of_reserved_mem_device_init_by_name() Mukesh Ojha
2026-07-03 19:38 ` [PATCH 03/42] firmware: qcom: scm: Use devm_of_reserved_mem_device_init() Mukesh Ojha
2026-07-03 23:12 ` Dmitry Baryshkov
2026-07-06 8:32 ` Konrad Dybcio
2026-07-03 19:38 ` [PATCH 04/42] remoteproc: da8xx: " Mukesh Ojha
2026-07-03 19:38 ` [PATCH 05/42] remoteproc: keystone: " Mukesh Ojha
2026-07-03 19:38 ` [PATCH 06/42] media: synopsys: hdmirx: " Mukesh Ojha
2026-07-06 15:00 ` Dmitry Osipenko
2026-07-03 19:38 ` [PATCH 07/42] remoteproc: omap: " Mukesh Ojha
2026-07-03 19:38 ` [PATCH 08/42] drm: logicvc: " Mukesh Ojha
2026-07-03 19:38 ` [PATCH 09/42] drm: hdlcd: " Mukesh Ojha
2026-07-03 19:38 ` [PATCH 10/42] drm: pl111: " Mukesh Ojha
2026-07-03 19:38 ` [PATCH 11/42] remoteproc: mtk_scp: " Mukesh Ojha
2026-07-03 19:38 ` [PATCH 12/42] media: aspeed: " Mukesh Ojha
2026-07-03 19:38 ` [PATCH 13/42] media: nuvoton: npcm-video: " Mukesh Ojha
2026-07-03 19:38 ` [PATCH 14/42] memory: tegra210-emc: Use devm_of_reserved_mem_device_init_by_name() Mukesh Ojha
2026-07-03 19:38 ` [PATCH 15/42] drm: komeda: Use devm_of_reserved_mem_device_init() Mukesh Ojha
2026-07-03 19:38 ` [PATCH 16/42] drm: malidp: " Mukesh Ojha
2026-07-03 19:38 ` [PATCH 17/42] drm: ingenic: " Mukesh Ojha
2026-07-03 19:38 ` [PATCH 18/42] drm: kmb: " Mukesh Ojha
2026-07-03 19:38 ` [PATCH 19/42] drm: sun4i: " Mukesh Ojha
2026-07-03 19:38 ` [PATCH 20/42] drm: xlnx: zynqmp_dpsub: " Mukesh Ojha
2026-07-07 9:13 ` Pandey, Radhey Shyam
2026-07-03 19:38 ` [PATCH 21/42] media: arm: mali-c55: " Mukesh Ojha
2026-07-03 19:38 ` [PATCH 22/42] media: mediatek: vpu: " Mukesh Ojha
2026-07-03 19:38 ` [PATCH 23/42] mmc: sdhci-of-bst: Use devm_of_reserved_mem_device_init_by_idx() Mukesh Ojha
2026-07-03 19:38 ` [PATCH 24/42] remoteproc: ti_k3: Use devm_of_reserved_mem_device_init() Mukesh Ojha
2026-07-03 19:38 ` [PATCH 25/42] ASoC: mediatek: mt8192: " Mukesh Ojha
2026-07-06 12:16 ` Mark Brown
2026-07-03 19:38 ` [PATCH 26/42] ASoC: mediatek: mt8196: " Mukesh Ojha
2026-07-06 12:16 ` Mark Brown
2026-07-03 19:38 ` [PATCH 27/42] ASoC: mediatek: mt8183: " Mukesh Ojha
2026-07-06 12:17 ` Mark Brown
2026-07-03 19:38 ` [PATCH 28/42] ASoC: mediatek: mt8189: " Mukesh Ojha
2026-07-06 12:18 ` Mark Brown
2026-07-03 19:38 ` [PATCH 29/42] ASoC: SOF: imx: Use devm_of_reserved_mem_device_init_by_name() Mukesh Ojha
2026-07-06 12:19 ` Mark Brown
2026-07-03 19:38 ` [PATCH 30/42] staging: media: cedrus: Use devm_of_reserved_mem_device_init() Mukesh Ojha
2026-07-03 19:38 ` [PATCH 31/42] ASoC: cix-ipbloq: " Mukesh Ojha
2026-07-06 12:20 ` Mark Brown
2026-07-07 1:34 ` Gary Yang
2026-07-03 19:38 ` [PATCH 32/42] drm: aspeed: " Mukesh Ojha
2026-07-05 19:40 ` [PATCH 33/42] drm: arcpgu: " Mukesh Ojha
2026-07-05 19:40 ` [PATCH 34/42] ASoC: mediatek: mt8173: " Mukesh Ojha
2026-07-05 19:40 ` [PATCH 35/42] ASoC: mediatek: mt8186: " Mukesh Ojha
2026-07-05 19:40 ` [PATCH 36/42] ASoC: mediatek: mt8188: " Mukesh Ojha
2026-07-05 19:40 ` [PATCH 37/42] ASoC: mediatek: mt8195: " Mukesh Ojha
2026-07-05 19:40 ` [PATCH 38/42] ASoC: SOF: mediatek: mt8186: " Mukesh Ojha
2026-07-05 19:40 ` [PATCH 39/42] ASoC: SOF: mediatek: mt8195: " Mukesh Ojha
2026-07-05 19:40 ` [PATCH 40/42] misc: fastrpc: " Mukesh Ojha
2026-07-06 4:55 ` Ekansh Gupta
2026-07-05 19:40 ` [PATCH 41/42] ASoC: fsl: imx-rpmsg: Use devm_of_reserved_mem_device_init_by_idx() Mukesh Ojha
2026-07-05 19:40 ` [PATCH 42/42] ASoC: sprd: Use devm_of_reserved_mem_device_init() Mukesh Ojha
2026-07-06 12:14 ` [PATCH 00/42] of: reserved_mem: Introduce devres helpers and convert drivers Mark Brown
2026-07-06 13:16 ` Mukesh Ojha
2026-07-07 11:39 ` Liviu Dudau
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=20260703193855.110619-2-mukesh.ojha@oss.qualcomm.com \
--to=mukesh.ojha@oss.qualcomm.com \
--cc=Frank.Li@nxp.com \
--cc=Vijendar.Mukunda@amd.com \
--cc=Xiubo.Lee@gmail.com \
--cc=abrodkin@synopsys.com \
--cc=adrian.hunter@intel.com \
--cc=airlied@gmail.com \
--cc=andersson@kernel.org \
--cc=andrew-ct.chen@mediatek.com \
--cc=andrew@codeconstruct.com.au \
--cc=angelogioacchino.delregno@collabora.com \
--cc=anitha.chrisanthus@intel.com \
--cc=arnd@arndb.de \
--cc=baolin.wang@linux.alibaba.com \
--cc=broonie@kernel.org \
--cc=bst-upstream@bstai.top \
--cc=cix-kernel-upstream@cixtech.com \
--cc=dan.scally@ideasonboard.com \
--cc=daniel.baluta@nxp.com \
--cc=devicetree@vger.kernel.org \
--cc=dmitry.osipenko@collabora.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=eajames@linux.ibm.com \
--cc=ekansh.gupta@oss.qualcomm.com \
--cc=festevam@gmail.com \
--cc=fugang.duan@cixtech.com \
--cc=gordon.ge@bst.ai \
--cc=gregkh@linuxfoundation.org \
--cc=houlong.wei@mediatek.com \
--cc=imx@lists.linux.dev \
--cc=jacopo.mondi@ideasonboard.com \
--cc=jernej.skrabec@gmail.com \
--cc=joel@jms.id.au \
--cc=jonathanh@nvidia.com \
--cc=kai.vehmanen@linux.intel.com \
--cc=kernel@collabora.com \
--cc=kernel@pengutronix.de \
--cc=kflin@nuvoton.com \
--cc=konrad.dybcio@oss.qualcomm.com \
--cc=konradybcio@kernel.org \
--cc=krzk@kernel.org \
--cc=kwliu@nuvoton.com \
--cc=laurent.pinchart@ideasonboard.com \
--cc=lgirdwood@gmail.com \
--cc=linusw@kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-arm-msm@vger.kernel.org \
--cc=linux-aspeed@lists.ozlabs.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=linux-mediatek@lists.infradead.org \
--cc=linux-mips@vger.kernel.org \
--cc=linux-mmc@vger.kernel.org \
--cc=linux-remoteproc@vger.kernel.org \
--cc=linux-sound@vger.kernel.org \
--cc=linux-staging@lists.linux.dev \
--cc=linux-sunxi@lists.linux.dev \
--cc=linux-tegra@vger.kernel.org \
--cc=linuxppc-dev@lists.ozlabs.org \
--cc=liviu.dudau@arm.com \
--cc=maarten.lankhorst@linux.intel.com \
--cc=mathieu.poirier@linaro.org \
--cc=matthias.bgg@gmail.com \
--cc=mchehab@kernel.org \
--cc=michal.simek@amd.com \
--cc=minghsiu.tsai@mediatek.com \
--cc=mripard@kernel.org \
--cc=nicoleotsuka@gmail.com \
--cc=openbmc@lists.ozlabs.org \
--cc=orsonzhai@gmail.com \
--cc=paul@crapouillou.net \
--cc=paulk@sys-base.io \
--cc=perex@perex.cz \
--cc=peter.chen@cixtech.com \
--cc=peter.ujfalusi@linux.intel.com \
--cc=pierre-louis.bossart@linux.dev \
--cc=robh@kernel.org \
--cc=s.hauer@pengutronix.de \
--cc=samuel@sholland.org \
--cc=saravanak@kernel.org \
--cc=shengjiu.wang@gmail.com \
--cc=simona@ffwll.ch \
--cc=sound-open-firmware@alsa-project.org \
--cc=srini@kernel.org \
--cc=thierry.reding@kernel.org \
--cc=tiffany.lin@mediatek.com \
--cc=tiwai@suse.com \
--cc=tomi.valkeinen@ideasonboard.com \
--cc=tzimmermann@suse.de \
--cc=ulfh@kernel.org \
--cc=wens@kernel.org \
--cc=yunfei.dong@mediatek.com \
--cc=yung-chuan.liao@linux.intel.com \
--cc=zhang.lyra@gmail.com \
/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