[PATCH v4 2/2] soc: fsl: dpio: Use scope-based resource management in dpaa2_io_create()
From: Markus Elfring <hidden>
Date: 2026-09-24 07:19:54
Also in:
kernel-janitors, linuxppc-dev, lkml
Subsystem:
freescale soc drivers, the rest · Maintainers:
Christophe Leroy, Linus Torvalds
From: Markus Elfring <redacted>
Date: Thu, 24 Sep 2026 08:42:19 +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.
* Replace a return statement by the macro call “return_ptr(obj)”.
Signed-off-by: Markus Elfring <redacted>
---
drivers/soc/fsl/dpio/dpio-service.c | 48 +++++++++++++++--------------
1 file changed, 25 insertions(+), 23 deletions(-)
diff --git a/drivers/soc/fsl/dpio/dpio-service.c b/drivers/soc/fsl/dpio/dpio-service.c
index cb870aae30b4..8085c42c74ce 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);
@@ -192,7 +174,27 @@ struct dpaa2_io *dpaa2_io_create(const struct dpaa2_io_desc *desc, obj->bytes = 0; obj->frames = 0; - return obj; + return_ptr(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); } /**
--
2.55.0