From mboxrd@z Thu Jan 1 00:00:00 1970 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 3692128003C; Tue, 27 May 2025 17:54:41 +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=1748368483; cv=none; b=Brzu1Ht7aFsEttn/LVOhqObUOKHL99WQYikMna3uchSzt7XFihIOyifbMCsMzAnu5/C5T5PJVXeSieUieJTUpmV6+/NcYofWVsbVlJ6LagSwN2rd9b5heMMWmN8pJ+GKu5Z+PQVBJkAJg4k3PX2Lc8RM5taiBoyf2tbfABQwwoE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1748368483; c=relaxed/simple; bh=CtYSDzqQ753F2Cmutkm1GqIFlflPlS35LF+pND9GlWQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=e85ba7tM6l2n+XhFu0bdmZymFVAW3iuPJB5lJrbPguf5QfDnqno2TibEhn/0KhBTuydaBxBXWaghTPxUHFsWUlD38Q6jfLInKruPPlVC7hZjOh2V3wSc9rWMKenyTfw1jSeJ2PXkXRsLH1lbucoojlIxTYJRNua8eFTKsfM9Bik= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=hdh0MmYG; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="hdh0MmYG" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2F0B5C4CEEA; Tue, 27 May 2025 17:54:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1748368481; bh=CtYSDzqQ753F2Cmutkm1GqIFlflPlS35LF+pND9GlWQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hdh0MmYGIgu/gyCKjvj0q9i2sx4+iC5OQgSbL+IfHii30RItiRPFEvf25AuvTqkSH ELJyxeyZO48Lb+vqu7BvTfltrRY71NwC45c67Qrs3vm8uh1OzMs8BmOvPo98EeNP9t YwHySYHcgkg32WH6M3hZWIVa4SMzPmUCyigAEhcc= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, =?UTF-8?q?Andr=C3=A9=20Draszik?= , Krzysztof Kozlowski , Stephen Boyd Subject: [PATCH 6.14 721/783] clk: s2mps11: initialise clk_hw_onecell_data::num before accessing ::hws[] in probe() Date: Tue, 27 May 2025 18:28:38 +0200 Message-ID: <20250527162542.472070079@linuxfoundation.org> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250527162513.035720581@linuxfoundation.org> References: <20250527162513.035720581@linuxfoundation.org> User-Agent: quilt/0.68 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 6.14-stable review patch. If anyone has any objections, please let me know. ------------------ From: André Draszik commit 3e14c7207a975eefcda1929b2134a9f4119dde45 upstream. With UBSAN enabled, we're getting the following trace: UBSAN: array-index-out-of-bounds in .../drivers/clk/clk-s2mps11.c:186:3 index 0 is out of range for type 'struct clk_hw *[] __counted_by(num)' (aka 'struct clk_hw *[]') This is because commit f316cdff8d67 ("clk: Annotate struct clk_hw_onecell_data with __counted_by") annotated the hws member of that struct with __counted_by, which informs the bounds sanitizer about the number of elements in hws, so that it can warn when hws is accessed out of bounds. As noted in that change, the __counted_by member must be initialised with the number of elements before the first array access happens, otherwise there will be a warning from each access prior to the initialisation because the number of elements is zero. This occurs in s2mps11_clk_probe() due to ::num being assigned after ::hws access. Move the assignment to satisfy the requirement of assign-before-access. Cc: stable@vger.kernel.org Fixes: f316cdff8d67 ("clk: Annotate struct clk_hw_onecell_data with __counted_by") Signed-off-by: André Draszik Link: https://lore.kernel.org/r/20250326-s2mps11-ubsan-v1-1-fcc6fce5c8a9@linaro.org Reviewed-by: Krzysztof Kozlowski Signed-off-by: Stephen Boyd Signed-off-by: Greg Kroah-Hartman --- drivers/clk/clk-s2mps11.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) --- a/drivers/clk/clk-s2mps11.c +++ b/drivers/clk/clk-s2mps11.c @@ -137,6 +137,8 @@ static int s2mps11_clk_probe(struct plat if (!clk_data) return -ENOMEM; + clk_data->num = S2MPS11_CLKS_NUM; + switch (hwid) { case S2MPS11X: s2mps11_reg = S2MPS11_REG_RTC_CTRL; @@ -186,7 +188,6 @@ static int s2mps11_clk_probe(struct plat clk_data->hws[i] = &s2mps11_clks[i].hw; } - clk_data->num = S2MPS11_CLKS_NUM; of_clk_add_hw_provider(s2mps11_clks->clk_np, of_clk_hw_onecell_get, clk_data);