cpupower: Add is_valid_path API
authorWyes Karny <wyes.karny@amd.com>
Mon, 19 Jun 2023 19:05:00 +0000 (19:05 +0000)
committerShuah Khan <skhan@linuxfoundation.org>
Tue, 18 Jul 2023 22:06:44 +0000 (16:06 -0600)
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>
tools/power/cpupower/lib/cpupower.c
tools/power/cpupower/lib/cpupower_intern.h

index 3f7d0c0..7a2ef69 100644 (file)
 #include "cpupower.h"
 #include "cpupower_intern.h"
 
+int is_valid_path(const char *path)
+{
+       if (access(path, F_OK) == -1)
+               return 0;
+       return 1;
+}
+
 unsigned int cpupower_read_sysfs(const char *path, char *buf, size_t buflen)
 {
        ssize_t numread;
index ac1112b..5fdb862 100644 (file)
@@ -7,5 +7,6 @@
 
 #define SYSFS_PATH_MAX 255
 
+int is_valid_path(const char *path);
 unsigned int cpupower_read_sysfs(const char *path, char *buf, size_t buflen);
 unsigned int cpupower_write_sysfs(const char *path, char *buf, size_t buflen);