[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <20211220064730.28806-1-zajec5@gmail.com>
Date: Mon, 20 Dec 2021 07:47:29 +0100
From: Rafał Miłecki <zajec5@...il.com>
To: Srinivas Kandagatla <srinivas.kandagatla@...aro.org>,
Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
"Rafael J . Wysocki" <rafael@...nel.org>,
Jonathan Corbet <corbet@....net>
Cc: Daniel Vetter <daniel.vetter@...ll.ch>,
Dan Williams <dan.j.williams@...el.com>,
Bjorn Helgaas <bhelgaas@...gle.com>,
Krzysztof Wilczyński <kw@...ux.com>,
Heiner Kallweit <hkallweit1@...il.com>,
linux-doc@...r.kernel.org, linux-kernel@...r.kernel.org,
Rafał Miłecki <rafal@...ecki.pl>
Subject: [PATCH 1/2] sysfs: add sysfs_add_bin_file_to_group()
From: Rafał Miłecki <rafal@...ecki.pl>
There already is sysfs_add_file_to_group() for adding "attribute" to a
group. This new function allows adding "bin_attribute" as well.
Signed-off-by: Rafał Miłecki <rafal@...ecki.pl>
---
fs/sysfs/file.c | 31 +++++++++++++++++++++++++++----
include/linux/sysfs.h | 3 +++
2 files changed, 30 insertions(+), 4 deletions(-)
diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c
index 42dcf96881b6..30c798c38d89 100644
--- a/fs/sysfs/file.c
+++ b/fs/sysfs/file.c
@@ -376,14 +376,19 @@ EXPORT_SYMBOL_GPL(sysfs_create_files);
* @attr: attribute descriptor.
* @group: group name.
*/
-int sysfs_add_file_to_group(struct kobject *kobj,
- const struct attribute *attr, const char *group)
+int __sysfs_add_file_to_group(struct kobject *kobj,
+ const struct attribute *attr,
+ const struct bin_attribute *battr,
+ const char *group)
{
struct kernfs_node *parent;
kuid_t uid;
kgid_t gid;
int error;
+ if (WARN_ON((attr && battr) || (!attr && !battr)))
+ return -EINVAL;
+
if (group) {
parent = kernfs_find_and_get(kobj->sd, group);
} else {
@@ -395,14 +400,32 @@ int sysfs_add_file_to_group(struct kobject *kobj,
return -ENOENT;
kobject_get_ownership(kobj, &uid, &gid);
- error = sysfs_add_file_mode_ns(parent, attr, attr->mode, uid, gid,
- NULL);
+ if (attr)
+ error = sysfs_add_file_mode_ns(parent, attr, attr->mode, uid,
+ gid, NULL);
+ else
+ error = sysfs_add_bin_file_mode_ns(parent, battr, battr->attr.mode,
+ uid, gid, NULL);
kernfs_put(parent);
return error;
}
+
+int sysfs_add_file_to_group(struct kobject *kobj, const struct attribute *attr,
+ const char *group)
+{
+ return __sysfs_add_file_to_group(kobj, attr, NULL, group);
+}
EXPORT_SYMBOL_GPL(sysfs_add_file_to_group);
+int sysfs_add_bin_file_to_group(struct kobject *kobj,
+ const struct bin_attribute *battr,
+ const char *group)
+{
+ return __sysfs_add_file_to_group(kobj, NULL, battr, group);
+}
+EXPORT_SYMBOL_GPL(sysfs_add_bin_file_to_group);
+
/**
* sysfs_chmod_file - update the modified mode value on an object attribute.
* @kobj: object we're acting for.
diff --git a/include/linux/sysfs.h b/include/linux/sysfs.h
index e3f1e8ac1f85..9b4f9d405604 100644
--- a/include/linux/sysfs.h
+++ b/include/linux/sysfs.h
@@ -302,6 +302,9 @@ void sysfs_remove_groups(struct kobject *kobj,
const struct attribute_group **groups);
int sysfs_add_file_to_group(struct kobject *kobj,
const struct attribute *attr, const char *group);
+int sysfs_add_bin_file_to_group(struct kobject *kobj,
+ const struct bin_attribute *battr,
+ const char *group);
void sysfs_remove_file_from_group(struct kobject *kobj,
const struct attribute *attr, const char *group);
int sysfs_merge_group(struct kobject *kobj,
--
2.31.1
Powered by blists - more mailing lists