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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 17238CD5BD1 for ; Mon, 1 Jun 2026 20:35:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:Message-ID:Date:Subject:Cc:To:From:Reply-To:Content-Type: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Owner; bh=T/ACLI/O+MEH4QMv4GHRPdBcYwgQV3Hd/E0FFNYu5y8=; b=O7pSNR2C9AFx/lWmAyYRICUkpD MD+pwmXMropYl+/JH7AkJaubjcueBpX27fdwiZw/LITYbAK+PHgxPVh5VT6LnCEee8wNbw6v7oxBL 4Zb5YBabsjX+g02g4yLbtk2iXVZdjwVV+9PirWT+fJGbZHeaJMDIO5/DNaGn4zHKE7K2NGZkqevfj mT2CaZ+T5tI1jFVaC3d4KCOD6rjpuXJek7e1Afb0f1jG9pWtM9Pn1J50iJWTiH+VJlQQkKW4iAbnV T1DNs6PyiU+eQZdge9wlwwjsXeN0ghKjo5PaVBP9DWXQo/neGhd0RveEIYggAEl/ehySCxwuTIDQB 3iIYDsNQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.99.1 #2 (Red Hat Linux)) id 1wU9Lu-0000000BmhM-1iGt; Mon, 01 Jun 2026 20:35:14 +0000 Received: from mail-106111.protonmail.ch ([79.135.106.111]) by bombadil.infradead.org with esmtps (Exim 4.99.1 #2 (Red Hat Linux)) id 1wU9Lr-0000000Bmgp-0KlQ for linux-arm-kernel@lists.infradead.org; Mon, 01 Jun 2026 20:35:12 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=theesfeld.net; s=protonmail2; t=1780346104; x=1780605304; bh=T/ACLI/O+MEH4QMv4GHRPdBcYwgQV3Hd/E0FFNYu5y8=; h=From:To:Cc:Subject:Date:Message-ID:From:To:Cc:Date:Subject: Reply-To:Feedback-ID:Message-ID:BIMI-Selector; b=iz27cElDwGo3nbW9COmb+WgyYBkzqtzbP53MaBBZOzOhS78IAQW+GyfPLtIte6mra fgiU9rznEQYrQavt+FDUiLy5Bro9rlxg3A6pn15h8sTTprn9eJM6o0f4Rl0p8dSaq3 Zb+80qhgiLxxJWKIrmVy3tMS3feX2Ti5hboovjN7+SqBHCYNYDgcSL16ND4VjnAPxB navHfKnXBt48SZ687WPALdDVHjcThNePBcrShxXbdgW682p1OjOmjcT4ZDK66OzaIY lzltaOO4VTdhGhEnn0+3e4OPZhAmZnabRsOCpTybJ6yeeG7CFr3JV6oC5a331CeGrc 8/Q0Xsee0fJGQ== X-Pm-Submission-Id: 4gTm122Rwrz2Scpl From: William Theesfeld To: Michael Turquette Cc: Stephen Boyd , Brian Masney , Michal Simek , linux-clk@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH] clk: zynq: handle kasprintf() failure in periph_clk registration Date: Mon, 1 Jun 2026 16:35:00 -0400 Message-ID: <20260601203500.658135-1-william@theesfeld.net> X-Mailer: git-send-email 2.54.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.9.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20260601_133511_279665_E7915A84 X-CRM114-Status: GOOD ( 11.84 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org zynq_clk_register_periph_clk() ignores the return value of the two kasprintf() calls used to build the mux and divider clock names, and passes the resulting (possibly NULL) pointers straight into clk_register_mux(), clk_register_divider() and clk_register_gate() as the clock '"'name'"' argument. On allocation failure that name later gets dereferenced by the clock framework (e.g. in debugfs name formatting), causing a NULL-pointer dereference. Check both kasprintf() returns. On failure unwind any allocated name buffer and the spinlock, then fall through to the existing err label which sets clks[] to ERR_PTR(-ENOMEM). Freeing the spinlock on the error path is correct here because no clk_register_*() call has had a chance to take ownership of it; the success path intentionally hands it off to the registered clocks. The neighbouring zynq_clk_register_fclk() in the same file already uses this per-allocation goto-label cleanup pattern; this change brings periph_clk into line with it. Signed-off-by: William Theesfeld --- drivers/clk/zynq/clkc.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/drivers/clk/zynq/clkc.c b/drivers/clk/zynq/clkc.c index 6a22cbbc1..777187744 100644 --- a/drivers/clk/zynq/clkc.c +++ b/drivers/clk/zynq/clkc.c @@ -186,7 +186,11 @@ static void __init zynq_clk_register_periph_clk(enum zynq_clk clk0, spin_lock_init(lock); mux_name = kasprintf(GFP_KERNEL, "%s_mux", clk_name0); + if (!mux_name) + goto err_mux_name; div_name = kasprintf(GFP_KERNEL, "%s_div", clk_name0); + if (!div_name) + goto err_div_name; clk_register_mux(NULL, mux_name, parents, 4, CLK_SET_RATE_NO_REPARENT, clk_ctrl, 4, 2, 0, lock); @@ -205,6 +209,10 @@ static void __init zynq_clk_register_periph_clk(enum zynq_clk clk0, return; +err_div_name: + kfree(mux_name); +err_mux_name: + kfree(lock); err: clks[clk0] = ERR_PTR(-ENOMEM); if (two_gates) -- 2.54.0