From fed79474e4d38321dba7ac0bc16f6bfb96260c41 Mon Sep 17 00:00:00 2001 From: Thomas Richter Date: Mon, 7 Apr 2025 15:23:19 +0200 Subject: [PATCH] cpumf: Convert S390_CPUMF_XXX to util_path_sysfs() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Use util_path_sysfs() to form a fully qualified sysfs file name for files S390_CPUMF_CF, S390_CPUMF_CFDIAG, S390_CPUMF_SF, S390_SYSFS_PAI_CRYPTO and S390_SYSFS_PAI_EXT. No functional change. Signed-off-by: Thomas Richter Reviewed-by: Sumanth Korikkar Reviewed-by: Jan Höppner Signed-off-by: Jan Höppner --- cpumf/lspai.c | 2 +- include/lib/libcpumf.h | 10 +++++----- libcpumf/libcpumf_pmutype.c | 9 +++------ libcpumf/libcpumf_support.c | 23 ++++++++++++++--------- 4 files changed, 23 insertions(+), 21 deletions(-) diff --git a/cpumf/lspai.c b/cpumf/lspai.c index 434601a3..d2646b71 100644 --- a/cpumf/lspai.c +++ b/cpumf/lspai.c @@ -243,7 +243,7 @@ static void make_painode(enum pai_types t) node->base = pai_type_base(t); /* Read PMU type number. */ - path = util_path_sysfs(PAI_PATH, node->sysfs_name); + util_asprintf(&path, PAI_PATH, node->sysfs_name); node->pmu = libcpumf_pmutype(path); if (node->pmu < 0) errx(EXIT_FAILURE, "Cannot open %s", path); diff --git a/include/lib/libcpumf.h b/include/lib/libcpumf.h index 4f672b0c..33a1f832 100644 --- a/include/lib/libcpumf.h +++ b/include/lib/libcpumf.h @@ -10,13 +10,13 @@ #include #include -#define S390_CPUMF_CF "/sys/devices/cpum_cf/" -#define S390_CPUMF_CFDIAG "/sys/devices/cpum_cf_diag/" -#define S390_CPUMF_SF "/sys/devices/cpum_sf/" +#define S390_CPUMF_CF "devices/cpum_cf/" +#define S390_CPUMF_CFDIAG "devices/cpum_cf_diag/" +#define S390_CPUMF_SF "devices/cpum_sf/" #define S390_CPUS_ONLINE "devices/system/cpu/online" #define S390_CPUMSF_BUFFERSZ "module/kernel/parameters/cpum_sfb_size" -#define S390_SYSFS_PAI_CRYPTO "/sys/devices/pai_crypto/" -#define S390_SYSFS_PAI_EXT "/sys/devices/pai_ext/" +#define S390_SYSFS_PAI_CRYPTO "devices/pai_crypto/" +#define S390_SYSFS_PAI_EXT "devices/pai_ext/" #define S390_SYSFS_PAI_NNPA S390_SYSFS_PAI_EXT "events/NNPA_ALL" #define CPUMF_CTRSET_NONE 0 diff --git a/libcpumf/libcpumf_pmutype.c b/libcpumf/libcpumf_pmutype.c index f301e74d..4215b3b6 100644 --- a/libcpumf/libcpumf_pmutype.c +++ b/libcpumf/libcpumf_pmutype.c @@ -1,4 +1,4 @@ -/* Copyright IBM Corp. 2022 +/* Copyright IBM Corp. 2022, 2025 * * s390-tools is free software; you can redistribute it and/or modify * it under the terms of the MIT license. See LICENSE for details. @@ -18,16 +18,13 @@ int libcpumf_pmutype(const char *dirname) { + int ret = -1; FILE *file; char *fn; - int ret; - ret = asprintf(&fn, "%s/type", dirname); - if (ret == -1) /* No memory, errno set */ - return ret; + fn = util_path_sysfs("%s/type", dirname); file = fopen(fn, "r"); free(fn); - ret = -1; /* Errno set on file open error */ if (file) { /* Read out a single number from that file */ if (fscanf(file, "%u", &ret) != 1) diff --git a/libcpumf/libcpumf_support.c b/libcpumf/libcpumf_support.c index c32be93a..69630025 100644 --- a/libcpumf/libcpumf_support.c +++ b/libcpumf/libcpumf_support.c @@ -144,23 +144,28 @@ bool libcpumf_sfb_info(unsigned long *min, unsigned long *max) return rc; } +static bool libcpumf_have_pai_sysfs(char *p) +{ + char *path; + bool ret; + + path = util_path_sysfs(p); + ret = util_path_exists(path); + free(path); + return ret; +} + bool libcpumf_have_pai_crypto(void) { - struct stat statbuf; - - return (stat(S390_SYSFS_PAI_CRYPTO, &statbuf) == -1) ? false : true; + return libcpumf_have_pai_sysfs(S390_SYSFS_PAI_CRYPTO); } bool libcpumf_have_pai_ext(void) { - struct stat statbuf; - - return (stat(S390_SYSFS_PAI_EXT, &statbuf) == -1) ? false : true; + return libcpumf_have_pai_sysfs(S390_SYSFS_PAI_EXT); } bool libcpumf_have_pai_nnpa(void) { - struct stat statbuf; - - return (stat(S390_SYSFS_PAI_NNPA, &statbuf) == -1) ? false : true; + return libcpumf_have_pai_sysfs(S390_SYSFS_PAI_NNPA); }