[PATCH 0/1 RFC] drivers: cacheinfo: introduce automatic cleanup
From: Vincenzo Mezzela
Date: Sat Jun 22 2024 - 11:25:59 EST
This patch introduces the automatic cleanup feature using the __free attribute
in drivers/base/cacheinfo.c. With this enhancement, resources allocated
with __free are automatically released at the end of their scope, improving
code maintainability and reducing the risk of resource leaks.
This work follows a previous patch [1] that introduced the same feature in
drivers/base/arch_topology.c.
To introduce this feature, some modifications to the code structure were
necessary. The original pattern:
```
prev = np;
while(...) {
[...]
np = of_find_next_cache_node(np);
of_node_put(prev);
prev = np;
[...]
}
```
has been updated to:
```
while(...) {
[...]
struct device_node __free(device_node) *prev = np;
np = of_find_next_cache_node(np)
[...]
}
```
With this change, the previous node is automatically cleaned up at the end
of the scope, allowing the elimination of all of_node_put() calls and some
goto statements.
The updated code has been compiled and run on QEMU. Debugging confirmed
that of_node_put() is called appropriately. However, I was unable to hit
all code paths during testing.
Sending this patch as RFC because I wasn't able to debug and test the
code in the while loops on QEMU. I'm also getting some warning and
errors from checkpatch but I believe these are false positives (?).
Thanks,
Vincenzo
- [1] https://lore.kernel.org/lkml/20240607163350.392971-1-vincenzo.mezzela@xxxxxxxxx/
Vincenzo Mezzela (1):
drivers: cacheinfo: use __free attribute instead of of_node_put()
drivers/base/cacheinfo.c | 41 +++++++++++++---------------------------
1 file changed, 13 insertions(+), 28 deletions(-)
--
2.43.0