All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/2] sysfs: add sysfs_add_bin_file_to_group()
@ 2021-12-20  6:47 Rafał Miłecki
  2021-12-20  6:47 ` [PATCH 2/2] nvmem: expose NVMEM cells in sysfs Rafał Miłecki
                   ` (5 more replies)
  0 siblings, 6 replies; 30+ messages in thread
From: Rafał Miłecki @ 2021-12-20  6:47 UTC (permalink / raw)
  To: Srinivas Kandagatla, Greg Kroah-Hartman, Rafael J . Wysocki,
	Jonathan Corbet
  Cc: Daniel Vetter, Dan Williams, Bjorn Helgaas,
	Krzysztof Wilczyński, Heiner Kallweit, linux-doc,
	linux-kernel, Rafał Miłecki

From: Rafał Miłecki <rafal@milecki.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@milecki.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


^ permalink raw reply related	[flat|nested] 30+ messages in thread

end of thread, other threads:[~2021-12-22  0:11 UTC | newest]

Thread overview: 30+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-20  6:47 [PATCH 1/2] sysfs: add sysfs_add_bin_file_to_group() Rafał Miłecki
2021-12-20  6:47 ` [PATCH 2/2] nvmem: expose NVMEM cells in sysfs Rafał Miłecki
2021-12-20  8:00   ` Greg Kroah-Hartman
2021-12-20 20:39     ` Rafał Miłecki
2021-12-21  6:33       ` Greg Kroah-Hartman
2021-12-21  6:39         ` Rafał Miłecki
2021-12-21  6:45           ` Greg Kroah-Hartman
2021-12-21  6:53             ` Rafał Miłecki
2021-12-21  7:13               ` Greg Kroah-Hartman
2021-12-21 12:24                 ` Rafał Miłecki
2021-12-21 12:56                   ` Greg Kroah-Hartman
2021-12-21 13:05                     ` Rafał Miłecki
2021-12-21 13:27                       ` Greg Kroah-Hartman
2021-12-21 13:52                         ` Rafał Miłecki
2021-12-21 14:27                           ` Greg Kroah-Hartman
2021-12-21 15:09                             ` Rafał Miłecki
2021-12-21 15:18                               ` Greg Kroah-Hartman
2021-12-21 15:33                                 ` Rafał Miłecki
2021-12-20 14:07   ` kernel test robot
2021-12-20 14:07     ` kernel test robot
2021-12-22  0:11   ` John Thomson
2021-12-20  8:01 ` [PATCH 1/2] sysfs: add sysfs_add_bin_file_to_group() Greg Kroah-Hartman
2021-12-20 14:07 ` kernel test robot
2021-12-20 14:07   ` kernel test robot
2021-12-20 14:18 ` kernel test robot
2021-12-20 14:18   ` kernel test robot
2021-12-20 20:16 ` [RFC PATCH] sysfs: __sysfs_add_file_to_group() can be static kernel test robot
2021-12-20 20:16   ` kernel test robot
2021-12-20 20:26 ` [PATCH 1/2] sysfs: add sysfs_add_bin_file_to_group() kernel test robot
2021-12-20 20:26   ` kernel test robot

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.