mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Markus Elfring <Markus.Elfring@web.de>
To: linuxppc-dev@lists.ozlabs.org,
	linux-arm-kernel@lists.infradead.org,
	Christophe Leroy <chleroy@kernel.org>,
	Dan Carpenter <error27@gmail.com>,
	Ioana Ciornei <ioana.ciornei@nxp.com>,
	Roy Pledge <Roy.Pledge@nxp.com>
Cc: LKML <linux-kernel@vger.kernel.org>,
	kernel-janitors@vger.kernel.org,
	Peter Zijlstra <peterz@infradead.org>
Subject: [PATCH v4 1/2] soc: fsl: dpio: Use scope-based resource management in dpaa2_io_store_create()
Date: Thu, 24 Sep 2026 09:17:26 +0200	[thread overview]
Message-ID: <7862715c-da53-49ba-9fc1-6ca5c5d39dde@web.de> (raw)
In-Reply-To: <6c08552a-49e9-4ee0-b1ba-b27e17ade9c5@web.de>

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Wed, 23 Sep 2026 15:48:11 +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.

* Replace a return statement by the macro call “return_ptr(ret)”.

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

diff --git a/drivers/soc/fsl/dpio/dpio-service.c b/drivers/soc/fsl/dpio/dpio-service.c
index 317ca50b0c2b..cb870aae30b4 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,14 +660,33 @@ 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);
+}
+
+/**
+ * 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


  reply	other threads:[~2026-09-24  7:17 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-24  7:15 [PATCH v4 0/2] soc: fsl: dpio: Use scope-based resource management in two functions Markus Elfring
2026-09-24  7:17 ` Markus Elfring [this message]
2026-09-24  7:19 ` [PATCH v4 2/2] soc: fsl: dpio: Use scope-based resource management in dpaa2_io_create() Markus Elfring

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=7862715c-da53-49ba-9fc1-6ca5c5d39dde@web.de \
    --to=markus.elfring@web.de \
    --cc=Roy.Pledge@nxp.com \
    --cc=chleroy@kernel.org \
    --cc=error27@gmail.com \
    --cc=ioana.ciornei@nxp.com \
    --cc=kernel-janitors@vger.kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linuxppc-dev@lists.ozlabs.org \
    --cc=peterz@infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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®