[PATCH v3 1/2] soc: fsl: dpio: Use scope-based resource management in dpaa2_io_store_create()
Markus Elfring <[email protected]> Wed, 29 Jul 2026 13:42:24 +0200
| Newsgroups | gmane.linux.ports.ppc64.devel,gmane.linux.ports.arm.kernel,gmane.linux.kernel,gmane.linux.kernel.janitors |
|---|---|
| Message-ID | <[email protected]> |
From: Markus Elfring <[email protected]> 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 =E2=80=9Cdpaa2_io_store_create=E2=80=9D to a new function. * Use the attribute =E2=80=9C__free(kfree)=E2=80=9D for the local variable= =E2=80=9Cret=E2=80=9D. * Omit two kfree() calls accordingly. Signed-off-by: Markus Elfring <[email protected]> =2D-- 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/dp= io-service.c index 317ca50b0c2b..b621755d8988 100644 =2D-- 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. */ =20 -/** - * dpaa2_io_store_create() - Create the dma memory storage for dequeue re= sult. - * @max_frames: the maximum number of dequeued result for frames, must be= <=3D 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 stora= ge - * 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) =3D kmalloc_obj(*ret); =20 - if (!max_frames || (max_frames > 32)) - return NULL; - - ret =3D kmalloc_obj(*ret); if (!ret) return NULL; =20 ret->max =3D max_frames; size =3D max_frames * sizeof(struct dpaa2_dq) + 64; ret->alloced_addr =3D kzalloc(size, GFP_KERNEL); - if (!ret->alloced_addr) { - kfree(ret); + if (!ret->alloced_addr) return NULL; - } =20 ret->vaddr =3D PTR_ALIGN(ret->alloced_addr, 64); ret->paddr =3D 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; } =20 @@ -685,6 +668,26 @@ struct dpaa2_io_store *dpaa2_io_store_create(unsigned= int max_frames, =20 return ret; } + +/** + * dpaa2_io_store_create() - Create the dma memory storage for dequeue re= sult. + * @max_frames: the maximum number of dequeued result for frames, must be= <=3D 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 stora= ge + * 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); =20 /** =2D-=20 2.55.0