cpupower:Fix resource leaks in sysfs_get_enabled()
authorHao Zeng <zenghao@kylinos.cn>
Tue, 18 Apr 2023 01:30:56 +0000 (09:30 +0800)
committerShuah Khan <skhan@linuxfoundation.org>
Mon, 8 May 2023 14:11:24 +0000 (08:11 -0600)
commite652be0f59d4ba4d5c636b1f7f4dcb73aae049fa
treed511b59633d2d7e50f53baeb9ab5bded66425b64
parentac9a78681b921877518763ba0e89202254349d1b
cpupower:Fix resource leaks in sysfs_get_enabled()

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@kylinos.cn>
Suggested-by: Shuah Khan <skhan@linuxfoundation.org>
Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
tools/power/cpupower/lib/powercap.c