* [PATCH] soc: fsl: dpio: Use common error handling code in two functions
@ 2026-06-11 10:02 Markus Elfring
2026-07-04 9:19 ` Christophe Leroy (CS GROUP)
0 siblings, 1 reply; 6+ messages in thread
From: Markus Elfring @ 2026-06-11 10:02 UTC (permalink / raw)
To: linux-arm-kernel, linuxppc-dev, Christophe Leroy, Roy Pledge
Cc: LKML, kernel-janitors
From: Markus Elfring <elfring@users.sourceforge.net>
Date: Thu, 11 Jun 2026 11:56:18 +0200
Use additional labels so that a bit of exception handling can be better
reused at the end of two function implementations.
This issue was detected by using the Coccinelle software.
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
drivers/soc/fsl/dpio/dpio-service.c | 30 ++++++++++++++---------------
1 file changed, 15 insertions(+), 15 deletions(-)
diff --git a/drivers/soc/fsl/dpio/dpio-service.c b/drivers/soc/fsl/dpio/dpio-service.c
index 317ca50b0c2b..025d9fb5660d 100644
--- a/drivers/soc/fsl/dpio/dpio-service.c
+++ b/drivers/soc/fsl/dpio/dpio-service.c
@@ -140,10 +140,8 @@ struct dpaa2_io *dpaa2_io_create(const struct dpaa2_io_desc *desc,
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;
- }
+ if (desc->cpu != DPAA2_IO_ANY_CPU && desc->cpu >= num_possible_cpus())
+ goto free_obj;
obj->dpio_desc = *desc;
obj->swp_desc.cena_bar = obj->dpio_desc.regs_cena;
@@ -158,11 +156,8 @@ struct dpaa2_io *dpaa2_io_create(const struct dpaa2_io_desc *desc,
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);
- return NULL;
- }
+ if (!obj->swp)
+ goto free_obj;
INIT_LIST_HEAD(&obj->node);
spin_lock_init(&obj->lock_mgmt_cmd);
@@ -192,6 +187,10 @@ struct dpaa2_io *dpaa2_io_create(const struct dpaa2_io_desc *desc,
obj->frames = 0;
return obj;
+
+free_obj:
+ kfree(obj);
+ return NULL;
}
/**
@@ -665,10 +664,8 @@ struct dpaa2_io_store *dpaa2_io_store_create(unsigned int max_frames,
ret->max = max_frames;
size = max_frames * sizeof(struct dpaa2_dq) + 64;
ret->alloced_addr = kzalloc(size, GFP_KERNEL);
- if (!ret->alloced_addr) {
- kfree(ret);
- return NULL;
- }
+ if (!ret->alloced_addr)
+ goto free_ret;
ret->vaddr = PTR_ALIGN(ret->alloced_addr, 64);
ret->paddr = dma_map_single(dev, ret->vaddr,
@@ -676,14 +673,17 @@ struct dpaa2_io_store *dpaa2_io_store_create(unsigned int max_frames,
DMA_FROM_DEVICE);
if (dma_mapping_error(dev, ret->paddr)) {
kfree(ret->alloced_addr);
- kfree(ret);
- return NULL;
+ goto free_ret;
}
ret->idx = 0;
ret->dev = dev;
return ret;
+
+free_ret:
+ kfree(ret);
+ return NULL;
}
EXPORT_SYMBOL_GPL(dpaa2_io_store_create);
--
2.54.0
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH] soc: fsl: dpio: Use common error handling code in two functions
2026-06-11 10:02 [PATCH] soc: fsl: dpio: Use common error handling code in two functions Markus Elfring
@ 2026-07-04 9:19 ` Christophe Leroy (CS GROUP)
2026-07-04 10:11 ` Markus Elfring
2026-07-06 10:36 ` [PATCH v2 0/2] soc: fsl: dpio: Use scope-based resource management " Markus Elfring
0 siblings, 2 replies; 6+ messages in thread
From: Christophe Leroy (CS GROUP) @ 2026-07-04 9:19 UTC (permalink / raw)
To: Markus Elfring, linux-arm-kernel, linuxppc-dev, Roy Pledge
Cc: LKML, kernel-janitors
Le 11/06/2026 à 12:02, Markus Elfring a écrit :
> From: Markus Elfring <elfring@users.sourceforge.net>
> Date: Thu, 11 Jun 2026 11:56:18 +0200
>
> Use additional labels so that a bit of exception handling can be better
> reused at the end of two function implementations.
>
> This issue was detected by using the Coccinelle software.
I think it would be better to declare obj and ret as automatic free instead:
struct dpaa2_io __free(kfree) *obj = kmalloc_obj(*obj);
>
> Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
> ---
> drivers/soc/fsl/dpio/dpio-service.c | 30 ++++++++++++++---------------
> 1 file changed, 15 insertions(+), 15 deletions(-)
>
> diff --git a/drivers/soc/fsl/dpio/dpio-service.c b/drivers/soc/fsl/dpio/dpio-service.c
> index 317ca50b0c2b..025d9fb5660d 100644
> --- a/drivers/soc/fsl/dpio/dpio-service.c
> +++ b/drivers/soc/fsl/dpio/dpio-service.c
> @@ -140,10 +140,8 @@ struct dpaa2_io *dpaa2_io_create(const struct dpaa2_io_desc *desc,
> 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;
> - }
> + if (desc->cpu != DPAA2_IO_ANY_CPU && desc->cpu >= num_possible_cpus())
> + goto free_obj;
>
> obj->dpio_desc = *desc;
> obj->swp_desc.cena_bar = obj->dpio_desc.regs_cena;
> @@ -158,11 +156,8 @@ struct dpaa2_io *dpaa2_io_create(const struct dpaa2_io_desc *desc,
> 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);
> - return NULL;
> - }
> + if (!obj->swp)
> + goto free_obj;
>
> INIT_LIST_HEAD(&obj->node);
> spin_lock_init(&obj->lock_mgmt_cmd);
> @@ -192,6 +187,10 @@ struct dpaa2_io *dpaa2_io_create(const struct dpaa2_io_desc *desc,
> obj->frames = 0;
>
> return obj;
> +
> +free_obj:
> + kfree(obj);
> + return NULL;
> }
>
> /**
> @@ -665,10 +664,8 @@ struct dpaa2_io_store *dpaa2_io_store_create(unsigned int max_frames,
> ret->max = max_frames;
> size = max_frames * sizeof(struct dpaa2_dq) + 64;
> ret->alloced_addr = kzalloc(size, GFP_KERNEL);
> - if (!ret->alloced_addr) {
> - kfree(ret);
> - return NULL;
> - }
> + if (!ret->alloced_addr)
> + goto free_ret;
>
> ret->vaddr = PTR_ALIGN(ret->alloced_addr, 64);
> ret->paddr = dma_map_single(dev, ret->vaddr,
> @@ -676,14 +673,17 @@ struct dpaa2_io_store *dpaa2_io_store_create(unsigned int max_frames,
> DMA_FROM_DEVICE);
> if (dma_mapping_error(dev, ret->paddr)) {
> kfree(ret->alloced_addr);
> - kfree(ret);
> - return NULL;
> + goto free_ret;
> }
>
> ret->idx = 0;
> ret->dev = dev;
>
> return ret;
> +
> +free_ret:
> + kfree(ret);
> + return NULL;
> }
> EXPORT_SYMBOL_GPL(dpaa2_io_store_create);
>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] soc: fsl: dpio: Use common error handling code in two functions
2026-07-04 9:19 ` Christophe Leroy (CS GROUP)
@ 2026-07-04 10:11 ` Markus Elfring
2026-07-06 10:36 ` [PATCH v2 0/2] soc: fsl: dpio: Use scope-based resource management " Markus Elfring
1 sibling, 0 replies; 6+ messages in thread
From: Markus Elfring @ 2026-07-04 10:11 UTC (permalink / raw)
To: Christophe Leroy (CS GROUP), linux-arm-kernel, linuxppc-dev,
Roy Pledge
Cc: LKML, kernel-janitors
>> Use additional labels so that a bit of exception handling can be better
>> reused at the end of two function implementations.
>>
>> This issue was detected by using the Coccinelle software.
>
> I think it would be better to declare obj and ret as automatic free instead:
Please reconsider such information in more detail.
> struct dpaa2_io __free(kfree) *obj = kmalloc_obj(*obj);
The application of scope-base resource management can eventually be increased further.
Regards,
Markus
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH v2 0/2] soc: fsl: dpio: Use scope-based resource management in two functions
2026-07-04 9:19 ` Christophe Leroy (CS GROUP)
2026-07-04 10:11 ` Markus Elfring
@ 2026-07-06 10:36 ` Markus Elfring
2026-07-06 10:38 ` [PATCH v2 1/2] soc: fsl: dpio: Use scope-based resource management in dpaa2_io_store_create() Markus Elfring
2026-07-06 10:40 ` [PATCH v2 2/2] soc: fsl: dpio: Use scope-based resource management in dpaa2_io_create() Markus Elfring
1 sibling, 2 replies; 6+ messages in thread
From: Markus Elfring @ 2026-07-06 10:36 UTC (permalink / raw)
To: linux-arm-kernel, linuxppc-dev, Christophe Leroy, Roy Pledge
Cc: LKML, kernel-janitors
From: Markus Elfring <elfring@users.sourceforge.net>
Date: Mon, 6 Jul 2026 11:42:10 +0200
Some adjustment opportunities were picked up.
Markus Elfring (2):
Use scope-based resource management in dpaa2_io_store_create()
Use scope-based resource management in dpaa2_io_create()
v2:
Christophe Leroy requested to apply the attribute “__free(kfree)”.
drivers/soc/fsl/dpio/dpio-service.c | 37 ++++++++++-------------------
1 file changed, 12 insertions(+), 25 deletions(-)
--
2.54.0
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH v2 1/2] soc: fsl: dpio: Use scope-based resource management in dpaa2_io_store_create()
2026-07-06 10:36 ` [PATCH v2 0/2] soc: fsl: dpio: Use scope-based resource management " Markus Elfring
@ 2026-07-06 10:38 ` Markus Elfring
2026-07-06 10:40 ` [PATCH v2 2/2] soc: fsl: dpio: Use scope-based resource management in dpaa2_io_create() Markus Elfring
1 sibling, 0 replies; 6+ messages in thread
From: Markus Elfring @ 2026-07-06 10:38 UTC (permalink / raw)
To: linux-arm-kernel, linuxppc-dev, Christophe Leroy, Roy Pledge
Cc: LKML, kernel-janitors
From: Markus Elfring <elfring@users.sourceforge.net>
Date: Mon, 6 Jul 2026 10:34:43 +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)”.
* Reduce the scope for the local variable “ret”.
* Omit two kfree() calls accordingly.
* Omit the local variable “size” (for another memory allocation).
* Use the macro call “return_ptr(ret)” at the end.
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
drivers/soc/fsl/dpio/dpio-service.c | 15 ++++-----------
1 file changed, 4 insertions(+), 11 deletions(-)
diff --git a/drivers/soc/fsl/dpio/dpio-service.c b/drivers/soc/fsl/dpio/dpio-service.c
index 317ca50b0c2b..b252c3c7fa65 100644
--- a/drivers/soc/fsl/dpio/dpio-service.c
+++ b/drivers/soc/fsl/dpio/dpio-service.c
@@ -652,23 +652,17 @@ EXPORT_SYMBOL_GPL(dpaa2_io_service_acquire);
struct dpaa2_io_store *dpaa2_io_store_create(unsigned int max_frames,
struct device *dev)
{
- struct dpaa2_io_store *ret;
- size_t size;
-
if (!max_frames || (max_frames > 32))
return NULL;
- ret = kmalloc_obj(*ret);
+ struct dpaa2_io_store *ret __free(kfree) = kmalloc_obj(*ret);
if (!ret)
return NULL;
ret->max = max_frames;
- size = max_frames * sizeof(struct dpaa2_dq) + 64;
- ret->alloced_addr = kzalloc(size, GFP_KERNEL);
- if (!ret->alloced_addr) {
- kfree(ret);
+ ret->alloced_addr = kzalloc(max_frames * sizeof(struct dpaa2_dq) + 64, GFP_KERNEL);
+ if (!ret->alloced_addr)
return NULL;
- }
ret->vaddr = PTR_ALIGN(ret->alloced_addr, 64);
ret->paddr = dma_map_single(dev, ret->vaddr,
@@ -676,14 +670,13 @@ struct dpaa2_io_store *dpaa2_io_store_create(unsigned int max_frames,
DMA_FROM_DEVICE);
if (dma_mapping_error(dev, ret->paddr)) {
kfree(ret->alloced_addr);
- kfree(ret);
return NULL;
}
ret->idx = 0;
ret->dev = dev;
- return ret;
+ return_ptr(ret);
}
EXPORT_SYMBOL_GPL(dpaa2_io_store_create);
--
2.54.0
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH v2 2/2] soc: fsl: dpio: Use scope-based resource management in dpaa2_io_create()
2026-07-06 10:36 ` [PATCH v2 0/2] soc: fsl: dpio: Use scope-based resource management " Markus Elfring
2026-07-06 10:38 ` [PATCH v2 1/2] soc: fsl: dpio: Use scope-based resource management in dpaa2_io_store_create() Markus Elfring
@ 2026-07-06 10:40 ` Markus Elfring
1 sibling, 0 replies; 6+ messages in thread
From: Markus Elfring @ 2026-07-06 10:40 UTC (permalink / raw)
To: linux-arm-kernel, linuxppc-dev, Christophe Leroy, Roy Pledge
Cc: LKML, kernel-janitors
From: Markus Elfring <elfring@users.sourceforge.net>
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 <elfring@users.sourceforge.net>
---
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
^ permalink raw reply related [flat|nested] 6+ messages in thread
end of thread, other threads:[~2026-07-06 10:40 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-06-11 10:02 [PATCH] soc: fsl: dpio: Use common error handling code in two functions Markus Elfring
2026-07-04 9:19 ` Christophe Leroy (CS GROUP)
2026-07-04 10:11 ` Markus Elfring
2026-07-06 10:36 ` [PATCH v2 0/2] soc: fsl: dpio: Use scope-based resource management " Markus Elfring
2026-07-06 10:38 ` [PATCH v2 1/2] soc: fsl: dpio: Use scope-based resource management in dpaa2_io_store_create() Markus Elfring
2026-07-06 10:40 ` [PATCH v2 2/2] soc: fsl: dpio: Use scope-based resource management in dpaa2_io_create() Markus Elfring
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox