Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp2881063lqp; Mon, 25 Mar 2024 11:51:27 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXPd1e+mVAOM/ssfRdr7Jwi2G5SZnSYhQNixJXY1u71RmDqiuZu3/B3m2aSYmRaatjttXr6/ZU9hfkDb/o3hEGPXu/iiKk9tHtVm8H7Kg== X-Google-Smtp-Source: AGHT+IFAyNPdolFEZ3xnV97tWbEz0gg6YSwva7iovPf6xkQpP9gk57HWzhkbklvC8So3vFKjNzg7 X-Received: by 2002:a17:907:72c1:b0:a4a:3b6e:1fa9 with SMTP id du1-20020a17090772c100b00a4a3b6e1fa9mr2676196ejc.15.1711392687581; Mon, 25 Mar 2024 11:51:27 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711392687; cv=pass; d=google.com; s=arc-20160816; b=evf8AVS8GbZMgO9HQjyrHVM3qxJzdSTyg50BJ44+mGnE6a4f9nqPo2XtjwO9N9ZjPS ppk1cgAt+dGxpiE0sit8ueKw0+ZWTc7uTu42sUVXh9JtmXw1WoveYgRRD428KLvJjCf9 LKEItHnSe0WLpO85LFuEQEEzkF0sLSDiPAiExfuouKBSm2dQfLhgUn26Yew6F810vG2C n0J/s0eFxvTbS3HfL9TOUvKCZSVN9hEyJLViwucFPB4AbCbISkFWHgIld9H6hJ3s1AKn +Wgy7egtFt0h1MEGQZkAdJQM7TZkS5VrYsFJDZG6h9RVTTxrSwOyYdZXDThkH0H2+10I 9aYA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=XJRpPHH9yrqkrhSdFkO0giMzeVmV4g/f9GQwy1lV6A0=; fh=z/zm7tH+5sM7XgtkV4nVsbjEbNPWzYHRcJFaEJSqTw8=; b=Cb2zsg+qgmCQ5s93QnoGb7CAIM33xV9msvedbkZWJ1LBaVjbXWPZsrn5H9FA8t4Dj/ aAVbhhTm7FvdhKDeN0QON0r+6Ada0wl3f4lC1C/S9YetDPPK4In3xKz2wEyW4YDagjl/ abwAP402ZRTPxd1L5DSFQCjsltII1dHHKHSLHW2gA93/IC7foiq9p/aBCYqZ5Uelopqx oAKnYlQYloM5lprKmzJQUai6CKZOeEaIqv0B1XG4/kBDwJFlmy9s2YUI7HaNybUOCJtD LSb0v2FbQKF9W+XPKieH/iieCvTQgvXefo2DPbvlYNOWlmAXe8SbXObk5EVXK9j5irZX rUvg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Jxx7Yn6f; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-117739-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-117739-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id p21-20020a1709060e9500b00a45efe0c97csi2678714ejf.984.2024.03.25.11.51.27 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Mar 2024 11:51:27 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-117739-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Jxx7Yn6f; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-117739-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-117739-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 4B88A1FA7438 for ; Mon, 25 Mar 2024 18:51:27 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id AF37E74C09; Mon, 25 Mar 2024 18:42:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Jxx7Yn6f" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BE61180606; Mon, 25 Mar 2024 18:42:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711392127; cv=none; b=XPJL3kTHJ1QCTanV4Ib5CCQ/hRdAtzNwp3QtAYH4lonXk5DhmyuajumDksFzYkhGveGktJbIMVQqO9wkQfKLN4QFUu0EgYRja9ejmdqSwvSFGm5KJOdQ/vW9+quG5L9rmgiiB8BoZ6HsuQoqyk9b2TJ6Ubknre7zA0Q1YmQnbuo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711392127; c=relaxed/simple; bh=onaeBFADTWFzOVhM/6B/QEw4squGRUq4bVkj4JHF800=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=I5Dp0QPFcFr4yCn/e2vgjXT3tnapJQ5ia1z9GBli7FflHxKoTz3jv1Tuo6iDQQqTZ3ObUWZtXzX6bDBaOGhQbVAMJYJRdTpVd4M78XhBmErYs5Or0Gm9y6/fWemmPgkw270PQKxGsc8WaU3YWIM3LcgdQ4cfN+kou/lV4TZ+2FQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Jxx7Yn6f; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 05BC7C43390; Mon, 25 Mar 2024 18:42:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1711392127; bh=onaeBFADTWFzOVhM/6B/QEw4squGRUq4bVkj4JHF800=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Jxx7Yn6f/cCx9ADdM8gdrESUSJzfJ5yfUPe6uOY0+pU8x1g2EGhAqSwxaTs6AtE7n qh1ytg94dDA4/hxm0hccmOF5lPivxZF3on2HRvVYDnHOhJE77hufAZXfPvqpJLQimw CmOp23v6C6qCBHhCS48us7x1XAvK9rsdKyweNzhGTmHGHs4a9/ZhzKOSw7zcjX3voY QlRg9RKIWcX3Bnw/c+A5HHWZVTsDvMbQD53MqRTRdJ8OImcBxZVaUBagi26SUKze8t tDMp65TZaUcbzho1Nx8JgWdKv3VzFoY7PjK0lGncva2yzRExn1uTHxo7nrAN8pni3+ ewTySS50JcF0A== From: Stephen Boyd To: Michael Turquette , Stephen Boyd Cc: linux-kernel@vger.kernel.org, linux-clk@vger.kernel.org, patches@lists.linux.dev, linux-arm-msm@vger.kernel.org, Douglas Anderson Subject: [PATCH v2 3/5] clk: Initialize struct clk_core kref earlier Date: Mon, 25 Mar 2024 11:41:57 -0700 Message-ID: <20240325184204.745706-4-sboyd@kernel.org> X-Mailer: git-send-email 2.44.0.396.g6e790dbe36-goog In-Reply-To: <20240325184204.745706-1-sboyd@kernel.org> References: <20240325184204.745706-1-sboyd@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Initialize this kref once we allocate memory for the struct clk_core so that we can reuse the release function to free any memory associated with the structure. This mostly consolidates code, but also clarifies that the kref lifetime exists once the container structure (struct clk_core) is allocated instead of leaving it in a half-baked state for most of __clk_core_init(). Reviewed-by: Douglas Anderson Signed-off-by: Stephen Boyd --- drivers/clk/clk.c | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c index 9fc522c26de8..ee80b21f2824 100644 --- a/drivers/clk/clk.c +++ b/drivers/clk/clk.c @@ -3959,8 +3959,6 @@ static int __clk_core_init(struct clk_core *core) } clk_core_reparent_orphans_nolock(); - - kref_init(&core->ref); out: clk_pm_runtime_put(core); unlock: @@ -4189,6 +4187,16 @@ static void clk_core_free_parent_map(struct clk_core *core) kfree(core->parents); } +/* Free memory allocated for a struct clk_core */ +static void __clk_release(struct kref *ref) +{ + struct clk_core *core = container_of(ref, struct clk_core, ref); + + clk_core_free_parent_map(core); + kfree_const(core->name); + kfree(core); +} + static struct clk * __clk_register(struct device *dev, struct device_node *np, struct clk_hw *hw) { @@ -4209,6 +4217,8 @@ __clk_register(struct device *dev, struct device_node *np, struct clk_hw *hw) goto fail_out; } + kref_init(&core->ref); + core->name = kstrdup_const(init->name, GFP_KERNEL); if (!core->name) { ret = -ENOMEM; @@ -4263,12 +4273,10 @@ __clk_register(struct device *dev, struct device_node *np, struct clk_hw *hw) hw->clk = NULL; fail_create_clk: - clk_core_free_parent_map(core); fail_parents: fail_ops: - kfree_const(core->name); fail_name: - kfree(core); + kref_put(&core->ref, __clk_release); fail_out: return ERR_PTR(ret); } @@ -4348,16 +4356,6 @@ int of_clk_hw_register(struct device_node *node, struct clk_hw *hw) } EXPORT_SYMBOL_GPL(of_clk_hw_register); -/* Free memory allocated for a clock. */ -static void __clk_release(struct kref *ref) -{ - struct clk_core *core = container_of(ref, struct clk_core, ref); - - clk_core_free_parent_map(core); - kfree_const(core->name); - kfree(core); -} - /* * Empty clk_ops for unregistered clocks. These are used temporarily * after clk_unregister() was called on a clock and until last clock -- https://git.kernel.org/pub/scm/linux/kernel/git/clk/linux.git/ https://git.kernel.org/pub/scm/linux/kernel/git/sboyd/spmi.git