From: Markus Elfring <Markus.Elfring@web.de>
To: linuxppc-dev@lists.ozlabs.org,
linux-arm-kernel@lists.infradead.org,
Christophe Leroy <chleroy@kernel.org>,
Dan Carpenter <error27@gmail.com>,
Ioana Ciornei <ioana.ciornei@nxp.com>,
Roy Pledge <Roy.Pledge@nxp.com>
Cc: LKML <linux-kernel@vger.kernel.org>,
kernel-janitors@vger.kernel.org,
Peter Zijlstra <peterz@infradead.org>
Subject: [PATCH v3 2/2] soc: fsl: dpio: Use scope-based resource management in dpaa2_io_create()
Date: Wed, 29 Jul 2026 13:44:06 +0200 [thread overview]
Message-ID: <d03db8ee-0b75-43da-9e0a-056cd7c28967@web.de> (raw)
In-Reply-To: <709fefd1-821a-4cd1-8598-b1179a95ce52@web.de>
From: Markus Elfring <elfring@users.sourceforge.net>
Date: Wed, 29 Jul 2026 12:46:56 +0200
Scope-based resource management became supported for some
programming interfaces by contributions of Peter Zijlstra on 2023-05-26.
See also the commit 54da6a0924311c7cf5015533991e44fb8eb12773 ("locking:
Introduce __cleanup() based infrastructure").
* Move some source code from the implementation of the function
“dpaa2_io_create” to a new function.
* Use the attribute “__free(kfree)” for the local variable “obj”.
* Omit two kfree() calls accordingly.
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
drivers/soc/fsl/dpio/dpio-service.c | 46 +++++++++++++++--------------
1 file changed, 24 insertions(+), 22 deletions(-)
diff --git a/drivers/soc/fsl/dpio/dpio-service.c b/drivers/soc/fsl/dpio/dpio-service.c
index b621755d8988..4ff99928e9c6 100644
--- a/drivers/soc/fsl/dpio/dpio-service.c
+++ b/drivers/soc/fsl/dpio/dpio-service.c
@@ -121,31 +121,15 @@ static void dpaa2_io_dim_work(struct work_struct *w)
dim->state = DIM_START_MEASURE;
}
-/**
- * dpaa2_io_create() - create a dpaa2_io object.
- * @desc: the dpaa2_io descriptor
- * @dev: the actual DPIO device
- *
- * Activates a "struct dpaa2_io" corresponding to the given config of an actual
- * DPIO object.
- *
- * Return a valid dpaa2_io object for success, or NULL for failure.
- */
-struct dpaa2_io *dpaa2_io_create(const struct dpaa2_io_desc *desc,
- struct device *dev)
+static inline
+struct dpaa2_io *dpaa2_io_create_impl(const struct dpaa2_io_desc *desc, struct device *dev)
{
- struct dpaa2_io *obj = kmalloc_obj(*obj);
u32 qman_256_cycles_per_ns;
+ struct dpaa2_io *obj __free(kfree) = kmalloc_obj(*obj);
if (!obj)
return NULL;
- /* check if CPU is out of range (-1 means any cpu) */
- if (desc->cpu != DPAA2_IO_ANY_CPU && desc->cpu >= num_possible_cpus()) {
- kfree(obj);
- return NULL;
- }
-
obj->dpio_desc = *desc;
obj->swp_desc.cena_bar = obj->dpio_desc.regs_cena;
obj->swp_desc.cinh_bar = obj->dpio_desc.regs_cinh;
@@ -160,10 +144,8 @@ struct dpaa2_io *dpaa2_io_create(const struct dpaa2_io_desc *desc,
obj->swp_desc.qman_256_cycles_per_ns = qman_256_cycles_per_ns;
obj->swp = qbman_swp_init(&obj->swp_desc);
- if (!obj->swp) {
- kfree(obj);
+ if (!obj->swp)
return NULL;
- }
INIT_LIST_HEAD(&obj->node);
spin_lock_init(&obj->lock_mgmt_cmd);
@@ -195,6 +177,26 @@ struct dpaa2_io *dpaa2_io_create(const struct dpaa2_io_desc *desc,
return obj;
}
+/**
+ * dpaa2_io_create() - create a dpaa2_io object.
+ * @desc: the dpaa2_io descriptor
+ * @dev: the actual DPIO device
+ *
+ * Activates a "struct dpaa2_io" corresponding to the given config of an actual
+ * DPIO object.
+ *
+ * Return a valid dpaa2_io object for success, or NULL for failure.
+ */
+struct dpaa2_io *dpaa2_io_create(const struct dpaa2_io_desc *desc,
+ struct device *dev)
+{
+ /* check if CPU is out of range (-1 means any cpu) */
+ if (desc->cpu != DPAA2_IO_ANY_CPU && desc->cpu >= num_possible_cpus())
+ return NULL;
+
+ return dpaa2_io_create_impl(desc, dev);
+}
+
/**
* dpaa2_io_down() - release the dpaa2_io object.
* @d: the dpaa2_io object to be released.
--
2.55.0
prev parent reply other threads:[~2026-07-29 11:44 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-29 11:36 [PATCH v3 0/2] soc: fsl: dpio: Use scope-based resource management in two functions Markus Elfring
2026-07-29 11:42 ` [PATCH v3 1/2] soc: fsl: dpio: Use scope-based resource management in dpaa2_io_store_create() Markus Elfring
2026-07-29 11:44 ` Markus Elfring [this message]
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=d03db8ee-0b75-43da-9e0a-056cd7c28967@web.de \
--to=markus.elfring@web.de \
--cc=Roy.Pledge@nxp.com \
--cc=chleroy@kernel.org \
--cc=error27@gmail.com \
--cc=ioana.ciornei@nxp.com \
--cc=kernel-janitors@vger.kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linuxppc-dev@lists.ozlabs.org \
--cc=peterz@infradead.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