* [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; 3+ 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] 3+ 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
0 siblings, 1 reply; 3+ 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] 3+ 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
0 siblings, 0 replies; 3+ 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] 3+ messages in thread
end of thread, other threads:[~2026-07-04 10:11 UTC | newest]
Thread overview: 3+ 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
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox