mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v3 0/2] soc: fsl: dpio: Use scope-based resource management in two functions
@ 2026-07-29 11:36 Markus Elfring
  2026-07-29 11:42 ` [PATCH v3 1/2] soc: fsl: dpio: Use scope-based resource management in dpaa2_io_store_create() Markus Elfring
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Markus Elfring @ 2026-07-29 11:36 UTC (permalink / raw)
  To: linuxppc-dev, linux-arm-kernel, Christophe Leroy, Dan Carpenter,
	Ioana Ciornei, Roy Pledge
  Cc: LKML, kernel-janitors, Peter Zijlstra

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Wed, 29 Jul 2026 13:28:09 +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()


v3:
* Dan Carpenter requested to add an #include directive.
  https://lore.kernel.org/kernel-janitors/amdBqQfIsAjxMsqX@stanley.mountain/

* Ioana Ciornei requested to keep variable declarations at the start of
  function implementations.
  https://lore.kernel.org/kernel-janitors/6woig227u5snmdsrjfuw7gfcf3vk5iwaap4yf7ow6b6s3pba7z@yg4vmdoaak3h/


v2:
Christophe Leroy requested to apply the attribute “__free(kfree)”.
https://lore.kernel.org/kernel-janitors/d95d2f4c-f3cf-44eb-b61b-79ba7891674d@kernel.org/


 drivers/soc/fsl/dpio/dpio-service.c | 37 ++++++++++-------------------
 1 file changed, 12 insertions(+), 25 deletions(-)

-- 
2.54.0


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

* [PATCH v3 1/2] soc: fsl: dpio: Use scope-based resource management in dpaa2_io_store_create()
  2026-07-29 11:36 [PATCH v3 0/2] soc: fsl: dpio: Use scope-based resource management in two functions Markus Elfring
@ 2026-07-29 11:42 ` Markus Elfring
  2026-07-29 11:44 ` [PATCH v3 2/2] soc: fsl: dpio: Use scope-based resource management in dpaa2_io_create() Markus Elfring
  2026-09-22 10:23 ` [PATCH v3 0/2] soc: fsl: dpio: Use scope-based resource management in two functions Christophe Leroy (CS GROUP)
  2 siblings, 0 replies; 4+ messages in thread
From: Markus Elfring @ 2026-07-29 11:42 UTC (permalink / raw)
  To: linuxppc-dev, linux-arm-kernel, Christophe Leroy, Dan Carpenter,
	Ioana Ciornei, Roy Pledge
  Cc: LKML, kernel-janitors, Peter Zijlstra

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Wed, 29 Jul 2026 10:54:15 +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_store_create” to a new function.

* Use the attribute “__free(kfree)” for the local variable “ret”.

* Omit two kfree() calls accordingly.

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
 drivers/soc/fsl/dpio/dpio-service.c | 47 +++++++++++++++--------------
 1 file changed, 25 insertions(+), 22 deletions(-)

diff --git a/drivers/soc/fsl/dpio/dpio-service.c b/drivers/soc/fsl/dpio/dpio-service.c
index 317ca50b0c2b..b621755d8988 100644
--- a/drivers/soc/fsl/dpio/dpio-service.c
+++ b/drivers/soc/fsl/dpio/dpio-service.c
@@ -4,6 +4,7 @@
  * Copyright 2016-2019 NXP
  *
  */
+#include <linux/cleanup.h>
 #include <linux/types.h>
 #include <linux/fsl/mc.h>
 #include <soc/fsl/dpaa2-io.h>
@@ -638,37 +639,20 @@ EXPORT_SYMBOL_GPL(dpaa2_io_service_acquire);
  * assist with parsing those results.
  */
 
-/**
- * dpaa2_io_store_create() - Create the dma memory storage for dequeue result.
- * @max_frames: the maximum number of dequeued result for frames, must be <= 32.
- * @dev:        the device to allow mapping/unmapping the DMAable region.
- *
- * The size of the storage is "max_frames*sizeof(struct dpaa2_dq)".
- * The 'dpaa2_io_store' returned is a DPIO service managed object.
- *
- * Return pointer to dpaa2_io_store struct for successfully created storage
- * memory, or NULL on error.
- */
-struct dpaa2_io_store *dpaa2_io_store_create(unsigned int max_frames,
-					     struct device *dev)
+static inline
+struct dpaa2_io_store *dpaa2_io_store_create_impl(unsigned int max_frames, struct device *dev)
 {
-	struct dpaa2_io_store *ret;
 	size_t size;
+	struct dpaa2_io_store *ret __free(kfree) = kmalloc_obj(*ret);
 
-	if (!max_frames || (max_frames > 32))
-		return NULL;
-
-	ret = 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);
+	if (!ret->alloced_addr)
 		return NULL;
-	}
 
 	ret->vaddr = PTR_ALIGN(ret->alloced_addr, 64);
 	ret->paddr = dma_map_single(dev, ret->vaddr,
@@ -676,7 +660,6 @@ 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;
 	}
 
@@ -685,6 +668,26 @@ struct dpaa2_io_store *dpaa2_io_store_create(unsigned int max_frames,
 
 	return ret;
 }
+
+/**
+ * dpaa2_io_store_create() - Create the dma memory storage for dequeue result.
+ * @max_frames: the maximum number of dequeued result for frames, must be <= 32.
+ * @dev:        the device to allow mapping/unmapping the DMAable region.
+ *
+ * The size of the storage is "max_frames*sizeof(struct dpaa2_dq)".
+ * The 'dpaa2_io_store' returned is a DPIO service managed object.
+ *
+ * Return pointer to dpaa2_io_store struct for successfully created storage
+ * memory, or NULL on error.
+ */
+struct dpaa2_io_store *dpaa2_io_store_create(unsigned int max_frames,
+					     struct device *dev)
+{
+	if (!max_frames || (max_frames > 32))
+		return NULL;
+
+	return dpaa2_io_store_create_impl(max_frames, dev);
+}
 EXPORT_SYMBOL_GPL(dpaa2_io_store_create);
 
 /**
-- 
2.55.0


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

* [PATCH v3 2/2] soc: fsl: dpio: Use scope-based resource management in dpaa2_io_create()
  2026-07-29 11:36 [PATCH v3 0/2] soc: fsl: dpio: Use scope-based resource management in two functions Markus Elfring
  2026-07-29 11:42 ` [PATCH v3 1/2] soc: fsl: dpio: Use scope-based resource management in dpaa2_io_store_create() Markus Elfring
@ 2026-07-29 11:44 ` Markus Elfring
  2026-09-22 10:23 ` [PATCH v3 0/2] soc: fsl: dpio: Use scope-based resource management in two functions Christophe Leroy (CS GROUP)
  2 siblings, 0 replies; 4+ messages in thread
From: Markus Elfring @ 2026-07-29 11:44 UTC (permalink / raw)
  To: linuxppc-dev, linux-arm-kernel, Christophe Leroy, Dan Carpenter,
	Ioana Ciornei, Roy Pledge
  Cc: LKML, kernel-janitors, Peter Zijlstra

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Wed, 29 Jul 2026 12:46:56 +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.

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
 drivers/soc/fsl/dpio/dpio-service.c | 46 +++++++++++++++--------------
 1 file changed, 24 insertions(+), 22 deletions(-)

diff --git a/drivers/soc/fsl/dpio/dpio-service.c b/drivers/soc/fsl/dpio/dpio-service.c
index b621755d8988..4ff99928e9c6 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);
@@ -195,6 +177,26 @@ struct dpaa2_io *dpaa2_io_create(const struct dpaa2_io_desc *desc,
 	return 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);
+}
+
 /**
  * dpaa2_io_down() - release the dpaa2_io object.
  * @d: the dpaa2_io object to be released.
-- 
2.55.0


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

* Re: [PATCH v3 0/2] soc: fsl: dpio: Use scope-based resource management in two functions
  2026-07-29 11:36 [PATCH v3 0/2] soc: fsl: dpio: Use scope-based resource management in two functions Markus Elfring
  2026-07-29 11:42 ` [PATCH v3 1/2] soc: fsl: dpio: Use scope-based resource management in dpaa2_io_store_create() Markus Elfring
  2026-07-29 11:44 ` [PATCH v3 2/2] soc: fsl: dpio: Use scope-based resource management in dpaa2_io_create() Markus Elfring
@ 2026-09-22 10:23 ` Christophe Leroy (CS GROUP)
  2 siblings, 0 replies; 4+ messages in thread
From: Christophe Leroy (CS GROUP) @ 2026-09-22 10:23 UTC (permalink / raw)
  To: Markus Elfring, linuxppc-dev, linux-arm-kernel, Dan Carpenter,
	Ioana Ciornei, Roy Pledge
  Cc: LKML, kernel-janitors, Peter Zijlstra



Le 29/07/2026 à 13:36, Markus Elfring a écrit :
> From: Markus Elfring <elfring@users.sourceforge.net>
> Date: Wed, 29 Jul 2026 13:28:09 +0200
> 
> Some adjustment opportunities were picked up.

Feedback from sashiko has to be adressed at least, see 
https://sashiko.dev/#/patchset/709fefd1-821a-4cd1-8598-b1179a95ce52@web.de

Christophe

> 
> Markus Elfring (2):
>    Use scope-based resource management in dpaa2_io_store_create()
>    Use scope-based resource management in dpaa2_io_create()
> 
> 
> v3:
> * Dan Carpenter requested to add an #include directive.
>    https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Flore.kernel.org%2Fkernel-janitors%2FamdBqQfIsAjxMsqX%40stanley.mountain%2F&data=05%7C02%7Cchristophe.leroy%40csgroup.eu%7C6bd2db2a294b450f9afe08deed65baaf%7C8b87af7d86474dc78df45f69a2011bb5%7C0%7C0%7C639209218359212161%7CUnknown%7CTWFpbGZsb3d8eyJFbXB0eU1hcGkiOnRydWUsIlYiOiIwLjAuMDAwMCIsIlAiOiJXaW4zMiIsIkFOIjoiTWFpbCIsIldUIjoyfQ%3D%3D%7C0%7C%7C%7C&sdata=6%2F8aUajE%2B%2FNYTpo%2B09SVBa9lbZez3WYGUhtpdSTYF4w%3D&reserved=0
> 
> * Ioana Ciornei requested to keep variable declarations at the start of
>    function implementations.
>    https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Flore.kernel.org%2Fkernel-janitors%2F6woig227u5snmdsrjfuw7gfcf3vk5iwaap4yf7ow6b6s3pba7z%40yg4vmdoaak3h%2F&data=05%7C02%7Cchristophe.leroy%40csgroup.eu%7C6bd2db2a294b450f9afe08deed65baaf%7C8b87af7d86474dc78df45f69a2011bb5%7C0%7C0%7C639209218359235520%7CUnknown%7CTWFpbGZsb3d8eyJFbXB0eU1hcGkiOnRydWUsIlYiOiIwLjAuMDAwMCIsIlAiOiJXaW4zMiIsIkFOIjoiTWFpbCIsIldUIjoyfQ%3D%3D%7C0%7C%7C%7C&sdata=icEeNsVtx34DKgqjmsDjR3QUqqmeSh1o7gWr5PJYFKo%3D&reserved=0
> 
> 
> v2:
> Christophe Leroy requested to apply the attribute “__free(kfree)”.
> https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Flore.kernel.org%2Fkernel-janitors%2Fd95d2f4c-f3cf-44eb-b61b-79ba7891674d%40kernel.org%2F&data=05%7C02%7Cchristophe.leroy%40csgroup.eu%7C6bd2db2a294b450f9afe08deed65baaf%7C8b87af7d86474dc78df45f69a2011bb5%7C0%7C0%7C639209218359253601%7CUnknown%7CTWFpbGZsb3d8eyJFbXB0eU1hcGkiOnRydWUsIlYiOiIwLjAuMDAwMCIsIlAiOiJXaW4zMiIsIkFOIjoiTWFpbCIsIldUIjoyfQ%3D%3D%7C0%7C%7C%7C&sdata=wx8iGxIWhoBQPzSqd2fsa4eeZV9DTQ9pEBL4AWxLcdY%3D&reserved=0
> 
> 
>   drivers/soc/fsl/dpio/dpio-service.c | 37 ++++++++++-------------------
>   1 file changed, 12 insertions(+), 25 deletions(-)
> 


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

end of thread, other threads:[~2026-09-22 10:23 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-07-29 11:36 [PATCH v3 0/2] soc: fsl: dpio: Use scope-based resource management in two functions Markus Elfring
2026-07-29 11:42 ` [PATCH v3 1/2] soc: fsl: dpio: Use scope-based resource management in dpaa2_io_store_create() Markus Elfring
2026-07-29 11:44 ` [PATCH v3 2/2] soc: fsl: dpio: Use scope-based resource management in dpaa2_io_create() Markus Elfring
2026-09-22 10:23 ` [PATCH v3 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

all inboxes | Powered by JetHome®