[PATCH -next 3/3] configfs: Add subsys_to_item helper

From: Shang XiaoJing
Date: Fri Sep 09 2022 - 02:21:51 EST


Add helper function subsys_to_item, which get the corresponding
config_item of the configfs_subsystem.

Signed-off-by: Shang XiaoJing <shangxiaojing@xxxxxxxxxx>
---
fs/configfs/dir.c | 22 ++++++++++++++--------
1 file changed, 14 insertions(+), 8 deletions(-)

diff --git a/fs/configfs/dir.c b/fs/configfs/dir.c
index b5614b66add2..e4386eab3428 100644
--- a/fs/configfs/dir.c
+++ b/fs/configfs/dir.c
@@ -281,7 +281,7 @@ static void configfs_remove_dirent(struct dentry *dentry)

/**
* configfs_create_dir - create a directory for an config_item.
- * @item: config_itemwe're creating directory for.
+ * @item: config_item we're creating directory for.
* @dentry: config_item's dentry.
* @frag: config_item's fragment.
*
@@ -616,6 +616,12 @@ static inline struct dentry *group_to_dentry(struct config_group *group)
return group->cg_item.ci_dentry;
}

+static inline
+struct config_item *subsys_to_item(struct configfs_subsystem *subsys)
+{
+ return &subsys->su_group.cg_item;
+}
+
static int configfs_attach_group(struct config_item *parent_item,
struct config_item *item,
struct dentry *dentry,
@@ -1119,7 +1125,7 @@ int configfs_depend_item(struct configfs_subsystem *subsys,
{
int ret;
struct configfs_dirent *subsys_sd;
- struct config_item *s_item = &subsys->su_group.cg_item;
+ struct config_item *s_item = subsys_to_item(subsys);
struct dentry *root;

/*
@@ -1238,11 +1244,11 @@ int configfs_depend_item_unlocked(struct configfs_subsystem *caller_subsys,
*/
subsys_sd = configfs_find_subsys_dentry(
group_to_dentry(root)->d_fsdata,
- &target_subsys->su_group.cg_item);
+ subsys_to_item(target_subsys));
if (!subsys_sd)
goto out_root_unlock;
} else {
- subsys_sd = target_subsys->su_group.cg_item.ci_dentry->d_fsdata;
+ subsys_sd = subsys_to_item(target_subsys)->ci_dentry->d_fsdata;
}

/* Now we can execute core of depend item */
@@ -1315,11 +1321,11 @@ static int configfs_mkdir(struct user_namespace *mnt_userns, struct inode *dir,
* being created. We don't want to safely pin the new item but
* fail to pin the subsystem it sits under.
*/
- if (!subsys->su_group.cg_item.ci_type) {
+ if (!subsys_to_item(subsys)->ci_type) {
ret = -EINVAL;
goto out_put;
}
- subsys_owner = subsys->su_group.cg_item.ci_type->ct_owner;
+ subsys_owner = subsys_to_item(subsys)->ci_type->ct_owner;
if (!try_module_get(subsys_owner)) {
ret = -EINVAL;
goto out_put;
@@ -1469,8 +1475,8 @@ static int configfs_rmdir(struct inode *dir, struct dentry *dentry)
}

/* configfs_mkdir() shouldn't have allowed this */
- BUG_ON(!subsys->su_group.cg_item.ci_type);
- subsys_owner = subsys->su_group.cg_item.ci_type->ct_owner;
+ BUG_ON(!subsys_to_item(subsys)->ci_type);
+ subsys_owner = subsys_to_item(subsys)->ci_type->ct_owner;

/*
* Ensure that no racing symlink() will make detach_prep() fail while
--
2.17.1