Re: [v2 1/2] soc: fsl: dpio: Use scope-based resource management in dpaa2_io_store_create()
From: Ioana Ciornei
Date: Mon Jul 27 2026 - 08:47:28 EST
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