drivers/base/arch_topology.c | 145 +++++++++++++++++------------------ 1 file changed, 72 insertions(+), 73 deletions(-)
This patch series introduces the automatic cleanup feature using the __free
attribute. With this modification, resources allocated with __free are
automatically released at the end of the scope.
In some cases, modifying the structure of loops is necessary to utilize the
__free attribute effectively. For example:
```
struct device_node *t;
do {
t = of_get_child_by_name(..);
if (t) {
// some code here
of_node_put(t);
}
i++;
} while (t);
// ^
// |
// device_node here
```
To use the __free attribute here, we need to move the declaration of the device_node
within the loop, otherwise the automatic cleanup is called only at the end of the
function, and not at end of each iteration of the loop, being it scope-based.
However, moving the declaration of the device_node within the loop, we can no
longer check the exit condition in the loop statement, being it outside
the loop's scope.
Therefore, this work is split into two patches. The first patch moves the exit
condition of the loop directly within the loop's scope with an explicit break
statement:
```
struct device_node *t;
do {
t = of_get_child_by_name(..);
if (!t)
break;
// some code here
of_node_put(t);
i++;
} while (1);
```
The second patch eliminates all of_node_put() calls, introducing the __free
attribute to the device_node.
changes in v2:
- check loop exit condition within the loop
- add cleanup.h header
changes in v3:
- split patch in two
- fix misalignment
- fix checkpatch warnings
- replace break with return statement where possible
changes in v4:
- fix commit subject
- fix coding style
Vincenzo Mezzela (2):
drivers: arch_topology: Refactor do-while loops
drivers: arch_topology: use __free attribute instead of of_node_put()
drivers/base/arch_topology.c | 145 +++++++++++++++++------------------
1 file changed, 72 insertions(+), 73 deletions(-)
--
2.34.1
On Mon, May 13, 2024 at 10:13:02AM +0200, Vincenzo Mezzela wrote:
> This patch series introduces the automatic cleanup feature using the __free
> attribute. With this modification, resources allocated with __free are
> automatically released at the end of the scope.
>
> In some cases, modifying the structure of loops is necessary to utilize the
> __free attribute effectively. For example:
>
> ```
> struct device_node *t;
>
> do {
> t = of_get_child_by_name(..);
> if (t) {
>
> // some code here
>
> of_node_put(t);
> }
> i++;
>
> } while (t);
>
> // ^
> // |
> // device_node here
> ```
>
> To use the __free attribute here, we need to move the declaration of the device_node
> within the loop, otherwise the automatic cleanup is called only at the end of the
> function, and not at end of each iteration of the loop, being it scope-based.
>
> However, moving the declaration of the device_node within the loop, we can no
> longer check the exit condition in the loop statement, being it outside
> the loop's scope.
>
> Therefore, this work is split into two patches. The first patch moves the exit
> condition of the loop directly within the loop's scope with an explicit break
> statement:
>
> ```
> struct device_node *t;
>
> do {
> t = of_get_child_by_name(..);
> if (!t)
> break;
>
> // some code here
>
> of_node_put(t);
> i++;
>
> } while (1);
> ```
> The second patch eliminates all of_node_put() calls, introducing the __free
> attribute to the device_node.
>
>
> changes in v2:
> - check loop exit condition within the loop
> - add cleanup.h header
>
> changes in v3:
> - split patch in two
> - fix misalignment
> - fix checkpatch warnings
> - replace break with return statement where possible
>
> changes in v4:
> - fix commit subject
> - fix coding style
>
Looks good now to me.
Acked-by: Sudeep Holla <sudeep.holla@arm.com>
It is merge window now, so there is a chance that it may get lost. You
may have to post it again at -rc1. Greg can then pick it up for v6.11
--
Regards,
Sudeep
On 13/05/24 12:02, Sudeep Holla wrote:
> On Mon, May 13, 2024 at 10:13:02AM +0200, Vincenzo Mezzela wrote:
>> This patch series introduces the automatic cleanup feature using the __free
>> attribute. With this modification, resources allocated with __free are
>> automatically released at the end of the scope.
>>
>> In some cases, modifying the structure of loops is necessary to utilize the
>> __free attribute effectively. For example:
>>
>> ```
>> struct device_node *t;
>>
>> do {
>> t = of_get_child_by_name(..);
>> if (t) {
>>
>> // some code here
>>
>> of_node_put(t);
>> }
>> i++;
>>
>> } while (t);
>>
>> // ^
>> // |
>> // device_node here
>> ```
>>
>> To use the __free attribute here, we need to move the declaration of the device_node
>> within the loop, otherwise the automatic cleanup is called only at the end of the
>> function, and not at end of each iteration of the loop, being it scope-based.
>>
>> However, moving the declaration of the device_node within the loop, we can no
>> longer check the exit condition in the loop statement, being it outside
>> the loop's scope.
>>
>> Therefore, this work is split into two patches. The first patch moves the exit
>> condition of the loop directly within the loop's scope with an explicit break
>> statement:
>>
>> ```
>> struct device_node *t;
>>
>> do {
>> t = of_get_child_by_name(..);
>> if (!t)
>> break;
>>
>> // some code here
>>
>> of_node_put(t);
>> i++;
>>
>> } while (1);
>> ```
>> The second patch eliminates all of_node_put() calls, introducing the __free
>> attribute to the device_node.
>>
>>
>> changes in v2:
>> - check loop exit condition within the loop
>> - add cleanup.h header
>>
>> changes in v3:
>> - split patch in two
>> - fix misalignment
>> - fix checkpatch warnings
>> - replace break with return statement where possible
>>
>> changes in v4:
>> - fix commit subject
>> - fix coding style
>>
> Looks good now to me.
>
> Acked-by: Sudeep Holla<sudeep.holla@arm.com>
>
> It is merge window now, so there is a chance that it may get lost. You
> may have to post it again at -rc1. Greg can then pick it up for v6.11
>
> --
> Regards,t
> Sudeep
Hi Greg,
hope this message finds you well. I wanted to kindly follow up on the
patch [1] I
submitted to introduce the __free attribute in drivers/base/arch_topology.c
Thanks,
Vincenzo
- [1]
https://lore.kernel.org/lkml/20240513081304.499915-1-vincenzo.mezzela@gmail.com/
On Tue, May 28, 2024 at 10:23:37AM +0200, Vincenzo Mezzela wrote: > On 13/05/24 12:02, Sudeep Holla wrote: [...] > > > changes in v4: > > > - fix commit subject > > > - fix coding style > > > > > Looks good now to me. > > > > Acked-by: Sudeep Holla<sudeep.holla@arm.com> > > > > It is merge window now, so there is a chance that it may get lost. You > > may have to post it again at -rc1. Greg can then pick it up for v6.11 > > > > -- > > Regards,t > > Sudeep > > Hi Greg, > > hope this message finds you well. I wanted to kindly follow up on the patch > [1] I > submitted to introduce the __free attribute in drivers/base/arch_topology.c > Hi Vincenzo, Just rebase on -rc1/rc2 and resend the code as the original patch might have got lost deep in the mbox. -- Regards, Sudeep
On 13/05/24 12:02, Sudeep Holla wrote:
> On Mon, May 13, 2024 at 10:13:02AM +0200, Vincenzo Mezzela wrote:
>> This patch series introduces the automatic cleanup feature using the __free
>> attribute. With this modification, resources allocated with __free are
>> automatically released at the end of the scope.
>>
>> In some cases, modifying the structure of loops is necessary to utilize the
>> __free attribute effectively. For example:
>>
>> ```
>> struct device_node *t;
>>
>> do {
>> t = of_get_child_by_name(..);
>> if (t) {
>>
>> // some code here
>>
>> of_node_put(t);
>> }
>> i++;
>>
>> } while (t);
>>
>> // ^
>> // |
>> // device_node here
>> ```
>>
>> To use the __free attribute here, we need to move the declaration of the device_node
>> within the loop, otherwise the automatic cleanup is called only at the end of the
>> function, and not at end of each iteration of the loop, being it scope-based.
>>
>> However, moving the declaration of the device_node within the loop, we can no
>> longer check the exit condition in the loop statement, being it outside
>> the loop's scope.
>>
>> Therefore, this work is split into two patches. The first patch moves the exit
>> condition of the loop directly within the loop's scope with an explicit break
>> statement:
>>
>> ```
>> struct device_node *t;
>>
>> do {
>> t = of_get_child_by_name(..);
>> if (!t)
>> break;
>>
>> // some code here
>>
>> of_node_put(t);
>> i++;
>>
>> } while (1);
>> ```
>> The second patch eliminates all of_node_put() calls, introducing the __free
>> attribute to the device_node.
>>
>>
>> changes in v2:
>> - check loop exit condition within the loop
>> - add cleanup.h header
>>
>> changes in v3:
>> - split patch in two
>> - fix misalignment
>> - fix checkpatch warnings
>> - replace break with return statement where possible
>>
>> changes in v4:
>> - fix commit subject
>> - fix coding style
>>
> Looks good now to me.
>
> Acked-by: Sudeep Holla <sudeep.holla@arm.com>
>
> It is merge window now, so there is a chance that it may get lost. You
> may have to post it again at -rc1. Greg can then pick it up for v6.11
>
> --
> Regards,
> Sudeep
Ok, perfect.
Thanks!
Vincenzo
© 2016 - 2026 Red Hat, Inc.