The Linux Kernel Mailing List
 help / color / mirror / Atom feed
* [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; 16+ 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] 16+ 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; 16+ 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] 16+ 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; 16+ 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] 16+ 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
                       ` (2 more replies)
  1 sibling, 3 replies; 16+ 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] 16+ 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-27 11:31       ` Dan Carpenter
  2026-07-27 12:08       ` Ioana Ciornei
  2026-07-06 10:40     ` [PATCH v2 2/2] soc: fsl: dpio: Use scope-based resource management in dpaa2_io_create() Markus Elfring
  2026-07-27  9:57     ` [PATCH v2 0/2] soc: fsl: dpio: Use scope-based resource management in two functions Christophe Leroy (CS GROUP)
  2 siblings, 2 replies; 16+ 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] 16+ 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
  2026-07-27 11:32       ` Dan Carpenter
  2026-07-27 12:09       ` [PATCH v2 " Ioana Ciornei
  2026-07-27  9:57     ` [PATCH v2 0/2] soc: fsl: dpio: Use scope-based resource management in two functions Christophe Leroy (CS GROUP)
  2 siblings, 2 replies; 16+ 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] 16+ messages in thread

* Re: [PATCH v2 0/2] soc: fsl: dpio: Use scope-based resource management in two functions
  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
@ 2026-07-27  9:57     ` Christophe Leroy (CS GROUP)
  2 siblings, 0 replies; 16+ messages in thread
From: Christophe Leroy (CS GROUP) @ 2026-07-27  9:57 UTC (permalink / raw)
  To: Markus Elfring, Ioana Ciornei
  Cc: LKML, linuxppc-dev, Roy Pledge, kernel-janitors, linux-arm-kernel

Hi Ioana,

Le 06/07/2026 à 12:36, Markus Elfring a écrit :
> 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()
> 

As the (new) maintainer of drivers/soc/fsl/dpio, could you have a look 
at this series ?

Thanks
Christophe

> 
> 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(-)
> 


^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH v2 1/2] soc: fsl: dpio: Use scope-based resource management in dpaa2_io_store_create()
  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-27 11:31       ` Dan Carpenter
  2026-07-27 12:08       ` Ioana Ciornei
  1 sibling, 0 replies; 16+ messages in thread
From: Dan Carpenter @ 2026-07-27 11:31 UTC (permalink / raw)
  To: Markus Elfring
  Cc: linux-arm-kernel, linuxppc-dev, Christophe Leroy, Roy Pledge,
	LKML, kernel-janitors

On Mon, Jul 06, 2026 at 12:38:08PM +0200, Markus Elfring wrote:
> 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).

Why?  This seems unrelated...

> 
> * 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);

Missing #include <linux/cleanup.h>

>  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;

Why convert the ret allocation but not the ret->alloced_addr allocation?

regards,
dan carpenter

> -	}
>  
>  	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	[flat|nested] 16+ messages in thread

* Re: [PATCH v2 2/2] soc: fsl: dpio: Use scope-based resource management in dpaa2_io_create()
  2026-07-06 10:40     ` [PATCH v2 2/2] soc: fsl: dpio: Use scope-based resource management in dpaa2_io_create() Markus Elfring
@ 2026-07-27 11:32       ` Dan Carpenter
  2026-07-27 12:14         ` [v2 " Markus Elfring
  2026-07-27 12:09       ` [PATCH v2 " Ioana Ciornei
  1 sibling, 1 reply; 16+ messages in thread
From: Dan Carpenter @ 2026-07-27 11:32 UTC (permalink / raw)
  To: Markus Elfring
  Cc: linux-arm-kernel, linuxppc-dev, Christophe Leroy, Roy Pledge,
	LKML, kernel-janitors

On Mon, Jul 06, 2026 at 12:40:09PM +0200, Markus Elfring wrote:
> 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”.

Why?  No one does this except bcachefs and that was removed.

regards,
dan carpenter



^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH v2 1/2] soc: fsl: dpio: Use scope-based resource management in dpaa2_io_store_create()
  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-27 11:31       ` Dan Carpenter
@ 2026-07-27 12:08       ` Ioana Ciornei
  2026-07-27 12:24         ` [v2 " Markus Elfring
  1 sibling, 1 reply; 16+ messages in thread
From: Ioana Ciornei @ 2026-07-27 12:08 UTC (permalink / raw)
  To: Markus Elfring
  Cc: linux-arm-kernel, linuxppc-dev, Christophe Leroy, Roy Pledge,
	LKML, kernel-janitors

On Mon, Jul 06, 2026 at 12:38:08PM +0200, Markus Elfring wrote:
> 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”.

Please don't. Let all the variables be defined at the start of each
function.

> 
> * Omit two kfree() calls accordingly.
> 
> * Omit the local variable “size” (for another memory allocation).

Please remove this change, not related to the intention of the patch.

Ioana

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH v2 2/2] soc: fsl: dpio: Use scope-based resource management in dpaa2_io_create()
  2026-07-06 10:40     ` [PATCH v2 2/2] soc: fsl: dpio: Use scope-based resource management in dpaa2_io_create() Markus Elfring
  2026-07-27 11:32       ` Dan Carpenter
@ 2026-07-27 12:09       ` Ioana Ciornei
  2026-07-27 13:14         ` [v2 " Markus Elfring
  1 sibling, 1 reply; 16+ messages in thread
From: Ioana Ciornei @ 2026-07-27 12:09 UTC (permalink / raw)
  To: Markus Elfring
  Cc: linux-arm-kernel, linuxppc-dev, Christophe Leroy, Roy Pledge,
	LKML, kernel-janitors

On Mon, Jul 06, 2026 at 12:40:09PM +0200, Markus Elfring wrote:
> 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”.

Remove these changes. All variables should be defined at the start of
the function, especially since there is no strong reason not to.

Ioana

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [v2 2/2] soc: fsl: dpio: Use scope-based resource management in dpaa2_io_create()
  2026-07-27 11:32       ` Dan Carpenter
@ 2026-07-27 12:14         ` Markus Elfring
  0 siblings, 0 replies; 16+ messages in thread
From: Markus Elfring @ 2026-07-27 12:14 UTC (permalink / raw)
  To: Dan Carpenter, linux-arm-kernel, linuxppc-dev
  Cc: Christophe Leroy, Ioana Ciornei, Roy Pledge, LKML,
	kernel-janitors

>> 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”.
> 
> Why?  No one does this except bcachefs and that was removed.
Have you still got development difficulties with scope reductions for
selected local variables?
https://elixir.bootlin.com/linux/v7.2-rc4/source/include/linux/cleanup.h#L142-L146

Regards,
Markus

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [v2 1/2] soc: fsl: dpio: Use scope-based resource management in dpaa2_io_store_create()
  2026-07-27 12:08       ` Ioana Ciornei
@ 2026-07-27 12:24         ` Markus Elfring
  2026-07-27 12:46           ` Ioana Ciornei
  0 siblings, 1 reply; 16+ messages in thread
From: Markus Elfring @ 2026-07-27 12:24 UTC (permalink / raw)
  To: Ioana Ciornei, linux-arm-kernel, linuxppc-dev
  Cc: Christophe Leroy, Roy Pledge, LKML, kernel-janitors

>> 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”.
> 
> Please don't. Let all the variables be defined at the start of each function.

Do we stumble on another coding style preferences conflict here?
https://elixir.bootlin.com/linux/v7.2-rc4/source/include/linux/cleanup.h#L142-L146


>> * Omit two kfree() calls accordingly.
>>
>> * Omit the local variable “size” (for another memory allocation).
> 
> Please remove this change, not related to the intention of the patch.
What does hinder to perform the required size determination as a direct parameter
for a kzalloc() call?

Regards,
Markus

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [v2 1/2] soc: fsl: dpio: Use scope-based resource management in dpaa2_io_store_create()
  2026-07-27 12:24         ` [v2 " Markus Elfring
@ 2026-07-27 12:46           ` Ioana Ciornei
  2026-07-27 12:52             ` Markus Elfring
  0 siblings, 1 reply; 16+ messages in thread
From: Ioana Ciornei @ 2026-07-27 12:46 UTC (permalink / raw)
  To: Markus Elfring
  Cc: linux-arm-kernel, linuxppc-dev, Christophe Leroy, Roy Pledge,
	LKML, kernel-janitors

On Mon, Jul 27, 2026 at 02:24:55PM +0200, Markus Elfring wrote:
> >> 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”.
> > 
> > Please don't. Let all the variables be defined at the start of each function.
> 
> Do we stumble on another coding style preferences conflict here?

Yes, especially when moving the variable definition is unnecessary.

> https://elixir.bootlin.com/linux/v7.2-rc4/source/include/linux/cleanup.h#L142-L146

The context for the recommendation linked by you is (also from
cleanup.h):

	 * "When multiple variables in the same scope have cleanup attributes,
	 * at exit from the scope their associated cleanup functions are run in
	 * reverse order of definition (last defined, first cleanup)."
	 *
	 * When the unwind order matters it requires that variables be defined
	 * mid-function scope rather than at the top of the file.  Take the
	 * following example and notice the bug highlighted by "!!"::

Which is not the case of these simple functions which only need a kfree.

> 
> 
> >> * Omit two kfree() calls accordingly.
> >>
> >> * Omit the local variable “size” (for another memory allocation).
> > 
> > Please remove this change, not related to the intention of the patch.
> What does hinder to perform the required size determination as a direct parameter
> for a kzalloc() call?

Nothing, but it's a different change. On top of this, it's just churning
the code without an added benefit.

Ioana

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [v2 1/2] soc: fsl: dpio: Use scope-based resource management in dpaa2_io_store_create()
  2026-07-27 12:46           ` Ioana Ciornei
@ 2026-07-27 12:52             ` Markus Elfring
  0 siblings, 0 replies; 16+ messages in thread
From: Markus Elfring @ 2026-07-27 12:52 UTC (permalink / raw)
  To: Ioana Ciornei, linux-arm-kernel, linuxppc-dev
  Cc: Christophe Leroy, Roy Pledge, LKML, kernel-janitors

>>>> * Omit the local variable “size” (for another memory allocation).
>>>
>>> Please remove this change, not related to the intention of the patch.
>> What does hinder to perform the required size determination as a direct parameter
>> for a kzalloc() call?
> 
> Nothing, but it's a different change. On top of this, it's just churning
> the code without an added benefit.
It influences development concerns also according to preferred variable scopes.

Regards,
Markus

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [v2 2/2] soc: fsl: dpio: Use scope-based resource management in dpaa2_io_create()
  2026-07-27 12:09       ` [PATCH v2 " Ioana Ciornei
@ 2026-07-27 13:14         ` Markus Elfring
  0 siblings, 0 replies; 16+ messages in thread
From: Markus Elfring @ 2026-07-27 13:14 UTC (permalink / raw)
  To: Ioana Ciornei, linux-arm-kernel, linuxppc-dev
  Cc: Christophe Leroy, Peter Zijlstra, Roy Pledge, LKML,
	kernel-janitors

>> 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”.
> 
> Remove these changes. All variables should be defined at the start of
> the function, especially since there is no strong reason not to.
Can such a feedback be also interpreted in the way that you have got still difficulties
with complete support of scope-based resource management?

Regards,
Markus

^ permalink raw reply	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2026-07-27 13:15 UTC | newest]

Thread overview: 16+ 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-27 11:31       ` Dan Carpenter
2026-07-27 12:08       ` Ioana Ciornei
2026-07-27 12:24         ` [v2 " Markus Elfring
2026-07-27 12:46           ` Ioana Ciornei
2026-07-27 12:52             ` 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
2026-07-27 11:32       ` Dan Carpenter
2026-07-27 12:14         ` [v2 " Markus Elfring
2026-07-27 12:09       ` [PATCH v2 " Ioana Ciornei
2026-07-27 13:14         ` [v2 " Markus Elfring
2026-07-27  9:57     ` [PATCH v2 0/2] soc: fsl: dpio: Use scope-based resource management in two functions Christophe Leroy (CS GROUP)

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox