[PATCH v2 4/7] powerpc/secvar: Handle format string in the consumer

Andrew Donnellan ajd at linux.ibm.com
Wed Jan 4 18:31:08 AEDT 2023


On Fri, 2022-12-30 at 15:20 +1100, Russell Currey wrote:
> The code that handles the format string in secvar-sysfs.c is entirely
> OPAL specific, so create a new "format" op in secvar_operations to
> make
> the secvar code more generic.  No functional change.
> 
> Signed-off-by: Russell Currey <ruscur at russell.cc>

LGTM

Reviewed-by: Andrew Donnellan <ajd at linux.ibm.com>

> ---
>  arch/powerpc/include/asm/secvar.h            |  1 +
>  arch/powerpc/kernel/secvar-sysfs.c           | 21 +---------------
>  arch/powerpc/platforms/powernv/opal-secvar.c | 25
> ++++++++++++++++++++
>  3 files changed, 27 insertions(+), 20 deletions(-)
> 
> diff --git a/arch/powerpc/include/asm/secvar.h
> b/arch/powerpc/include/asm/secvar.h
> index 4cc35b58b986..3b7e5a3625bd 100644
> --- a/arch/powerpc/include/asm/secvar.h
> +++ b/arch/powerpc/include/asm/secvar.h
> @@ -20,6 +20,7 @@ struct secvar_operations {
>                         uint64_t keybufsize);
>         int (*set)(const char *key, uint64_t key_len, u8 *data,
>                    uint64_t data_size);
> +       ssize_t (*format)(char *buf);
>  };
>  
>  #ifdef CONFIG_PPC_SECURE_BOOT
> diff --git a/arch/powerpc/kernel/secvar-sysfs.c
> b/arch/powerpc/kernel/secvar-sysfs.c
> index 02e9fee1552e..190238f51335 100644
> --- a/arch/powerpc/kernel/secvar-sysfs.c
> +++ b/arch/powerpc/kernel/secvar-sysfs.c
> @@ -21,26 +21,7 @@ static struct kset *secvar_kset;
>  static ssize_t format_show(struct kobject *kobj, struct
> kobj_attribute *attr,
>                            char *buf)
>  {
> -       ssize_t rc = 0;
> -       struct device_node *node;
> -       const char *format;
> -
> -       node = of_find_compatible_node(NULL, NULL, "ibm,secvar-
> backend");
> -       if (!of_device_is_available(node)) {
> -               rc = -ENODEV;
> -               goto out;
> -       }
> -
> -       rc = of_property_read_string(node, "format", &format);
> -       if (rc)
> -               goto out;
> -
> -       rc = sysfs_emit(buf, "%s\n", format);
> -
> -out:
> -       of_node_put(node);
> -
> -       return rc;
> +       return secvar_ops->format(buf);
>  }
>  
>  
> diff --git a/arch/powerpc/platforms/powernv/opal-secvar.c
> b/arch/powerpc/platforms/powernv/opal-secvar.c
> index 14133e120bdd..5e9de06b2533 100644
> --- a/arch/powerpc/platforms/powernv/opal-secvar.c
> +++ b/arch/powerpc/platforms/powernv/opal-secvar.c
> @@ -101,10 +101,35 @@ static int opal_set_variable(const char *key,
> uint64_t ksize, u8 *data,
>         return opal_status_to_err(rc);
>  }
>  
> +static ssize_t opal_secvar_format(char *buf)
> +{
> +       ssize_t rc = 0;
> +       struct device_node *node;
> +       const char *format;
> +
> +       node = of_find_compatible_node(NULL, NULL, "ibm,secvar-
> backend");
> +       if (!of_device_is_available(node)) {
> +               rc = -ENODEV;
> +               goto out;
> +       }
> +
> +       rc = of_property_read_string(node, "format", &format);
> +       if (rc)
> +               goto out;
> +
> +       rc = sysfs_emit(buf, "%s\n", format);
> +
> +out:
> +       of_node_put(node);
> +
> +       return rc;
> +}
> +
>  static const struct secvar_operations opal_secvar_ops = {
>         .get = opal_get_variable,
>         .get_next = opal_get_next_variable,
>         .set = opal_set_variable,
> +       .format = opal_secvar_format,
>  };
>  
>  static int opal_secvar_probe(struct platform_device *pdev)

-- 
Andrew Donnellan    OzLabs, ADL Canberra
ajd at linux.ibm.com   IBM Australia Limited


More information about the Linuxppc-dev mailing list