summaryrefslogtreecommitdiffstats
path: root/fs/sysfs
diff options
context:
space:
mode:
authorChristoph Hellwig <hch@lst.de>2021-09-13 07:41:13 +0200
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2021-09-14 17:02:58 +0200
commitd1a1a9606e080c9767e229742f5b331b3b551c0c (patch)
treed48e9326214e3cf0049a6e478dff3f05832aa2f1 /fs/sysfs
parentsysfs: split out binary attribute handling from sysfs_add_file_mode_ns (diff)
downloadlinux-d1a1a9606e080c9767e229742f5b331b3b551c0c.tar.xz
linux-d1a1a9606e080c9767e229742f5b331b3b551c0c.zip
sysfs: refactor sysfs_add_file_mode_ns
Regroup the code so that preallocated attributes and normal attributes are handled in clearly separate blocks. Acked-by: Christian Brauner <christian.brauner@ubuntu.com> Acked-by: Tejun Heo <tj@kernel.org> Signed-off-by: Christoph Hellwig <hch@lst.de> Link: https://lore.kernel.org/r/20210913054121.616001-6-hch@lst.de Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'fs/sysfs')
-rw-r--r--fs/sysfs/file.c27
1 files changed, 14 insertions, 13 deletions
diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c
index f737bd61f71b..74a2a8021c8b 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