Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp2657148lqp; Mon, 25 Mar 2024 05:58:02 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCW7TWahcwYIJam7jqPjxeljexhKZvzaKkKmf2xtLbu1tsKMe49Bb29e292iaEmTIzbq9UAiisSnVrTSDTJqZB8wfRdJxO6Qs8IlN4HjRw== X-Google-Smtp-Source: AGHT+IHA16cTGsiGpk03QgSAfDUQkTp6fIDR5Anp4F7wawcOb6Avpf779sUKSsFNXFC+zgGJwGmr X-Received: by 2002:a05:6214:508e:b0:696:7fc8:b841 with SMTP id kk14-20020a056214508e00b006967fc8b841mr8997076qvb.16.1711371482251; Mon, 25 Mar 2024 05:58:02 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711371482; cv=pass; d=google.com; s=arc-20160816; b=zxbv5ejiUnENK6iDI8LRWsu4/qDanyOmJjT4ysjO8yY9LDPa8gMzkbpzO2z5lXdF3c ZyKh7tveTfXPtaAV2dcf4ISFhi3tAtOwpHijtRImx48jYkby5n3E2A/rL8ZKjds6Hev2 71sFuoE4HHTdZgoox0p882FpyX7cKlA9Woc5jTqu3AfZfVszqX9cw1jimLY91Uz37UnX V1OJz66NvjN4/iDJmikjw80eydcmyu7ZDp707zIKNVN1mncp/tttGXXS9e6TzNDiqUjJ k5wRrXImlRGYhXO2LE4HpRndeymYiZsVNhfLdC13Ert6OsdLRQC5nFIAIZGLhxdWXQUS DMCw== 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=YMZkbDwnqcnID26YAN7tElYZvZq2JvdkySLlje92Vts=; fh=z/zm7tH+5sM7XgtkV4nVsbjEbNPWzYHRcJFaEJSqTw8=; b=JIMIr7qtCm2nwJOfUWrE6uBFjLcN1MMUPlILwxJaYT8uxa8B0azk6iPK+7RldmKpSl gGn4FCEUOoqNiDRCAXaJTcrO02wBIrDBb5/2o3BY1AOz+/0GQsbM1z2G/+bfT/Xpshx/ aytZmwsu6zppvnqfOFNxH2B+rqOSoWbCXdVVZL979bi3sItdUHuxVm2jUHE0gXFpsEeR aF+/whUqpmLodEP6rXDcGA0ZzazQ1vERU8mqNM6tK9mRmP1TXJylToeCgn1RjsZFX1Xa 45FEekUD+qk7yclNyvto9QVhfn6GlbdW2+e987DRADyYf+CggJ+T1tdxL9IThfwiE7/m Dwcg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=D9xG6cQ4; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-116543-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-116543-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id fv3-20020a056214240300b006969228eee3si1156952qvb.227.2024.03.25.05.58.02 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Mar 2024 05:58:02 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-116543-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=D9xG6cQ4; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-116543-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-116543-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id E55221C2D8AD for ; Mon, 25 Mar 2024 12:58:01 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 731551411CF; Mon, 25 Mar 2024 07:57:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="D9xG6cQ4" 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 EE6D754906; Mon, 25 Mar 2024 05:44:06 +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=1711345447; cv=none; b=ME1IL00WPHqWh4HB+ED1CaK2kp9uPo5WJzLU5rlrHH0+lpOscX0YzsJ/7WOEvLxgtub4KEHCV9AvkFB/TEwmdqeT/iRWy9S7DJrS3OoHDE2YWxgybxB8s1ZqEjEWUfcVIiahc3Ucsy2827FxVJ1jH1tB0jms+CK9StLKsSc1KSY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711345447; c=relaxed/simple; bh=JQLZlvK/niz9A5rF1vqEGVWJiWXrV5wGTOHqQFT/TfM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=TXWRbs0QlVvoJyE/CmK+J9zovhrudhJ3y1wEWcbSxNt7BSWdJNq2HjFqcspJ2ZduoFpBq3tQDZC3WFCqnj1mKiE5mglF8v9s/RMpKKQqfcMjcSTgQvDKk5wvrtxvs/SU4fLSeAcxj7rbpr+7tslJmAn7fUaJzQXsA5wyPISBczQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=D9xG6cQ4; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2A59DC433C7; Mon, 25 Mar 2024 05:44:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1711345446; bh=JQLZlvK/niz9A5rF1vqEGVWJiWXrV5wGTOHqQFT/TfM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=D9xG6cQ4hSOdAK1TZmWuUNztMjf3ep/9Jh6v0g2OytnLLIIdZFif3aKbqeU2A6flz WUgiN8Gd4PlYVGOD9Xy8Squz7LO9zUMh0i/agnfFvNLmOdYErXMKnc/kDQ+fXfC+oN 72s8YFoafi9GAI2YJwRYCmKlfu+FghXhWIBDPrpEpdPP+vlqHz9oYyclUMCiXysneA DBoVHdW5JCMmp92YACqH8rYLgy5E7Rj+9nPCabMdv9CpbbDKH1D1GCOZpOOABrxrDy aWl0ig3aXfLCi6juHde1uFfeP9aKTkvMRy5FG4J8RiviL9UHMh1+WYHL4RiUjfk0iK ZRwz/th8YqoTQ== 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 3/5] clk: Initialize struct clk_core kref earlier Date: Sun, 24 Mar 2024 22:44:00 -0700 Message-ID: <20240325054403.592298-4-sboyd@kernel.org> X-Mailer: git-send-email 2.44.0.396.g6e790dbe36-goog In-Reply-To: <20240325054403.592298-1-sboyd@kernel.org> References: <20240325054403.592298-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(). Cc: 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