[Intel-gfx] [RFC PATCH i-g-t] lib/sysfs: Add support for getting boolean module parameters

Chris Wilson chris at chris-wilson.co.uk
Tue Dec 10 14:30:50 UTC 2019


Quoting Janusz Krzysztofik (2019-12-10 14:25:31)
> Boolean module parameters are exposed as "Y"/"N" strings, not 0/1.
> Make igt_sysfs_get_boolean() helper useful for getting their values.
> 
> Signed-off-by: Janusz Krzysztofik <janusz.krzysztofik at linux.intel.com>
> Cc: Chris Wilson <chris at chris-wilson.co.uk>
> ---
>  lib/igt_sysfs.c | 14 +++++++++++++-
>  1 file changed, 13 insertions(+), 1 deletion(-)
> 
> diff --git a/lib/igt_sysfs.c b/lib/igt_sysfs.c
> index c439944d..c2b8291d 100644
> --- a/lib/igt_sysfs.c
> +++ b/lib/igt_sysfs.c
> @@ -474,11 +474,23 @@ bool igt_sysfs_set_u32(int dir, const char *attr, uint32_t value)
>   */
>  bool igt_sysfs_get_boolean(int dir, const char *attr)
>  {
> +       char *buf;
>         int result;
>  
> -       if (igt_sysfs_scanf(dir, attr, "%d", &result) != 1)
> +       buf = igt_sysfs_get(dir, attr);
> +       if (!buf)
>                 return false;
>  
> +       if (sscanf(buf, "%d", &result) == 1)
> +               goto out;
> +
> +       /* kernel's param_get_bool() returns "Y"/"N" */
> +       if (!strcmp(buf, "Y"))
> +               result = true;
> +       else
> +               result = false;

result = !strcasecmp(buf, "Y");

Just for compactness?

Reviewed-by: Chris Wilson <chris at chris-wilson.co.uk>
-Chris


More information about the Intel-gfx mailing list