Re: [PATCH v4] cpupower:Fix resource leaks in sysfs_get_enabled()

From: Shuah Khan
Date: Tue Apr 18 2023 - 11:42:13 EST


On 4/17/23 19:30, Hao Zeng wrote:
The sysfs_get_enabled() opened file processor not closed,
may cause a file handle leak.
Putting error handling and resource cleanup code together
makes the code easy to maintain and read.
Removed the unnecessary else if branch from the original
function, as it should return an error in cases other than '0'.

Signed-off-by: Hao Zeng <zenghao@xxxxxxxxxx>
Suggested-by: Shuah Khan <skhan@xxxxxxxxxxxxxxxxxxx>
---
tools/power/cpupower/lib/powercap.c | 23 ++++++++++++++++-------
1 file changed, 16 insertions(+), 7 deletions(-)


Thank you.

Applied to
git://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux.git cpupower
branch for Linux 6.4-rc1

thanks,
-- Shuah