From: Tejun Heo <tj@kernel.org>
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org,
Chengming Zhou <zhouchengming@bytedance.com>,
Johannes Weiner <hannes@cmpxchg.org>,
Imran Khan <imran.f.khan@oracle.com>,
kernel-team@fb.com, Tejun Heo <tj@kernel.org>
Subject: [PATCH 3/7] kernfs: Refactor kernfs_get_open_node()
Date: Fri, 19 Aug 2022 14:05:47 -1000 [thread overview]
Message-ID: <20220820000550.367085-4-tj@kernel.org> (raw)
In-Reply-To: <20220820000550.367085-1-tj@kernel.org>
Factor out commont part. This is cleaner and should help with future
changes. No functional changes.
Signed-off-by: Tejun Heo <tj@kernel.org>
---
fs/kernfs/file.c | 25 +++++++++++--------------
1 file changed, 11 insertions(+), 14 deletions(-)
diff --git a/fs/kernfs/file.c b/fs/kernfs/file.c
index 6437f7c7162d..7060a2a714b8 100644
--- a/fs/kernfs/file.c
+++ b/fs/kernfs/file.c
@@ -554,31 +554,28 @@ static int kernfs_fop_mmap(struct file *file, struct vm_area_struct *vma)
static int kernfs_get_open_node(struct kernfs_node *kn,
struct kernfs_open_file *of)
{
- struct kernfs_open_node *on, *new_on = NULL;
+ struct kernfs_open_node *on;
struct mutex *mutex;
mutex = kernfs_open_file_mutex_lock(kn);
on = kernfs_deref_open_node_locked(kn);
- if (on) {
- list_add_tail(&of->list, &on->files);
- mutex_unlock(mutex);
- return 0;
- } else {
+ if (!on) {
/* not there, initialize a new one */
- new_on = kmalloc(sizeof(*new_on), GFP_KERNEL);
- if (!new_on) {
+ on = kmalloc(sizeof(*on), GFP_KERNEL);
+ if (!on) {
mutex_unlock(mutex);
return -ENOMEM;
}
- atomic_set(&new_on->event, 1);
- init_waitqueue_head(&new_on->poll);
- INIT_LIST_HEAD(&new_on->files);
- list_add_tail(&of->list, &new_on->files);
- rcu_assign_pointer(kn->attr.open, new_on);
+ atomic_set(&on->event, 1);
+ init_waitqueue_head(&on->poll);
+ INIT_LIST_HEAD(&on->files);
+ rcu_assign_pointer(kn->attr.open, on);
}
- mutex_unlock(mutex);
+ list_add_tail(&of->list, &on->files);
+
+ mutex_unlock(mutex);
return 0;
}
--
2.37.2
next prev parent reply other threads:[~2022-08-20 0:06 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-08-20 0:05 [PATCHSET for-6.1] kernfs, cgroup: implement kernfs_deactivate() and cgroup_file_show() Tejun Heo
2022-08-20 0:05 ` [PATCH 1/7] kernfs: Simply by replacing kernfs_deref_open_node() with of_on() Tejun Heo
2022-08-23 5:15 ` Chengming Zhou
2022-08-20 0:05 ` [PATCH 2/7] kernfs: Drop unnecessary "mutex" local variable initialization Tejun Heo
2022-08-23 5:15 ` Chengming Zhou
2022-08-20 0:05 ` Tejun Heo [this message]
2022-08-23 5:16 ` [PATCH 3/7] kernfs: Refactor kernfs_get_open_node() Chengming Zhou
2022-08-20 0:05 ` [PATCH 4/7] kernfs: Skip kernfs_drain_open_files() more aggressively Tejun Heo
2022-08-23 5:27 ` Chengming Zhou
2022-08-23 19:37 ` Tejun Heo
2022-08-25 12:11 ` Chengming Zhou
2022-08-20 0:05 ` [PATCH 5/7] kernfs: Make kernfs_drain() skip draining " Tejun Heo
2022-08-23 5:33 ` Chengming Zhou
2022-08-20 0:05 ` [PATCH 6/7] kernfs: Allow kernfs nodes to be deactivated and re-activated Tejun Heo
2022-08-23 5:49 ` Chengming Zhou
2022-08-23 20:31 ` Tejun Heo
2022-08-20 0:05 ` [PATCH 7/7] cgroup: Implement cgroup_file_show() Tejun Heo
2022-08-22 1:58 ` [PATCHSET for-6.1] kernfs, cgroup: implement kernfs_deactivate() and cgroup_file_show() Chengming Zhou
2022-08-22 7:10 ` Tejun Heo
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220820000550.367085-4-tj@kernel.org \
--to=tj@kernel.org \
--cc=gregkh@linuxfoundation.org \
--cc=hannes@cmpxchg.org \
--cc=imran.f.khan@oracle.com \
--cc=kernel-team@fb.com \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=zhouchengming@bytedance.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.