Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

cpupower: Add is_valid_path API

Add is_valid_path API to check whether the sysfs file is present or not.

Suggested-by: Gautham R. Shenoy <gautham.shenoy@amd.com>
Reviewed-by: Mario Limonciello <mario.limonciello@amd.com>
Signed-off-by: Wyes Karny <wyes.karny@amd.com>
Tested-by: Perry Yuan <Perry.Yuan@amd.com>
Acked-by: Huang Rui <ray.huang@amd.com>
Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>

authored by

Wyes Karny and committed by
Shuah Khan
1ce5ab7c a1cf97c2

+8
+7
tools/power/cpupower/lib/cpupower.c
··· 14 14 #include "cpupower.h" 15 15 #include "cpupower_intern.h" 16 16 17 + int is_valid_path(const char *path) 18 + { 19 + if (access(path, F_OK) == -1) 20 + return 0; 21 + return 1; 22 + } 23 + 17 24 unsigned int cpupower_read_sysfs(const char *path, char *buf, size_t buflen) 18 25 { 19 26 ssize_t numread;
+1
tools/power/cpupower/lib/cpupower_intern.h
··· 7 7 8 8 #define SYSFS_PATH_MAX 255 9 9 10 + int is_valid_path(const char *path); 10 11 unsigned int cpupower_read_sysfs(const char *path, char *buf, size_t buflen); 11 12 unsigned int cpupower_write_sysfs(const char *path, char *buf, size_t buflen);