From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 09F38C25B08 for ; Tue, 23 Aug 2022 05:16:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234268AbiHWFQx (ORCPT ); Tue, 23 Aug 2022 01:16:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47124 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236060AbiHWFQu (ORCPT ); Tue, 23 Aug 2022 01:16:50 -0400 Received: from mail-pg1-x52e.google.com (mail-pg1-x52e.google.com [IPv6:2607:f8b0:4864:20::52e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 09D684B498 for ; Mon, 22 Aug 2022 22:16:49 -0700 (PDT) Received: by mail-pg1-x52e.google.com with SMTP id r22so11324377pgm.5 for ; Mon, 22 Aug 2022 22:16:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc; bh=fqQOcGIshToSvQyhg21sF8soYRf73aWYmaMl0SScXX8=; b=jfAymrwMpKfjsZ+XaXEKdwl6twDtg/hmhvKq1Jir4CguTo3+TfH+1q4m+0tTFqVfk1 njDDmUkQbPUgvXU1VLRs70Sj5X7h1E/GnVisiwT7DqwwcvnxOtNEvmOBBfN6lPk3XM3E S6jYGKcooxt81Gk6YGjM1YwA+L3UNoPgDjv4f1YfpZaqZC+QY9Yp7B6+UtZZJDzZOLBZ uXvnQBriHipFKg/xJ9P8RhtQP+S98duAOVQaE/vn0Bi2Hv8COyXH6dsGSAoU+1d8sCIc 1BrZ/p8oznLbtst0agaOqQidANETSRFUXk4TZL+0BF64rqg8xN15lNwEglB6lMGVa53y 1EYg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc; bh=fqQOcGIshToSvQyhg21sF8soYRf73aWYmaMl0SScXX8=; b=aJAL0jdwuwoPiWDwPfD5Ni99Ue4NYyq6KPr8iPdpjRaZGFSypTJluhP57czTPkf8py Y3qlwIUHbDegU2jvGx/slr0es6X411ByKItLZuuJeCJRHtbSuHM6IR/HGO+j2v18hPBj 3bX7oHqx26l8DuYmMQt6j8gpuEkO2uJgYYtNQHKSxUvf1eKC49CUuXBW7/5qTNesNSmF 7WQ549A2yysJqaShonZp/UEvApn7yfCgfhEmCtDOxhBnuVEQ8jOq+tTYYR63KXzyVmh4 uBOH900V/fpUvoKiWOCrpyPf/VbY5x+7pMggJKCXlCv1puYjBp70ZKR0n0c73A4WtGOe wYgw== X-Gm-Message-State: ACgBeo0uSpshqqvCljR+vj8rVpO93g2VbnCMdtlBBDZ8DHf0rTBA83qI FVg4QzKvi35N8YTTGhUNzo7rrw== X-Google-Smtp-Source: AA6agR4raQSAdD2MaqXbzBs6ck8VUdeRq4+xUzKmuW8KZKX/8ROBPIxYPkeEa+Q2H+QORYNELjEXjQ== X-Received: by 2002:a63:43c7:0:b0:429:7abb:aaf7 with SMTP id q190-20020a6343c7000000b004297abbaaf7mr19189184pga.204.1661231808443; Mon, 22 Aug 2022 22:16:48 -0700 (PDT) Received: from [10.4.208.12] ([139.177.225.228]) by smtp.gmail.com with ESMTPSA id d9-20020a170902cec900b00172973d3cd9sm9419880plg.55.2022.08.22.22.16.45 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 22 Aug 2022 22:16:48 -0700 (PDT) Message-ID: Date: Tue, 23 Aug 2022 13:16:41 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Thunderbird/102.1.2 Subject: Re: [PATCH 3/7] kernfs: Refactor kernfs_get_open_node() Content-Language: en-US To: Tejun Heo , Greg Kroah-Hartman Cc: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, Johannes Weiner , Imran Khan , kernel-team@fb.com References: <20220820000550.367085-1-tj@kernel.org> <20220820000550.367085-4-tj@kernel.org> From: Chengming Zhou In-Reply-To: <20220820000550.367085-4-tj@kernel.org> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 Thanks. > Signed-off-by: Tejun Heo > --- > 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; > } >