From: Markus Elfring <[email protected]>
Date: Mon, 6 Jul 2026 11:18:39 +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").

* Thus use the attribute “__free(kfree)”.

* Omit two kfree() calls accordingly.

* Reduce the scopes for the local variables “obj”
  and “qman_256_cycles_per_ns”.

* Use the macro call “return_ptr(obj)” at the end.

Signed-off-by: Markus Elfring <[email protected]>
---
 drivers/soc/fsl/dpio/dpio-service.c | 22 ++++++++--------------
 1 file changed, 8 insertions(+), 14 deletions(-)

diff --git a/drivers/soc/fsl/dpio/dpio-service.c 
b/drivers/soc/fsl/dpio/dpio-service.c
index b252c3c7fa65..80fb11206160 100644
--- a/drivers/soc/fsl/dpio/dpio-service.c
+++ b/drivers/soc/fsl/dpio/dpio-service.c
@@ -133,17 +133,14 @@ static void dpaa2_io_dim_work(struct work_struct *w)
 struct dpaa2_io *dpaa2_io_create(const struct dpaa2_io_desc *desc,
                                 struct device *dev)
 {
-       struct dpaa2_io *obj = kmalloc_obj(*obj);
-       u32 qman_256_cycles_per_ns;
-
-       if (!obj)
+       /* 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;
 
-       /* 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);
+       struct dpaa2_io *obj __free(kfree) = kmalloc_obj(*obj);
+
+       if (!obj)
                return NULL;
-       }
 
        obj->dpio_desc = *desc;
        obj->swp_desc.cena_bar = obj->dpio_desc.regs_cena;
@@ -155,14 +152,11 @@ struct dpaa2_io *dpaa2_io_create(const struct 
dpaa2_io_desc *desc,
         * the interrupt timeout period register needs to be specified in QBMAN
         * clock cycles in increments of 256.
         */
-       qman_256_cycles_per_ns = 256000 / (obj->swp_desc.qman_clk / 1000000);
+       u32 qman_256_cycles_per_ns = 256000 / (obj->swp_desc.qman_clk / 
1000000);
        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);
@@ -191,7 +185,7 @@ struct dpaa2_io *dpaa2_io_create(const struct dpaa2_io_desc 
*desc,
        obj->bytes = 0;
        obj->frames = 0;
 
-       return obj;
+       return_ptr(obj);
 }
 
 /**
-- 
2.54.0


Reply via email to