You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
drivers: cacheinfo: use __free attribute instead of of_node_put()
Introduce the __free attribute for scope-based resource management.
Resources allocated with __free are automatically released at the end of
the scope. This enhancement aims to mitigate memory management issues
associated with forgetting to release resources by utilizing __free
instead of of_node_put().
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 each iteration, allowing the elimination of all of_node_put() calls and
some goto statements.
Suggested-by: Julia Lawall <[email protected]>
Signed-off-by: Vincenzo Mezzela <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Greg Kroah-Hartman <[email protected]>
0 commit comments