Streamline the sysfs generation to make it more extensible.
Add a function to create a sysfs entry in the uv-sysfs dir.
Use this function for the query directory.
Reviewed-by: Janosch Frank <frankja@linux.ibm.com>
Reviewed-by: Christoph Schlameuss <schlameuss@linux.ibm.com>
Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
---
arch/s390/kernel/uv.c | 34 ++++++++++++++++++++++++----------
1 file changed, 24 insertions(+), 10 deletions(-)
diff --git a/arch/s390/kernel/uv.c b/arch/s390/kernel/uv.c
index 9646f773208a..901e852f858b 100644
--- a/arch/s390/kernel/uv.c
+++ b/arch/s390/kernel/uv.c
@@ -753,7 +753,26 @@ static const struct attribute *uv_prot_virt_attrs[] = {
static struct kset *uv_query_kset;
static struct kobject *uv_kobj;
-static int __init uv_info_init(void)
+static int __init uv_sysfs_dir_init(const struct attribute_group *grp,
+ struct kset **uv_dir_kset, const char *name)
+{
+ struct kset *kset;
+ int rc = -ENOMEM;
+
+ kset = kset_create_and_add(name, NULL, uv_kobj);
+ if (!kset)
+ return -ENOMEM;
+ *uv_dir_kset = kset;
+
+ rc = sysfs_create_group(&kset->kobj, grp);
+ if (!rc)
+ return 0;
+
+ kset_unregister(kset);
+ return rc;
+}
+
+static int __init uv_sysfs_init(void)
{
int rc = -ENOMEM;
@@ -768,17 +787,12 @@ static int __init uv_info_init(void)
if (rc)
goto out_kobj;
- uv_query_kset = kset_create_and_add("query", NULL, uv_kobj);
- if (!uv_query_kset) {
- rc = -ENOMEM;
+ rc = uv_sysfs_dir_init(&uv_query_attr_group, &uv_query_kset, "query");
+ if (rc)
goto out_ind_files;
- }
- rc = sysfs_create_group(&uv_query_kset->kobj, &uv_query_attr_group);
- if (!rc)
- return 0;
+ return 0;
- kset_unregister(uv_query_kset);
out_ind_files:
sysfs_remove_files(uv_kobj, uv_prot_virt_attrs);
out_kobj:
@@ -786,4 +800,4 @@ static int __init uv_info_init(void)
kobject_put(uv_kobj);
return rc;
}
-device_initcall(uv_info_init);
+device_initcall(uv_sysfs_init);
--
2.43.0
On Wed, Oct 02, 2024 at 06:04:17PM +0200, Steffen Eiden wrote: > Streamline the sysfs generation to make it more extensible. > Add a function to create a sysfs entry in the uv-sysfs dir. > Use this function for the query directory. > > Reviewed-by: Janosch Frank <frankja@linux.ibm.com> > Reviewed-by: Christoph Schlameuss <schlameuss@linux.ibm.com> > Signed-off-by: Steffen Eiden <seiden@linux.ibm.com> > --- > arch/s390/kernel/uv.c | 34 ++++++++++++++++++++++++---------- > 1 file changed, 24 insertions(+), 10 deletions(-) ... > -static int __init uv_info_init(void) > +static int __init uv_sysfs_dir_init(const struct attribute_group *grp, > + struct kset **uv_dir_kset, const char *name) > +{ > + struct kset *kset; > + int rc = -ENOMEM; rc is unnecessarily preinitialized, so you can wait for a cleanup patch from some bot. > + kset = kset_create_and_add(name, NULL, uv_kobj); > + if (!kset) > + return -ENOMEM; > + *uv_dir_kset = kset; > + > + rc = sysfs_create_group(&kset->kobj, grp); > + if (!rc) > + return 0; > + > + kset_unregister(kset); > + return rc; doing it like rc = sysfs_create_group(&kset->kobj, grp); if (rc) kset_unregister(kset); return rc; is shorter ;)
© 2016 - 2024 Red Hat, Inc.