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 00349CF2563 for ; Wed, 19 Nov 2025 00:10:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=BAsRQuK5KgUb3HI5iiySC4Tgu649z/k7uzPBfIfGx7g=; b=n4b2G+JVX2+Fn5 fc7vhJ0VtNeX6QFyD8qFOWMnsKYE056jWFpi2AghSy6q0YjvUJZvlP2XAazCUZN9SaiwHHSMsIxDZ 2sVT8H2o8oZLQcXqsjT+luKosNhk0/3J4xd8cDgVDTkAHhDCxJZoBfNBuJF0ecSBZdWy7wEtR91zc yD7pQceZn2Qh8PKqr36xJmU1sNSAO/R6amvDY+dQDMdV65MaWe3LitdS2LumI4IWSEdpKxwvnAKpz OIX/rIdhlExqJl7kqmfEf0UKjBZdOVXFE8zfnxXynyBhTqDc5Wf1Vbmb7AYKr3qyhxm8r352fFyq3 WOKL7AEqm/doZCwQJgtQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98.2 #2 (Red Hat Linux)) id 1vLVlw-00000001H0d-1ngX; Wed, 19 Nov 2025 00:10:08 +0000 Received: from dev.gentoo.org ([2001:470:ea4a:1:5054:ff:fec7:86e4] helo=smtp.gentoo.org) by bombadil.infradead.org with esmtps (Exim 4.98.2 #2 (Red Hat Linux)) id 1vLVlu-00000001H0D-2JPO for linux-riscv@lists.infradead.org; Wed, 19 Nov 2025 00:10:07 +0000 Received: from localhost (unknown [116.232.18.222]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange secp256r1 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: dlan) by smtp.gentoo.org (Postfix) with ESMTPSA id B384C340E31; Wed, 19 Nov 2025 00:03:36 +0000 (UTC) Date: Wed, 19 Nov 2025 08:03:32 +0800 From: Yixun Lan To: Stephen Boyd , Charles Mirabile Cc: linux-kernel@vger.kernel.org, spacemit@lists.linux.dev, linux-riscv@lists.infradead.org, linux-clk@vger.kernel.org, mturquette@baylibre.com, heylenay@4d2.org, elder@riscstar.com, troy.mitchell@linux.spacemit.com, inochiama@outlook.com, Yanko Kaneti Subject: Re: [PATCH] clk: spacemit: fix UBSAN warning during probe Message-ID: <20251119000332-GYB1726554@gentoo.org> References: <20251117190329.1337250-1-cmirabil@redhat.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20251117190329.1337250-1-cmirabil@redhat.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20251118_161006_621579_8B2506B1 X-CRM114-Status: GOOD ( 22.11 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org Hi Stephen, Could you take this patch directly? or let me know if you want me to handle On 14:03 Mon 17 Nov , Charles Mirabile wrote: > When booting with KASAN enabled the following splat is encountered during > probe of the k1 clock driver: > > UBSAN: array-index-out-of-bounds in drivers/clk/spacemit/ccu-k1.c:1044:16 > index 0 is out of range for type 'clk_hw *[*]' > CPU: 0 UID: 0 PID: 1 Comm: swapper/0 Not tainted 6.18.0-rc5+ #1 PREEMPT(lazy) > Hardware name: Unknown Unknown Product/Unknown Product, BIOS 2022.10spacemit 10/01/2022 > Call Trace: > [] dump_backtrace+0x28/0x38 > [] show_stack+0x3a/0x50 > [] dump_stack_lvl+0x5a/0x80 > [] dump_stack+0x18/0x20 > [] ubsan_epilogue+0x10/0x48 > [] __ubsan_handle_out_of_bounds+0xa6/0xa8 > [] k1_ccu_probe+0x37e/0x420 > [] platform_probe+0x56/0x98 > [] really_probe+0x9e/0x350 > [] __driver_probe_device+0x80/0x138 > [] driver_probe_device+0x3a/0xd0 > [] __driver_attach+0xac/0x1b8 > [] bus_for_each_dev+0x6c/0xc8 > [] driver_attach+0x26/0x38 > [] bus_add_driver+0x13e/0x268 > [] driver_register+0x52/0x100 > [] __platform_driver_register+0x28/0x38 > [] k1_ccu_driver_init+0x22/0x38 > [] do_one_initcall+0x62/0x2a0 > [] do_initcalls+0x170/0x1a8 > [] kernel_init_freeable+0x16a/0x1e0 > [] kernel_init+0x2c/0x180 > [] ret_from_fork_kernel+0x16/0x1d8 > [] ret_from_fork_kernel_asm+0x16/0x18 > ---[ end trace ]--- > > This is bogus and is simply a result of KASAN consulting the `.num` member > of the struct for bounds information (as it should due to `__counted_by`) > and finding 0 set by kzalloc because it has not been initialized before > the loop that fills in the array. The easy fix is to just move the line > that sets `num` to before the loop that fills the array so that KASAN has > the information it needs to accurately conclude that the access is valid. .. > > One blank line is enough > Fixes: 1b72c59db0add ("clk: spacemit: Add clock support for SpacemiT K1 SoC") > Tested-by: Yanko Kaneti > Drop, no blank line between Tested-by and SoF > Signed-off-by: Charles Mirabile Reviewed-by: Yixun Lan > --- > drivers/clk/spacemit/ccu-k1.c | 4 ++-- > 1 file changed, 2 insertions(+), 2 deletions(-) > > diff --git a/drivers/clk/spacemit/ccu-k1.c b/drivers/clk/spacemit/ccu-k1.c > index f5a9fe6ba1859..4761bc1e3b6e6 100644 > --- a/drivers/clk/spacemit/ccu-k1.c > +++ b/drivers/clk/spacemit/ccu-k1.c > @@ -1018,6 +1018,8 @@ static int spacemit_ccu_register(struct device *dev, > if (!clk_data) > return -ENOMEM; > > + clk_data->num = data->num; > + > for (i = 0; i < data->num; i++) { > struct clk_hw *hw = data->hws[i]; > struct ccu_common *common; > @@ -1044,8 +1046,6 @@ static int spacemit_ccu_register(struct device *dev, > clk_data->hws[i] = hw; > } > > - clk_data->num = data->num; > - > ret = devm_of_clk_add_hw_provider(dev, of_clk_hw_onecell_get, clk_data); > if (ret) > dev_err(dev, "failed to add clock hardware provider (%d)\n", ret); > > base-commit: 6a23ae0a96a600d1d12557add110e0bb6e32730c > -- > 2.51.1 > > -- Yixun Lan (dlan) _______________________________________________ linux-riscv mailing list linux-riscv@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-riscv