powerpc/secvar: Handle format string in the consumer

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@russell.cc>
Signed-off-by: Andrew Donnellan <ajd@linux.ibm.com>
Reviewed-by: Stefan Berger <stefanb@linux.ibm.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Link: https://lore.kernel.org/r/20230210080401.345462-8-ajd@linux.ibm.com
This commit is contained in:
Russell Currey
2023-02-10 19:03:42 +11:00
committed by Michael Ellerman
parent 16943a2faf
commit ec2f40bd00
3 changed files with 35 additions and 18 deletions

View File

@@ -21,26 +21,17 @@ 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;
char tmp[32];
ssize_t len = secvar_ops->format(tmp, sizeof(tmp));
node = of_find_compatible_node(NULL, NULL, "ibm,secvar-backend");
if (!of_device_is_available(node)) {
rc = -ENODEV;
goto out;
}
if (len > 0)
return sysfs_emit(buf, "%s\n", tmp);
else if (len < 0)
pr_err("Error %zd reading format string\n", len);
else
pr_err("Got empty format string from backend\n");
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 -EIO;
}