[v3,2/5] cpupower: Add is_valid_path API

Message ID 20230619190503.4061-3-wyes.karny@amd.com
State New
Headers
Series cpupower: Add various feature control support for amd_pstate |

Commit Message

Wyes Karny June 19, 2023, 7:05 p.m. UTC
  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>
---
 tools/power/cpupower/lib/cpupower.c        | 7 +++++++
 tools/power/cpupower/lib/cpupower_intern.h | 1 +
 2 files changed, 8 insertions(+)
  

Comments

Yuan, Perry June 20, 2023, 3:09 a.m. UTC | #1
[AMD Official Use Only - General]

> -----Original Message-----
> From: Karny, Wyes <Wyes.Karny@amd.com>
> Sent: Tuesday, June 20, 2023 3:05 AM
> To: trenn@suse.com; shuah@kernel.org
> Cc: linux-pm@vger.kernel.org; linux-kernel@vger.kernel.org; rafael@kernel.org;
> Shenoy, Gautham Ranjal <gautham.shenoy@amd.com>; Limonciello, Mario
> <Mario.Limonciello@amd.com>; Huang, Ray <Ray.Huang@amd.com>; Yuan,
> Perry <Perry.Yuan@amd.com>; Karny, Wyes <Wyes.Karny@amd.com>;
> Limonciello, Mario <Mario.Limonciello@amd.com>
> Subject: [PATCH v3 2/5] 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>
> ---
>  tools/power/cpupower/lib/cpupower.c        | 7 +++++++
>  tools/power/cpupower/lib/cpupower_intern.h | 1 +
>  2 files changed, 8 insertions(+)
>
> diff --git a/tools/power/cpupower/lib/cpupower.c
> b/tools/power/cpupower/lib/cpupower.c
> index 3f7d0c0c5067..7a2ef691b20e 100644
> --- a/tools/power/cpupower/lib/cpupower.c
> +++ b/tools/power/cpupower/lib/cpupower.c
> @@ -14,6 +14,13 @@
>  #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;
> diff --git a/tools/power/cpupower/lib/cpupower_intern.h
> b/tools/power/cpupower/lib/cpupower_intern.h
> index ac1112b956ec..5fdb8620d41b 100644
> --- a/tools/power/cpupower/lib/cpupower_intern.h
> +++ b/tools/power/cpupower/lib/cpupower_intern.h
> @@ -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);
> --
> 2.34.1

Tested-by: Perry Yuan <Perry.Yuan@amd.com>
  
Huang Rui June 20, 2023, 12:59 p.m. UTC | #2
On Tue, Jun 20, 2023 at 03:05:00AM +0800, Karny, Wyes wrote:
> 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>

Acked-by: Huang Rui <ray.huang@amd.com>

> ---
>  tools/power/cpupower/lib/cpupower.c        | 7 +++++++
>  tools/power/cpupower/lib/cpupower_intern.h | 1 +
>  2 files changed, 8 insertions(+)
> 
> diff --git a/tools/power/cpupower/lib/cpupower.c b/tools/power/cpupower/lib/cpupower.c
> index 3f7d0c0c5067..7a2ef691b20e 100644
> --- a/tools/power/cpupower/lib/cpupower.c
> +++ b/tools/power/cpupower/lib/cpupower.c
> @@ -14,6 +14,13 @@
>  #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;
> diff --git a/tools/power/cpupower/lib/cpupower_intern.h b/tools/power/cpupower/lib/cpupower_intern.h
> index ac1112b956ec..5fdb8620d41b 100644
> --- a/tools/power/cpupower/lib/cpupower_intern.h
> +++ b/tools/power/cpupower/lib/cpupower_intern.h
> @@ -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);
> -- 
> 2.34.1
>
  

Patch

diff --git a/tools/power/cpupower/lib/cpupower.c b/tools/power/cpupower/lib/cpupower.c
index 3f7d0c0c5067..7a2ef691b20e 100644
--- a/tools/power/cpupower/lib/cpupower.c
+++ b/tools/power/cpupower/lib/cpupower.c
@@ -14,6 +14,13 @@ 
 #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;
diff --git a/tools/power/cpupower/lib/cpupower_intern.h b/tools/power/cpupower/lib/cpupower_intern.h
index ac1112b956ec..5fdb8620d41b 100644
--- a/tools/power/cpupower/lib/cpupower_intern.h
+++ b/tools/power/cpupower/lib/cpupower_intern.h
@@ -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);