[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <fbc77b9b-62f1-f356-c91b-c1c9d160d9e8@bytedance.com>
Date: Tue, 23 Aug 2022 13:16:41 +0800
From: Chengming Zhou <zhouchengming@...edance.com>
To: Tejun Heo <tj@...nel.org>,
Greg Kroah-Hartman <gregkh@...uxfoundation.org>
Cc: linux-kernel@...r.kernel.org, linux-fsdevel@...r.kernel.org,
Johannes Weiner <hannes@...xchg.org>,
Imran Khan <imran.f.khan@...cle.com>, kernel-team@...com
Subject: Re: [PATCH 3/7] kernfs: Refactor kernfs_get_open_node()
On 2022/8/20 08:05, Tejun Heo wrote:
> Factor out commont part. This is cleaner and should help with future
> changes. No functional changes.
>
Reviewed-by: Chengming Zhou <zhouchengming@...edance.com>
Thanks.
> Signed-off-by: Tejun Heo <tj@...nel.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;
> }
>
Powered by blists - more mailing lists