[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <20240622152526.131974-1-vincenzo.mezzela@gmail.com>
Date: Sat, 22 Jun 2024 17:25:25 +0200
From: Vincenzo Mezzela <vincenzo.mezzela@...il.com>
To: gregkh@...uxfoundation.org,
rafael@...nel.org
Cc: linux-kernel@...r.kernel.org,
javier.carrasco.cruz@...il.com,
julia.lawall@...ia.fr,
skhan@...uxfoundation.org,
Vincenzo Mezzela <vincenzo.mezzela@...il.com>
Subject: [PATCH 0/1 RFC] drivers: cacheinfo: introduce automatic cleanup
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@gmail.com/
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
Powered by blists - more mailing lists