diff mbox series

[05/13] sysfs: refactor sysfs_add_file_mode_ns

Message ID 20210913054121.616001-6-hch@lst.de (mailing list archive)
State New, archived
Headers show
Series [01/13] seq_file: mark seq_get_buf as deprecated | expand

Commit Message

Christoph Hellwig Sept. 13, 2021, 5:41 a.m. UTC
Regroup the code so that preallocated attributes and normal attributes are
handled in clearly separate blocks.

Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 fs/sysfs/file.c | 27 ++++++++++++++-------------
 1 file changed, 14 insertions(+), 13 deletions(-)

Comments

Christian Brauner Sept. 13, 2021, 1:27 p.m. UTC | #1
On Mon, Sep 13, 2021 at 07:41:13AM +0200, Christoph Hellwig wrote:
> Regroup the code so that preallocated attributes and normal attributes are
> handled in clearly separate blocks.
> 
> Signed-off-by: Christoph Hellwig <hch@lst.de>
> ---

Acked-by: Christian Brauner <christian.brauner@ubuntu.com>
diff mbox series

Patch

diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c
index f737bd61f71bf..74a2a8021c8bb 100644
--- a/fs/sysfs/file.c
+++ b/fs/sysfs/file.c
@@ -261,7 +261,7 @@  int sysfs_add_file_mode_ns(struct kernfs_node *parent,
 	struct kobject *kobj = parent->priv;
 	const struct sysfs_ops *sysfs_ops = kobj->ktype->sysfs_ops;
 	struct lock_class_key *key = NULL;
-	const struct kernfs_ops *ops;
+	const struct kernfs_ops *ops = NULL;
 	struct kernfs_node *kn;
 
 	/* every kobject with an attribute needs a ktype assigned */
@@ -270,22 +270,23 @@  int sysfs_add_file_mode_ns(struct kernfs_node *parent,
 			kobject_name(kobj)))
 		return -EINVAL;
 
-	if (sysfs_ops->show && sysfs_ops->store) {
-		if (mode & SYSFS_PREALLOC)
+	if (mode & SYSFS_PREALLOC) {
+		if (sysfs_ops->show && sysfs_ops->store)
 			ops = &sysfs_prealloc_kfops_rw;
-		else
-			ops = &sysfs_file_kfops_rw;
-	} else if (sysfs_ops->show) {
-		if (mode & SYSFS_PREALLOC)
+		else if (sysfs_ops->show)
 			ops = &sysfs_prealloc_kfops_ro;
-		else
-			ops = &sysfs_file_kfops_ro;
-	} else if (sysfs_ops->store) {
-		if (mode & SYSFS_PREALLOC)
+		else if (sysfs_ops->store)
 			ops = &sysfs_prealloc_kfops_wo;
-		else
+	} else {
+		if (sysfs_ops->show && sysfs_ops->store)
+			ops = &sysfs_file_kfops_rw;
+		else if (sysfs_ops->show)
+			ops = &sysfs_file_kfops_ro;
+		else if (sysfs_ops->store)
 			ops = &sysfs_file_kfops_wo;
-	} else
+	}
+
+	if (!ops)
 		ops = &sysfs_file_kfops_empty;
 
 #ifdef CONFIG_DEBUG_LOCK_ALLOC