Received: from smtp3.osuosl.org (smtp3.osuosl.org [140.211.166.136]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AAB48606A31A for ; Wed, 2 Dec 2026 10:27:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=lists.u-boot-project.org header.i=@lists.u-boot-project.org header.a=rsa-sha256 header.s=default header.b=LjoTpG2s; dkim=pass (1024-bit key) header.d=amarulasolutions.com header.i=@amarulasolutions.com header.a=rsa-sha256 header.s=google header.b=l1smOV9q Received: from localhost (localhost [127.0.0.1]) by smtp3.osuosl.org (Postfix) with ESMTP id 84E33606F0; Wed, 2 Dec 2026 10:27:36 +0000 (UTC) X-Virus-Scanned: amavis at osuosl.org Received: from smtp3.osuosl.org ([127.0.0.1]) by localhost (smtp3.osuosl.org [127.0.0.1]) (amavis, port 10024) with ESMTP id YM7_1dnevLub; Wed, 2 Dec 2026 10:27:36 +0000 (UTC) ARC-Filter: OpenARC Filter v1.3.2 smtp3.osuosl.org BB863606F5 Authentication-Results: smtp3.osuosl.org; arc=none smtp.remote-ip=140.211.166.142 ARC-Seal: i=1; d=osuosl.org; s=arc; a=rsa-sha256; cv=none; t=1796207255; b=hanKX8TDx/LRQEFYJ1X/DWx5LhuVMRDSkU+psdRuNgBZoln3kR5Byrj5pHlGjMJ5YJXs sMHB0aiThhHtVjkkiQAt/UvV+/5uqJ1uAZKjdRYIiCeIB47mxS+ZjyczRE3yFqDf7JLRP lQuworM4N45EE8hrdQbLgQpFZf5ep4P1WHG7CeWmiq+hJSTX/jR2p42LNLL5dvC0saAe0 nDaAHw2a1o/0jBxj2zkL3CNL2f+V7xTzFcUjCxnmGZmTUGBzMJPQChwp1MAnCzazA9AGk tD22sfXCCKxcXbYxScJC+PtjhjC9MU67bdmI6tXjRizzr/Sa9i2l6pnlPt6mdKXCETw== ARC-Message-Signature: i=1; d=osuosl.org; s=arc; a=rsa-sha256; c=relaxed/relaxed; t=1796207255; h=X-Comment:DKIM-Signature:X-Original-To:Delivered-To:Received: Received:X-Virus-Scanned:X-Spam-Flag:X-Spam-Score:X-Spam-Level: X-Spam-Status:Received:ARC-Filter:Received-SPF:Received:Received: DKIM-Signature:X-Google-DKIM-Signature:X-Gm-Message-State:X-Gm-Gg: X-Received:Received:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:MIME-Version:Content-Transfer-Encoding: X-BeenThere:X-Mailman-Version:Precedence:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:Errors-To; bh=HbL0J8hDGXnm3lfBzl2zymQ/4G/SEWpZuraMOylyyyg=; b=NaMTPOapVLYpxGJcDEhPm44ljygNnZ9Taqi+ifrSQP2+4ViFit9GF+Qm1DGZxDxPdWxO MGbKqF/UCPLxQgSqzjrpH51LbGud5gbFDl5fTA+Dv4+dCarvXN//pR6iKf4GY77Zt1coQ rpqvIRC/dgQYZ0DKIKXJOG9QQRvHXohj6zNIRi2hyPCecQsGVGzpu/8jvMWkNImbdadce 6r0xfAetl+ceF+H0RQuua53UoBi/MXFY28JM2gQQBCa+nE+baxztoYeCeBVgR1VT9MwfF Ek+8tAk6nA0ZadO5Ipib9kEFsjXbj/8aQ7c1pFyee5/T1qHraS7spgnc7Ju0akEQtNg== ARC-Authentication-Results: i=1; smtp3.osuosl.org; arc=none smtp.remote-ip=140.211.166.142 X-Comment: SPF check N/A for local connections - client-ip=140.211.166.142; helo=lists1.osuosl.org; envelope-from=u-boot-bounces@lists.u-boot-project.org; receiver= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=lists.u-boot-project.org; s=default; t=1796207255; bh=HbL0J8hDGXnm3lfBzl2zymQ/4G/SEWpZuraMOylyyyg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=LjoTpG2slg8m6Eg7MV1+MlywUS0Uwv1NWYsJ+N4ZWxR0viRJi2cLqExQw1HJPD82g /FAHF1Al2X5ztCeZVf3HjRuz0RWWS6/qu9sA/u0z7Maw1V6IEqOqQKnnwdMnoA80TL XLhBBC/glV09ymynW4HLava5Q2/ll/5rPPGS3u+fXItJZH5lNsSJxhv1RE2cS/46pZ 3GjFhc908/G3YGXA9/RjTzjklKVSI6xUyMWnu0I1LK1IruJS3AVDwZGVVT3XG/spsI y7LokR0zCuzvEfMq8rqZRSh8qjmQhHbvMSxA6SwRRN/VDdwGI8WO1V5EW7OiKVRMBN KCkOVNp8QQfZw== Received: from lists1.osuosl.org (lists1.osuosl.org [140.211.166.142]) by smtp3.osuosl.org (Postfix) with ESMTP id BB863606F5; Wed, 2 Dec 2026 10:27:35 +0000 (UTC) Received: from smtp4.osuosl.org (smtp4.osuosl.org [IPv6:2605:bc80:3010::137]) by lists1.osuosl.org (Postfix) with ESMTP id DB875325 for ; Wed, 2 Dec 2026 10:27:32 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp4.osuosl.org (Postfix) with ESMTP id CE1DC408A5 for ; Wed, 2 Dec 2026 10:27:32 +0000 (UTC) X-Virus-Scanned: amavis at osuosl.org Received: from smtp4.osuosl.org ([127.0.0.1]) by localhost (smtp4.osuosl.org [127.0.0.1]) (amavis, port 10024) with ESMTP id CJapX-R_J5ha for ; Wed, 2 Dec 2026 10:27:32 +0000 (UTC) ARC-Filter: OpenARC Filter v1.3.2 smtp4.osuosl.org DEA36406C1 Authentication-Results: smtp4.osuosl.org; arc=none smtp.remote-ip="2a00:1450:4864:20::331" Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=2a00:1450:4864:20::331; helo=mail-wm1-x331.google.com; envelope-from=dario.binacchi@amarulasolutions.com; receiver= Authentication-Results: smtp4.osuosl.org; dmarc=pass (p=none dis=none) header.from=amarulasolutions.com Authentication-Results: smtp4.osuosl.org; dkim=pass (1024-bit key) header.d=amarulasolutions.com header.i=@amarulasolutions.com header.a=rsa-sha256 header.s=google header.b=l1smOV9q Received: from mail-wm1-x331.google.com (mail-wm1-x331.google.com [IPv6:2a00:1450:4864:20::331]) by smtp4.osuosl.org (Postfix) with ESMTPS id DEA36406C1 for ; Wed, 2 Dec 2026 10:27:31 +0000 (UTC) Received: by mail-wm1-x331.google.com with SMTP id 5b1f17b1804b1-4b467581b98so119366425e9.0 for ; Wed, 02 Dec 2026 02:27:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amarulasolutions.com; s=google; t=1796207250; x=1796812050; darn=lists.u-boot-project.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=HbL0J8hDGXnm3lfBzl2zymQ/4G/SEWpZuraMOylyyyg=; b=l1smOV9q77QkWPkEO/X+idEBaRU+J6Pz+4smZ/KCZGUBkveUAQ8eoeSsVccwxUSZ32 6GO1spQYV14ya+nk3aGwcNOZIHv4hOTcL0sPcOgNEF3vl6n8V0JQbWYaGvM9OIbioGzB 5ZU8QWf9eMvwBj0FpnDn/H1mc5Ik68gb/TDj8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796207250; x=1796812050; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=HbL0J8hDGXnm3lfBzl2zymQ/4G/SEWpZuraMOylyyyg=; b=A0yTnWMEkJ276dw6BFiKFLolENZWZAxv+HJ99+UFeNe0BK/R8pY5Q5M44y5wVDnhjW 9TFcZ4NTBYS2fXHKh8uxpahRuwn+mUaOjPmnMyjmorkpeupmTCxJy0Pt/Hv/I0f+h/39 lwsG8NHY8AkCT2kBOsUihhbK7etvNQqQ4Bbqyp9NFJfeEp2JfrAYbqSrzQCxkYP0z892 J6lZJrqUeMDw/WAYqJI3jxu6T+nUuEW3F9IesoIDNLNCWbi/mxhVTYwqRE9mmw/4h/QU hMTm6Y4s/I0B4c07StHgJgJTavddwLDQLknNsg1vfJJAR/KZBUpbFdtpLIpgKXAFN9kb a0Qg== X-Gm-Message-State: APuU4Z+c0ZJc2YglDqyAOl9Eq2cgfMJq/iOq9yY8DPmEB90ll4H264vJ ThdMWvFJBLbrTG3KUCjlssoLWssHL0wL1LWzzAeYbmUJsru1tgh3YCLa0QbbXZsjJCTEYJ0lnOg PWt6j X-Gm-Gg: AZFdTZevBqsbOt4y3NXAOXIO7oRUMXlR+dcxB66YFs1RG+Mc2OPx0VeslPf2NhLnGDa 2dkYoGdWBZNuHb72y6NY3SQ/z/p7WHrNkzr1y/4ugafcEH6aDBf5CkMra7vUJXwiiawPoqglorY i9D3quv0/hotQzJBbu9ODBKzs44Uc7hTBSe7p7q3t636u/607nS/MrC16JB374/R1gZ+of2tDga zfqBAgVTmnX46zwZSkzCqqsdtwoa2lEyT5tBsJ6hIp9kles3pvGuIGuT+m+gRk5uXjJAUgG0aEX yt4dn0/rE3xPTwVsPXYa2LUNuJEJ9HuNaeXQ6qNqy1dpVweE8v7RrdmtayejjNlVTGudhfp4kKr kcomCZDBzLexM0PZp5Q9LFZ031Kl92Lv0BPrW2l+XP4sYCtutCn3ALFyPqvlvZ8fIRAkLDAse7b Mmm4tuLqYsQm5fU/mBzf7xgoG4gF9WdL4QpTsvlB2xeKB9TACTuqVevCoHzxDt4wMIFOohx44uB o7YJHXJiqYheidzMsVTU/nE7Fex+inkVKPZyRJDnFC6YN2loMXvgjhaQLkAKHedvQLTWsemM9kB skeWLN70hotf5VAsFPUaQ8dwVDIhQBI/JYYKna4dvnSZjGxF5k7lVbLPzH6cAc4J5LKo3LMhBT7 ggZ8VMSTZg2RIA3PtqvZC X-Received: by 2002:a05:600c:a55:b0:4a1:992f:d0e7 with SMTP id 5b1f17b1804b1-4bb889234a7mr757556035e9.16.1796207249836; Wed, 02 Dec 2026 02:27:29 -0800 (PST) Received: from localhost.localdomain ([2001:b07:6474:ebbf:6962:3ebc:7df:e6bf]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4bbbaeb1e4csm366823865e9.13.2026.12.02.02.27.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Dec 2026 02:27:29 -0800 (PST) From: Dario Binacchi To: u-boot@lists.u-boot-project.org Cc: Heiko Schocher , linux-amarula@amarulasolutions.com, Peng Fan , simon.holesch@bshg.com, Marek Vasut , Valeriy.Yatsenko@bshg.com, Leonhard Hesse , michael@amarulasolutions.com, Miquel Raynal , Dario Binacchi , Lukasz Majewski , Maksim Kiselev , Tom Rini Subject: [PATCH v3 03/26] clk: clk-uclass: fix parent reference counting in clk_set_parent() Date: Wed, 2 Dec 2026 11:26:14 +0100 Message-ID: <20261202102716.572884-4-dario.binacchi@amarulasolutions.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20261202102716.572884-1-dario.binacchi@amarulasolutions.com> References: <20261202102716.572884-1-dario.binacchi@amarulasolutions.com> X-Archived-By: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: u-boot@lists.u-boot-project.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: U-Boot discussion List-Archive: List-Post: List-Help: List-Subscribe: , X-Spam-Status: No, score=-18.9 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 clk_set_parent() enables the new parent only if the clock is enabled, but on failure it disables it unconditionally, dropping a reference it never took. On success, it never releases the reference the clock holds on its old parent, which then keeps running forever. Disable the new parent on failure only if it was enabled, and release the old parent once the clock has moved away from it, as Linux does in __clk_set_parent_after(). Fixes: ac30d90f3367 ("clk: Ensure the parent clocks are enabled while reparenting") Fixes: b493db39ea7f ("clk: Only enable the parent clock if the clock was enabled before reparenting") Signed-off-by: Dario Binacchi --- (no changes since v2) Changes in v2: - Add patch drivers/clk/clk-uclass.c | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/drivers/clk/clk-uclass.c b/drivers/clk/clk-uclass.c index 0069ce9a8875..c503f6733907 100644 --- a/drivers/clk/clk-uclass.c +++ b/drivers/clk/clk-uclass.c @@ -631,6 +631,7 @@ ulong clk_set_rate(struct clk *clk, ulong rate) int clk_set_parent(struct clk *clk, struct clk *parent) { const struct clk_ops *ops; + struct clk *old_parent = NULL; int ret; debug("%s(clk=%p, parent=%p)\n", __func__, clk, parent); @@ -641,6 +642,12 @@ int clk_set_parent(struct clk *clk, struct clk *parent) if (!ops->set_parent) return -ENOSYS; + if (CONFIG_IS_ENABLED(CLK_CCF)) { + old_parent = clk_get_parent(clk); + if (IS_ERR(old_parent)) + old_parent = NULL; + } + if (clk->enable_count) { ret = clk_enable(parent); if (ret && ret != -ENOSYS) { @@ -650,18 +657,18 @@ int clk_set_parent(struct clk *clk, struct clk *parent) } ret = ops->set_parent(clk, parent); + if (!ret && CONFIG_IS_ENABLED(CLK_CCF)) + ret = device_reparent(clk->dev, parent->dev); + if (ret) { - clk_disable(parent); + if (clk->enable_count) + clk_disable(parent); return ret; } - if (CONFIG_IS_ENABLED(CLK_CCF)) { - ret = device_reparent(clk->dev, parent->dev); - if (ret) { - clk_disable(parent); - return ret; - } - } + /* The clock no longer keeps its old parent running */ + if (clk->enable_count && old_parent) + clk_disable(old_parent); return 0; } -- 2.43.0