cpufreq: ti: Implement scope-based cleanup in ti_cpufreq_match_node()
PATCH 1/1 cpufreq: ti: Implement scope-based cleanup in ti_cpufreq_match_node()
This patch modifies the ti_cpufreq_match_node() function to utilize the __free() cleanup handler for automatically releasing the device node when it goes out of scope.
By moving the declaration to the initialization, the patch ensures that the device node is properly managed throughout the function's scope, thus eliminating the need for manual invocation of of_node_put(). This approach reduces the potential for memory leaks.
--- drivers/cpufreq/ti-cpufreq.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/cpufreq/ti-cpufreq.c +1 -3
@@ -347,12 +347,10 @@ static const struct of_device_id ti_cpufreq_of_match[] = {static const struct of_device_id *ti_cpufreq_match_node (void ) { -struct device_node *np; + struct device_node *np __free(device_node) = of_find_node_by_path("/");const struct of_device_id *match; - np =of_find_node_by_path ("/" ); match =of_match_node (ti_cpufreq_of_match, np); -of_node_put (np);return match; }
--
2.34.1
Quoted 8 lines · Shivani Gupta
This patch modifies the
ti_cpufreq_match_node()function to utilize the__free()cleanup handler for automatically releasing the device node when it goes out of scope.By moving the declaration to the initialization, the patch ensures that the device node is properly managed throughout the function's scope, thus eliminating the need for manual invocation of
of_node_put(). This approach reduces the potential for memory leaks.
The code is fine. The log message is a bit verbose. Try to avoid referring to the patch. It's obvious that you are talking about the patch. Try to favor the imperative, so "Modify..." instead of "This patch modifies".
julia
Quoted 29 lines
Suggested-by Julia Lawall <[email protected]>Signed-off-by Shivani Gupta <[email protected]>--- drivers/cpufreq/ti-cpufreq.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)drivers/cpufreq/ti-cpufreq.c +1
-4@@ -347,12 +347,10 @@ static const struct of_device_id ti_cpufreq_of_match[] = {static const struct of_device_id *ti_cpufreq_match_node (void ) { -struct device_node *np; + struct device_node *np __free(device_node) = of_find_node_by_path("/");const struct of_device_id *match; - np =of_find_node_by_path ("/" ); match =of_match_node (ti_cpufreq_of_match, np); -of_node_put (np);return match; } --2.34.1
Viresh Kumar
maintainerQuoted 13 lines · Julia Lawall
Quoted 8 lines · Shivani Gupta
This patch modifies the
ti_cpufreq_match_node()function to utilize the__free()cleanup handler for automatically releasing the device node when it goes out of scope.By moving the declaration to the initialization, the patch ensures that the device node is properly managed throughout the function's scope, thus eliminating the need for manual invocation of
of_node_put(). This approach reduces the potential for memory leaks.
Quoted 4 lines
The code is fine. The log message is a bit verbose. Try to avoid referring to the patch. It's obvious that you are talking about the patch. Try to favor the imperative, so "Modify..." instead of "This patch modifies".
Fixed while applying.
Signature · 1 line
viresh