[PATCH i-g-t 2/3] lib/igt_sysfs: Add igt_sysfs_{get,set}_s32
Kamil Konieczny
kamil.konieczny at linux.intel.com
Fri Oct 11 08:36:12 UTC 2024
Hi Francois,
On 2024-10-09 at 14:28:48 +0200, Francois Dugast wrote:
> Add this family of functions to read and write signed values in sysfs.
imho better:
Add functions to read and write 32-bit signed values in sysfs.
Reviewed-by: Kamil Konieczny <kamil.konieczny at linux.intel.com>
>
> Signed-off-by: Francois Dugast <francois.dugast at intel.com>
> ---
> lib/igt_sysfs.c | 71 +++++++++++++++++++++++++++++++++++++++++++++++++
> lib/igt_sysfs.h | 5 ++++
> 2 files changed, 76 insertions(+)
>
> diff --git a/lib/igt_sysfs.c b/lib/igt_sysfs.c
> index b7746a1ec..56279d958 100644
> --- a/lib/igt_sysfs.c
> +++ b/lib/igt_sysfs.c
> @@ -873,6 +873,77 @@ void igt_sysfs_set_u32(int dir, const char *attr, uint32_t value)
> "Failed to write %u to %s attribute (%s)\n", value, attr, strerror(errno));
> }
>
> +/**
> + * __igt_sysfs_get_s32:
> + * @dir: directory corresponding to attribute
> + * @attr: name of the sysfs node to read
> + * @value: pointer for storing read value
> + *
> + * Convenience wrapper to read a signed 32bit integer from a sysfs file.
> + *
> + * Returns:
> + * True if value successfully read, false otherwise.
> + */
> +bool __igt_sysfs_get_s32(int dir, const char *attr, int32_t *value)
> +{
> + if (igt_debug_on(igt_sysfs_scanf(dir, attr, "%d", value) != 1))
> + return false;
> +
> + return true;
> +}
> +
> +/**
> + * igt_sysfs_get_s32:
> + * @dir: directory corresponding to attribute
> + * @attr: name of the sysfs node to read
> + *
> + * Convenience wrapper to read a signed 32bit integer from a sysfs file.
> + * It asserts on failure.
> + *
> + * Returns:
> + * Read value.
> + */
> +int32_t igt_sysfs_get_s32(int dir, const char *attr)
> +{
> + int32_t value;
> +
> + igt_assert_f(__igt_sysfs_get_s32(dir, attr, &value),
> + "Failed to read %s attribute (%s)\n", attr, strerror(errno));
> +
> + return value;
> +}
> +
> +/**
> + * __igt_sysfs_set_s32:
> + * @dir: directory corresponding to attribute
> + * @attr: name of the sysfs node to write
> + * @value: value to set
> + *
> + * Convenience wrapper to write a signed 32bit integer to a sysfs file.
> + *
> + * Returns:
> + * True if successfully written, false otherwise.
> + */
> +bool __igt_sysfs_set_s32(int dir, const char *attr, int32_t value)
> +{
> + return igt_sysfs_printf(dir, attr, "%d", value) > 0;
> +}
> +
> +/**
> + * igt_sysfs_set_s32:
> + * @dir: directory corresponding to attribute
> + * @attr: name of the sysfs node to write
> + * @value: value to set
> + *
> + * Convenience wrapper to write a signed 32bit integer to a sysfs file.
> + * It asserts on failure.
> + */
> +void igt_sysfs_set_s32(int dir, const char *attr, int32_t value)
> +{
> + igt_assert_f(__igt_sysfs_set_s32(dir, attr, value),
> + "Failed to write %d to %s attribute (%s)\n", value, attr, strerror(errno));
> +}
> +
> /**
> * __igt_sysfs_get_u64:
> * @dir: directory corresponding to attribute
> diff --git a/lib/igt_sysfs.h b/lib/igt_sysfs.h
> index 0ee253826..1bf026bed 100644
> --- a/lib/igt_sysfs.h
> +++ b/lib/igt_sysfs.h
> @@ -125,6 +125,11 @@ uint32_t igt_sysfs_get_u32(int dir, const char *attr);
> bool __igt_sysfs_set_u32(int dir, const char *attr, uint32_t value);
> void igt_sysfs_set_u32(int dir, const char *attr, uint32_t value);
>
> +bool __igt_sysfs_get_s32(int dir, const char *attr, int32_t *value);
> +int32_t igt_sysfs_get_s32(int dir, const char *attr);
> +bool __igt_sysfs_set_s32(int dir, const char *attr, int32_t value);
> +void igt_sysfs_set_s32(int dir, const char *attr, int32_t value);
> +
> bool __igt_sysfs_get_u64(int dir, const char *attr, uint64_t *value);
> uint64_t igt_sysfs_get_u64(int dir, const char *attr);
> bool __igt_sysfs_set_u64(int dir, const char *attr, uint64_t value);
> --
> 2.43.0
>
More information about the igt-dev
mailing list