From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.210.71 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796412365; b=3aapENT6PpQTMhmqy3203OxH0MN0mRvzFanYicEY2HdE1BgNGjaf6O+n7uAiw3iXORDO XJN2NDjDv5LQzGblmRWMIl0euQCyOaP5kVFUQmrtjESwuGAnTJJXMSKuWH3rxbOdrs7ci LzYzTaQqPJxiaT/tARA+u0Lpj0Hmj4HimNcpzkPYA7GsMloVt5GR7DaK/X0hMvezm6yTA gufusVWDhxB7KLhKiDjT1Uktezyg/U2IOL/ST0vKjVZjg9xMA+4JygJG/7yG6crssdAmT vZwO+5gvMYM+XFOENstERuMaWPfcDbBKrBBgAdTf3/KayoPPySvTqhwOuRXYJ9Y9n0w== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796412365; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Received:Date:In-Reply-To: Mime-Version:References:Message-ID:Subject:From:To:Cc:Content-Type; bh=HPPGpH/5fw6fnkXxGqM02iFTobIJXO9Xf4bRphmCi/8=; b=YJb5TuFeMTKxDCLDH9Z8kP4/XbcderB/Lwcc7psgAJBBK8mpx6fpWm3eQRc4qQSy2Huw jIZXTlpILwv0rH08W7BgTTHl0lxJKKbnKmfqob0y5WFDiFkz0zQKh01Cbs2ApY9+B7F5g ApUXtyhhkAmROS6osR9AWXGVT+NQ98vBQnnqO/evlnU9pGXZF/TGamtBd8lJWDlLow8in AqU2X53oXtmaz7pFaaeTj1tXrjlGAHcnzV9r/cI3/ykR7Wa8SrKxYNprEVzTVd7G17KWv 4SnFYILydGGXFDDgc+RTnVMWXPNvetm3PGItK7EhtmTh/icoL6EHdyEP9cgwp2NC28Q== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=google.com; spf=pass smtp.mailfrom=flex--justinstitt.bounces.google.com; dkim=pass header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=RzV6z54N; arc=none smtp.remote-ip=209.85.210.71 Received: from mail-ot1-f71.google.com (mail-ot1-f71.google.com [209.85.210.71]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DFD4D606A32F for ; Fri, 4 Dec 2026 19:26:04 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org DFD4D606A32F Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--justinstitt.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=RzV6z54N Received: by mail-ot1-f71.google.com with SMTP id 46e09a7af769-847e2926d94so2282441a34.0 for ; Fri, 04 Dec 2026 11:26:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20260707; t=1796412364; x=1797017164; darn=lists.linux.dev; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:from:to:cc:subject:date:message-id:reply-to :content-type; bh=HPPGpH/5fw6fnkXxGqM02iFTobIJXO9Xf4bRphmCi/8=; b=RzV6z54NbEhQK6o43KiZxezKuqi0qrXFPUdn3boOwN0R1FN5xcTYxThVw8Zhq9M2BZ QOYgdbIhKwB5u82g37eoL5XuzWluhaMkLt4pajCmRDTGKbc1v3lCTX1E/Ps34G7hbsgt xOJMmNSNuEJ3jo2uTMgRjhtP86BBhxTlkqUv6vVEh+Yhp750ic99ffI2lLwv0NloT08A XrpUaEaIG3lxJZLnrKeBrDNPjjge3T9v5sGtmbfZeMHM61Tlpj92FlQssdzmUrOKcaYp fFAETOJqWH86gqm9uCKxURQn4Y812IbJUL8+Z+QshAKxKjnpzvqYWM3uVveCtSBwWPvT fsNw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796412364; x=1797017164; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=HPPGpH/5fw6fnkXxGqM02iFTobIJXO9Xf4bRphmCi/8=; b=XtAh/IU2CVQmXW2Pp8awz4AxuAnBWSep6bocjxiLwg+0biXoDglGcnRVEnkrtsdB82 B4BK93sn+ZumzqMQ2sT+hc3PwKKQaR6NRoGyRZi6rG/MbYz2yj7uRfTNm2/JrwAf61di MspieJZoPATHKrps74xpALM5/F71gusLvwlFsWnhMzlKyuiubz3xdfLlpHXNnfUwsWlh vLDbU0TpXl6wFUHo5PKHpJ/AsvXLq+X3bfqFKhDtSIju+8rv+ktAg2Y37B6GFadqqS8I lbVh6nJBQf1cMGv2KSv4qkg4RKme+/SJ8M58DnUXTcG2YyTj2o7oLKCj7wSVNYGBK6VL IbrA== X-Forwarded-Encrypted: i=1; AL+hErEGTqYwOuRQztGveP4x6DyNKF/1F4wZn9Xq3P0plBldhDxSskLqgeKxRCYDb+a+HLW1vEKq@lists.linux.dev X-Gm-Message-State: APuU4Z8ZHa1scf2sM0JfrzaPOcCV2GdklAjVNBpnGHdKhgRpnzqqNvf6 3IBkhSuEGYtw8PQHRGUbhvZyBrdYaE5H24DBGDGGWFUxxAbAS+41iIpVF7pkC2+C/f9Uug8NFyZ npjQdsAH0emi+hI4VbhqrJ8rfpw== X-Received: from iobhd10.prod.google.com ([2002:a05:6602:680a:b0:9ea:3fb0:262]) (user=justinstitt job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6820:c446:10b0:71a:e74b:f97e with SMTP id 006d021491bc7-71bf203aa78mr1896235eaf.23.1796412363659; Fri, 04 Dec 2026 11:26:03 -0800 (PST) Date: Fri, 4 Dec 2026 11:26:03 -0800 In-Reply-To: <20261203-clk-onecell-count-order-v1-4-2b0e4e8d9ea6@cressey.dev> X-Mailing-List: llvm@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Mime-Version: 1.0 References: <20261203-clk-onecell-count-order-v1-0-2b0e4e8d9ea6@cressey.dev> <20261203-clk-onecell-count-order-v1-4-2b0e4e8d9ea6@cressey.dev> Message-ID: Subject: Re: [PATCH 04/11] clk: sifive: prci: Assign .num before accessing .hws From: Justin Stitt To: Ben Cressey Cc: Junhui Liu , Manivannan Sadhasivam , Nobuhiro Iwamatsu , Michal Simek , Stephen Boyd , Brian Masney , Jerome Brunet , Paul Walmsley , Samuel Holland , Emil Renner Berthing , Hal Feng , Nathan Chancellor , Kees Cook , Nick Desaulniers , Bill Wendling , "Gustavo A. R. Silva" , linux-arm-kernel@lists.infradead.org, linux-clk@vger.kernel.org, linux-riscv@lists.infradead.org, llvm@lists.linux.dev, linux-hardening@vger.kernel.org, Harry Austen , Changhuang Liang , stable@vger.kernel.org Content-Type: text/plain; charset="us-ascii" Hi, On Thu, Dec 03, 2026 at 04:15:42PM -0800, Ben Cressey wrote: > hws[] is annotated with __counted_by(num), but __prci_register_clocks() > fills it before it sets num. The count is still zero with Clang 20 and > 21, where devm_kzalloc_flex() does not set it, and on v6.6 to v7.3, > which use devm_kzalloc(). With __counted_by enabled, CONFIG_UBSAN_BOUNDS > reports the accesses and CONFIG_UBSAN_TRAP makes the first one trap > during probe. > > Set num right after the allocation. > > Found by an LLM-assisted check of __counted_by users. > > Fixes: f316cdff8d67 ("clk: Annotate struct clk_hw_onecell_data with __counted_by") > Cc: stable@vger.kernel.org > Signed-off-by: Ben Cressey > --- > drivers/clk/sifive/sifive-prci.c | 4 ++-- > 1 file changed, 2 insertions(+), 2 deletions(-) > > diff --git a/drivers/clk/sifive/sifive-prci.c b/drivers/clk/sifive/sifive-prci.c > index 402b905d010ed..b4544d024dd88 100644 > --- a/drivers/clk/sifive/sifive-prci.c > +++ b/drivers/clk/sifive/sifive-prci.c > @@ -540,8 +540,6 @@ static int __prci_register_clocks(struct device *dev, struct __prci_data *pd, > pd->hw_clks.hws[i] = &pic->hw; > } > > - pd->hw_clks.num = i; > - > r = devm_of_clk_add_hw_provider(dev, of_clk_hw_onecell_get, > &pd->hw_clks); > if (r) { > @@ -571,6 +569,8 @@ static int sifive_prci_probe(struct platform_device *pdev) > if (!pd) > return -ENOMEM; > > + pd->hw_clks.num = desc->num_clks; > + > pd->va = devm_platform_ioremap_resource(pdev, 0); > if (IS_ERR(pd->va)) > return PTR_ERR(pd->va); > > -- > 2.56.0 > Reviewed-by: Justin Stitt Justin