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 E5300ECAAA1 for ; Fri, 9 Sep 2022 14:02:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232281AbiIIOCL (ORCPT ); Fri, 9 Sep 2022 10:02:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59394 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232008AbiIIOAu (ORCPT ); Fri, 9 Sep 2022 10:00:50 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0681E9C1F3; Fri, 9 Sep 2022 07:00:34 -0700 (PDT) Date: Fri, 09 Sep 2022 14:00:32 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1662732033; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=hEpyJ2r2amdD8/iRLSJ/2K1z7jt/4JkPUQg3wp/Hemc=; b=ycJQgQkvE/cN/sGzkFgJ30b+7MualZxD53+GOnrA9Im+AIItvUuGfy95MVX/9NnhI0N0EW Wa9SYS3woBCt1Q0IaeKPaeemd7Qb/qUiGSXELnkH0pBenMHaXJZGDuHy9M6nA8hTogx+Iv NoY0CZnn7+fOTzfWdO4oPrPksYk2Kh8h72VaunU3zdhBZwPaQda8bP8PZzFYTKA9sRILUX zR8Le/Zj1/LrMLpYKbef4ZuvhkH/ZcybOS9PoNxNcG1+1JmWLM2nFzuCGWDxtG8e7uGNjL v+/HmHH7ERiy4MdU+v/XBEo8bZDq0bcNs2QFUwlQsvGzfRiQ/vuan3OD96xUuQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1662732033; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=hEpyJ2r2amdD8/iRLSJ/2K1z7jt/4JkPUQg3wp/Hemc=; b=bqwYxIJ61E3gV50tVfh5R7SvT+3ptRNgC0NQBvu1a0taTw85vVXgS5xvqmjt+pxKdNVul8 ft1gexTt3AA1GDAg== From: "tip-bot2 for Tejun Heo" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: sched/psi] kernfs: Refactor kernfs_get_open_node() Cc: Chengming Zhou , Tejun Heo , "Greg Kroah-Hartman" , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20220828050440.734579-4-tj@kernel.org> References: <20220828050440.734579-4-tj@kernel.org> MIME-Version: 1.0 Message-ID: <166273203218.401.16764817230191009830.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The following commit has been merged into the sched/psi branch of tip: Commit-ID: cf2dc9db93704c24f3d6d87d3bd09ae970446d1f Gitweb: https://git.kernel.org/tip/cf2dc9db93704c24f3d6d87d3bd09ae970446d1f Author: Tejun Heo AuthorDate: Sat, 27 Aug 2022 19:04:34 -10:00 Committer: Greg Kroah-Hartman CommitterDate: Thu, 01 Sep 2022 18:08:44 +02:00 kernfs: Refactor kernfs_get_open_node() Factor out commont part. This is cleaner and should help with future changes. No functional changes. Tested-by: Chengming Zhou Reviewed-by: Chengming Zhou Signed-off-by: Tejun Heo Link: https://lore.kernel.org/r/20220828050440.734579-4-tj@kernel.org Signed-off-by: Greg Kroah-Hartman --- 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 6437f7c..7060a2a 100644 --- a/fs/kernfs/file.c +++ b/fs/kernfs/file.c @@ -554,31 +554,28 @@ out_unlock: 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; }