From nobody Sat Jun 13 15:12:12 2026 Received: from mail-pg1-f177.google.com (mail-pg1-f177.google.com [209.85.215.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 316963D34B6 for ; Wed, 6 May 2026 23:38:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.177 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778110736; cv=none; b=MiVL/Vd4YTRdo+DytCdSs6BnJf2bKD1/RqzO98X/XcNOAEcZPsDmMvjJweFOtjSMolyiSYRMWtAEvfW5fei/0NujiSfemiNaLfNeyVuVWibUoIyjt603G+hlVN95q2yrmxZVwL8ouRXEikT6zq7BYsT08X+Gd/c35xzb6/kst/s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778110736; c=relaxed/simple; bh=YY+R1qr5oJy3WtrJhQmeK5L9NeY3a4lm2XE9sFQEb6s=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Vyh4HTt8hRwFojHAJ5qWMBpq49r3kqV+mpQjEQD9E6Ie88b0jbI12VqwemaJtRcUbCKwPlUomnx2NWpv+4rcdCI+y0p0x3QRJuuNgVZ9RSHR2ZPLYLtl/ato1CAqrfIdtqO9UndCb1wJOi1lbbUMIH37okMWfKZYMLTS24CvenE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=Qktz3qj4; arc=none smtp.client-ip=209.85.215.177 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Qktz3qj4" Received: by mail-pg1-f177.google.com with SMTP id 41be03b00d2f7-c70fb6aa323so64423a12.3 for ; Wed, 06 May 2026 16:38:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1778110732; x=1778715532; darn=vger.kernel.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; bh=CyuSYjZx1jLqRtBEtVQBj/M4Q/f4SPIG8RJjNTkgcSM=; b=Qktz3qj4FJhhAqld0ILcU9KwStIZav2c18ycDcP5aUNNmxrNDvyCPaHi2iKnfdCg3D 7Y3b0wzasLHCDcjUpBAb5bfsFnabSeXIyhJE0ptpVJeHU+1NzouPJoDOp4dEajUvh1AO yBj5iIsezgcur5JPxPkenMkdnTjJgujPfIz3YL/MYASePdiHwmXKRNVTRX6r/Gj4IO4I cn/VCrBsrFYxo0wAXfiv5ieaVAEGotzWjnZu2xdl0Z5LmRbcs9QZs6MYTe+nycNZ1fiA f+xZCkfX3d3sOywiI5G6GzxL+jkEAm9yZLw8udl5tkOuBeAZDEOKStpJp13Q9Lv6aQad L27A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778110732; x=1778715532; 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; bh=CyuSYjZx1jLqRtBEtVQBj/M4Q/f4SPIG8RJjNTkgcSM=; b=UnTY76BDHZzT0154LY5X1+8ZMbMaLEJSuzL3RWT7iNxu7tTL7gIO6vEyecdBq1r+YQ F6fUOV/tlFAnmEbDu2T1yJ2xJIG9fCnhieP4JLc2K3NEjgb5MjO4eGAj215Hr06hDGs3 4Bgd0Kjd0QjjGaQMlAsnvDNjp478QPQNHRaMwC6C1ZmsxjiOgvilSduhjphk8xGPxdG2 4ctFPrmOVCPwJO0d7UNZrE1AV1dP1vf/YDKBMlZi3JMVje6tSw9hVsUOtYjpdONPr7y7 VicQOmwb5NHzuO/xvjPguf53q2XknV0s15kHPBnEzE8vTnClXQzeLCE3k6YgDFMJaHQA +Hhw== X-Forwarded-Encrypted: i=1; AFNElJ8o4ikbbs/TaTzmleOykdf6mKHX7s7fIRQNALzCwuPsdKY3ntbIKGpFHmmVrWsehyYOWroxjSWyrbjD1bU=@vger.kernel.org X-Gm-Message-State: AOJu0YxaOnLAkw5EcVTQgvqJr9mr7nDOXd+cO+E4NnaBUcGknmDiIebZ sBbv0p4CkeMsqru68xl9gncZn6Z2lfz4Hew5QOiHlT2Hyqi7F6qD1z6C X-Gm-Gg: AeBDies7fbeAXRuF2Sxz3cIS82X40nT7c3IlBko+k5H1HUpf0hOyr8FWTcW34Ql4/52 Qw+tjRgEUuxmsz/xcq9MCdv4H2QzSFvF4BFuC1JRWn01J85d5HHcjGSStHWZWtInhLcbiJtmT/4 3QfrlVkfPqSjX4s0diQ1Iz1YuqNyWox3IvZsTn9cw44sDJvyXCTlEFgzFqOaQe48E/jJkWw5RsN y2uaQJCqekdsfPWr/mG8Xp/TwJoQJaeM6pZzqb6trh+qNbYFIcvLppxabQE/AcaHvD2lu0ROX/O K+K+vT+Lm72pdS4VXmocKWt3Q+c88r07xP4i+cnpMcVGqkfHfk/dBNDvIyWlXC02f2ZP9MPsI6V 1b1KX5+3FTHgK6/ASAlcHvqcNR9x7eBL11phR35KMIAZoRuS47vDu7cvTh5s0KPunAMU14xGqf1 48005T1F0UOSZVu1+D2zvnQE2p89Fl/MtUcjhZJricvX6nfmvofs3XwTSbSAiif8da2u3Opff39 ZDor+FA1JCweoQrF6T1ELv1ZmTWwowjv47FS7Dsy0PoWA== X-Received: by 2002:a17:903:2b04:b0:2b4:6080:d4d0 with SMTP id d9443c01a7336-2ba798c2f47mr60722265ad.22.1778110732541; Wed, 06 May 2026 16:38:52 -0700 (PDT) Received: from ryzen ([2601:644:8000:5b5d:7285:c2ff:fe45:8a32]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2babaaef08bsm3471805ad.28.2026.05.06.16.38.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 May 2026 16:38:52 -0700 (PDT) From: Rosen Penev To: linux-clk@vger.kernel.org Cc: Krzysztof Kozlowski , Sylwester Nawrocki , Chanwoo Choi , Alim Akhtar , Michael Turquette , Stephen Boyd , Brian Masney , Kees Cook , "Gustavo A. R. Silva" , linux-samsung-soc@vger.kernel.org (open list:SAMSUNG SOC CLOCK DRIVERS), linux-kernel@vger.kernel.org (open list), linux-hardening@vger.kernel.org (open list:KERNEL HARDENING (not covered by other areas):Keyword:\b__counted_by(_le|_be)?\b) Subject: [PATCHv2 1/3] clk: samsung: use kzalloc_flex Date: Wed, 6 May 2026 16:38:31 -0700 Message-ID: <20260506233833.178357-2-rosenp@gmail.com> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260506233833.178357-1-rosenp@gmail.com> References: <20260506233833.178357-1-rosenp@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Simplify allocation by using kzalloc_flex with a flexible array member to combine allocations. samsung_clk_alloc_reg_dump is no longer needed for this struct but is needed elsewhere. Add __counted_by for extra runtime analysis. Move counting variable assignment after kzalloc_flex which does the same with GCC 15 and above. Signed-off-by: Rosen Penev --- drivers/clk/samsung/clk.c | 11 ++++++----- drivers/clk/samsung/clk.h | 2 +- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/drivers/clk/samsung/clk.c b/drivers/clk/samsung/clk.c index 91e5cdbc79d7..2895c77534ae 100644 --- a/drivers/clk/samsung/clk.c +++ b/drivers/clk/samsung/clk.c @@ -430,21 +430,22 @@ void samsung_clk_extended_sleep_init(void __iomem *re= g_base, unsigned long nr_rsuspend) { struct samsung_clock_reg_cache *reg_cache; + int i; =20 - reg_cache =3D kzalloc_obj(struct samsung_clock_reg_cache); + reg_cache =3D kzalloc_flex(*reg_cache, rdump, nr_rdump); if (!reg_cache) panic("could not allocate register reg_cache.\n"); - reg_cache->rdump =3D samsung_clk_alloc_reg_dump(rdump, nr_rdump); =20 - if (!reg_cache->rdump) - panic("could not allocate register dump storage.\n"); + reg_cache->rd_num =3D nr_rdump; + + for (i =3D 0; i < nr_rdump; ++i) + reg_cache->rdump[i].offset =3D rdump[i]; =20 if (list_empty(&clock_reg_cache_list)) register_syscore(&samsung_clk_syscore); =20 reg_cache->reg_base =3D reg_base; reg_cache->sysreg =3D sysreg; - reg_cache->rd_num =3D nr_rdump; reg_cache->rsuspend =3D rsuspend; reg_cache->rsuspend_num =3D nr_rsuspend; list_add_tail(®_cache->node, &clock_reg_cache_list); diff --git a/drivers/clk/samsung/clk.h b/drivers/clk/samsung/clk.h index b1192ca03db5..098f27a6290d 100644 --- a/drivers/clk/samsung/clk.h +++ b/drivers/clk/samsung/clk.h @@ -324,10 +324,10 @@ struct samsung_clock_reg_cache { struct list_head node; void __iomem *reg_base; struct regmap *sysreg; - struct samsung_clk_reg_dump *rdump; unsigned int rd_num; const struct samsung_clk_reg_dump *rsuspend; unsigned int rsuspend_num; + struct samsung_clk_reg_dump rdump[] __counted_by(rd_num); }; =20 /** --=20 2.54.0 From nobody Sat Jun 13 15:12:12 2026 Received: from mail-pl1-f176.google.com (mail-pl1-f176.google.com [209.85.214.176]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9F2F73D4100 for ; Wed, 6 May 2026 23:38:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.176 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778110735; cv=none; b=PuFprFCgpYKsFINaesWFI/SYp9RKGDPFZ5XWi1HKuFY0HNVdwdormfiLMt3k4dNwunn7tK3AEkp5EybBmNp0BolI3HZV0HJMbgLmIsUZg4mwTrKqI4ZliPg87UiUN66uUt/F9c6Vz+McmegB8PO51ilAq6IqsT2ppGrHU1dlj2Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778110735; c=relaxed/simple; bh=JXP8l6SZOlYJ3RZ86oWzg8ag9M+Lc2vnpFBpDW52rRs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=FF5W6IXHLdfqJz/0VjPmTpwAlBHxfjCfm6ZH/w/tsbXHubJNzYYX4h4G9ofaFoJg4WVvw4m+mj1eFo5AH4JzWvt6Xx2KfOMq+xJ7VKwf0OhPDVXFHtgaCefvTg7ZrvayfZI+6fW4hU75JiyyWhHiYhrqze1/0r4X+5FE6WT6UkE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=GAlYNfXx; arc=none smtp.client-ip=209.85.214.176 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="GAlYNfXx" Received: by mail-pl1-f176.google.com with SMTP id d9443c01a7336-2b4583f0a1aso1256665ad.3 for ; Wed, 06 May 2026 16:38:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1778110734; x=1778715534; darn=vger.kernel.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; bh=o3IG9Yp6Pjl+c9PKNtEae4TwSgGvYdWevGerwBQ6zPI=; b=GAlYNfXxTc9ptgfxgIe24oLzxnmYXnuS98ptuX6JSalg3PKzHrcLRe1srpSZ9erwbW n1QUQmwwqPaazKar0/z8r/kJsXiQefJFZfteRC1jEz+oD4uRw8GI7es7PeWFP3EzEs8E V+FYEEd168rRrmN6NLTNx93tbUK9DOfO3fMVVEkPeateB0IGSvgaosWXjORsjCzLWncJ 9nFfejVz7JXNljQr0DooB7+MAwSywK1k+pqVIfAAXta/5kKAwDsdgkUI0ESM8CfrU6jH u+9IMZ9nmpLgE78ihsVPYe0ntkWuxD44JcrV+OTu4TGTVem90JUH990UlyAsn0uA5e0m uDxg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778110734; x=1778715534; 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; bh=o3IG9Yp6Pjl+c9PKNtEae4TwSgGvYdWevGerwBQ6zPI=; b=KR7oTN4yirATliI00ejL68BhPBHyrBjJ/H9HD5bxTuA+OqKqTS3WRjno1WNAstw2Y8 nl7ipkjMv9fvs+GgvWBgux7D9YjUt8s+aB5cQ/tS4/diae0ShxwHg3Tos0mfs8hXtiEx iPIsW3XGGbqAmvMx0VLH31yxXHSZ90pVcXBPeYg63yg10eIA6JVQ0F5kkPkBHB+hfFlG 713T0jjae77dVhhs9zVZEXENaQwtC82NjfBeT3fMColMT1/mgul3ToawNQSn4djCtcds s46tiu76MluJi1h2IXYMdobvWd4bYnffpFOfUk78UBw2eXpN3GROoYpPfrWe2bv9sfbl wj4A== X-Forwarded-Encrypted: i=1; AFNElJ9dEVFz4KJL0/tYOKCQDYJ1S/33U7zVqE4Fu7bCkBPwWKeHc18mjs+N2QVTZqOptFd21G+K8EXhk77A22A=@vger.kernel.org X-Gm-Message-State: AOJu0YxyoCG5Rlien7lF7/Y62332/eUE42/qh81eeUJ+tLMMgv+R4XGt oSzPDFVVDg+kMS332rizMEh6RJY2El/0Zp7vDoQ0/RKAeER0j8QHqC28 X-Gm-Gg: AeBDietWPQUGJB5/5yhcmH2xD1ox0NjF7Ajrqw9sLAZ7RLOHDfWCIuXxBKhyoi8MBHC Q3Pt0FENJVcXp44dRFNXu8bykCChmexTZ5jRYwYmMweKshgYomFIdexEHc1Ubk4e0dcF3xSE6sN USQ8e2PN44jJ/jeEls061Y3ufcMsdkGfbFZR5jJauyUd4JRwdulyxZhtbPeRpt8k5emq2dzXFsz Mx6RcVHgSQ5G01wh9xCZ9L2n8k3o4Dgx0fc0JRBg+mdWr9OZPaHEKBqoTsXDSBB85u/hADbfHMC xD+eOItBxcvanX00eY9EsfM8GnLpxtHp3jJTnz0nrU7dqVu9ZCUey4lrccc63t3RC3FIcU38O5L LOJVtDELwxRKkPzoafORvLpO/sMwKdZj0O9pOy6TXuLYJVHuZpitIZ1+rA2kU6RFBVDFMm2C5Xw WQEablUWKPn7djZ6qjabYwez+Nfw2vZLmJGJZavqqMnZZRFiokjHhA4vd9QhrdHa+WzfYehMNCk yvb/jaq2UEBIcEbu55XaPBClzR8clzcRz5mCMMW5hVi49dVRfdpGX0X X-Received: by 2002:a17:902:f650:b0:2b2:5258:a23d with SMTP id d9443c01a7336-2ba78f54b3dmr54071995ad.14.1778110734082; Wed, 06 May 2026 16:38:54 -0700 (PDT) Received: from ryzen ([2601:644:8000:5b5d:7285:c2ff:fe45:8a32]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2babaaef08bsm3471805ad.28.2026.05.06.16.38.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 May 2026 16:38:53 -0700 (PDT) From: Rosen Penev To: linux-clk@vger.kernel.org Cc: Krzysztof Kozlowski , Sylwester Nawrocki , Chanwoo Choi , Alim Akhtar , Michael Turquette , Stephen Boyd , Brian Masney , Kees Cook , "Gustavo A. R. Silva" , linux-samsung-soc@vger.kernel.org (open list:SAMSUNG SOC CLOCK DRIVERS), linux-kernel@vger.kernel.org (open list), linux-hardening@vger.kernel.org (open list:KERNEL HARDENING (not covered by other areas):Keyword:\b__counted_by(_le|_be)?\b) Subject: [PATCHv2 2/3] clk: samsung: cpu: use kzalloc_flex Date: Wed, 6 May 2026 16:38:32 -0700 Message-ID: <20260506233833.178357-3-rosenp@gmail.com> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260506233833.178357-1-rosenp@gmail.com> References: <20260506233833.178357-1-rosenp@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Use a flexible array member to combine allocations. As kmemdup_array is really kcalloc + memcpy and kzalloc_flex kzalloc + kcalloc, kzalloc and kcalloc combine leaving the memcpy. Add __counted_by for extra runtime analysis. Remove fake const num_cfgs. It needs to be assigned for __counted_by to work. Signed-off-by: Rosen Penev --- drivers/clk/samsung/clk-cpu.c | 34 ++++++++++++++-------------------- 1 file changed, 14 insertions(+), 20 deletions(-) diff --git a/drivers/clk/samsung/clk-cpu.c b/drivers/clk/samsung/clk-cpu.c index ffc33e5decf5..37cf47533dc6 100644 --- a/drivers/clk/samsung/clk-cpu.c +++ b/drivers/clk/samsung/clk-cpu.c @@ -101,11 +101,11 @@ struct exynos_cpuclk { const struct clk_hw *alt_parent; void __iomem *base; spinlock_t *lock; - const struct exynos_cpuclk_cfg_data *cfg; - const unsigned long num_cfgs; + unsigned long num_cfgs; struct notifier_block clk_nb; unsigned long flags; const struct exynos_cpuclk_chip *chip; + struct exynos_cpuclk_cfg_data cfg[] __counted_by(num_cfgs); }; =20 /* ---- Common code ------------------------------------------------------= --- */ @@ -660,10 +660,6 @@ static int __init exynos_register_cpu_clock(struct sam= sung_clk_provider *ctx, return -EINVAL; } =20 - cpuclk =3D kzalloc_obj(*cpuclk); - if (!cpuclk) - return -ENOMEM; - parent_name =3D clk_hw_get_name(parent); =20 init.name =3D clk_data->name; @@ -672,6 +668,17 @@ static int __init exynos_register_cpu_clock(struct sam= sung_clk_provider *ctx, init.num_parents =3D 1; init.ops =3D &exynos_cpuclk_clk_ops; =20 + /* Find count of configuration rates in cfg */ + for (num_cfgs =3D 0; clk_data->cfg[num_cfgs].prate !=3D 0; ) + num_cfgs++; + + cpuclk =3D kzalloc_flex(*cpuclk, cfg, num_cfgs); + if (!cpuclk) + return -ENOMEM; + + cpuclk->num_cfgs =3D num_cfgs; + + memcpy(cpuclk->cfg, clk_data->cfg, num_cfgs * sizeof(*cpuclk->cfg)); cpuclk->alt_parent =3D alt_parent; cpuclk->hw.init =3D &init; cpuclk->base =3D ctx->reg_base + clk_data->offset; @@ -687,29 +694,16 @@ static int __init exynos_register_cpu_clock(struct sa= msung_clk_provider *ctx, goto free_cpuclk; } =20 - /* Find count of configuration rates in cfg */ - for (num_cfgs =3D 0; clk_data->cfg[num_cfgs].prate !=3D 0; ) - num_cfgs++; - - cpuclk->cfg =3D kmemdup_array(clk_data->cfg, num_cfgs, sizeof(*cpuclk->cf= g), - GFP_KERNEL); - if (!cpuclk->cfg) { - ret =3D -ENOMEM; - goto unregister_clk_nb; - } - ret =3D clk_hw_register(NULL, &cpuclk->hw); if (ret) { pr_err("%s: could not register cpuclk %s\n", __func__, clk_data->name); - goto free_cpuclk_data; + goto unregister_clk_nb; } =20 samsung_clk_add_lookup(ctx, &cpuclk->hw, clk_data->id); return 0; =20 -free_cpuclk_data: - kfree(cpuclk->cfg); unregister_clk_nb: clk_notifier_unregister(parent->clk, &cpuclk->clk_nb); free_cpuclk: --=20 2.54.0 From nobody Sat Jun 13 15:12:12 2026 Received: from mail-pl1-f175.google.com (mail-pl1-f175.google.com [209.85.214.175]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 580733D4135 for ; Wed, 6 May 2026 23:38:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.175 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778110737; cv=none; b=JfkUmxmo/c4/oy4b+1fyBB8kImRlKqS7rmQchKXgPSIXAu94bNaNfEH7xM9Na5i7Z+I2fwlfWB2TCeV4n+BV5nHktX+l1T0idSu9rM9i3ULrxkz+3AVbyZ3xKlMmEVAy+hFAIujmWpX8EWiTm4xNV+pKwCYFuYasQS3Rad7h0pc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778110737; c=relaxed/simple; bh=2OtwiR0aUl1XQdXsTMhDBXZj/AxoFLijZjRd9Wnd81k=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=aS41TlocHV+GhTp8sK17zs49d2qqj6yFDvY7x6yeC0jvnfh2JJFW5azJd1IJ1z06coWJWljdadzWygfKUK+obHsJLZg1aNJqIo6FKnP0dErFm4wRoVrPw4Y9mu06/WZCSInUShWXyhoUZRmtofQVyI7F4ZproEzAvgr4ybzi6/I= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=oc9SftNn; arc=none smtp.client-ip=209.85.214.175 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="oc9SftNn" Received: by mail-pl1-f175.google.com with SMTP id d9443c01a7336-2b458ca2296so1490455ad.0 for ; Wed, 06 May 2026 16:38:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1778110736; x=1778715536; darn=vger.kernel.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; bh=okd3JtsJS3ksT2GaRH8nnVfDydk7G//ESOzr5O9Y1xA=; b=oc9SftNnNlefwgQh1Rx3kyrFn1tBuKmMYpHwyqbKxCim7y29yMjS1D5hxpYFP9r4kE whwf0d0hwiba5MSJUpzj7ZcHTHR/SfyKFYuc81JVGZF6eAAGt7Yf8ycLblnU9sfyfH/U pwjPOegkbYlUfI//G9oq/rUzIcXwFSUknzszSxpTMNLgD+X2fmDA+QfHXXr2htqESTlD lHxb61ku4rTQFH1BQ1JW/Q1/9rUZCoTwrbmzJjaBxkUYZkdLAv+6y9crka8H//22Zlcd ENYASk5pjZASVOgbte/76R7SNFd3Xf2P6xExw6BKJnNRgWJ8+5ipwA8PiyCMsLq+fuPA X2zw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778110736; x=1778715536; 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; bh=okd3JtsJS3ksT2GaRH8nnVfDydk7G//ESOzr5O9Y1xA=; b=j+OTaZ/ldnpDQpORJDvq9PnTbbYU3VTvSCZzZ9XZYGES7sDaEzz/b+YCavv8bVzYKd UrpB15PE/d6phCxUqwKRacZe2iDfkMcWZbn776X7Z8Byh6o8+txmEpv+gJ8J+gw2Zs72 8wRYQeQdR+yLHg93yt1qTGO7BjoebAk1Ya284MobARBq4Ss0fvMGkkb9wHNMymoS+xju WnQXRKNZKA/k0Ska5iy7Ny8kmCPbVP5G1L4hyuGgRho9Bf1A3WIEOIAbDYbSY9+6hJKF iuLua4m9DPqmeAA5n511Rz8LqiPgetXnaB4gpveHazjce0xRU7hH2AGRQpFLUrYND1Ee Iq6w== X-Forwarded-Encrypted: i=1; AFNElJ82Hlwz5ANJHUTJs9OioUhUe5Vk4CGwpnYi+xBeiHkvpHrbFXb9faup+8fYVUYA4cFnp4mFYJPc4kMqB/U=@vger.kernel.org X-Gm-Message-State: AOJu0Yx2snYTF5+97Qh5Yc/lzJ0F5WCTKGKFp0ky7hyfVmFxEQXlDuzP 0L1m0h2qoQBJAFjJanRvtXD3DUElZOCahIuRv3eUbOj/rwV3RefJHFxL X-Gm-Gg: AeBDievGcMUkfO0H3KUWGa/vtBeigmZ7DWFVAhwOkQi35asoYq1v5kkLiDN8BusHvgv xWVgBqZ6+d+9u55tPzEjldr7ibvRZt2gxLsgELVf6eEBMWu9JuOyDdMw0HgFb6WoDCI5qAvyVdq v5xNP8Mv0fnohZePTxAYhD5BgsVYVL6MrlRawWLKpv3mWkZytkxzvgcu90wJu2gatRWZpJj2l3D c450eo/oClQo2dF4bD7Vy4R8kU0ZM6dUgs9MT+zYETNEO8TcfNycoDk1OQfuAsnZbzxJaBfAC+1 p0wFkdGdNyyb54NRwkBSF7BrPx2zS0u/L8NYeVx04iGVdOf4lhGSN7963SOq50fI9Au4xT8hMeA nxOB5QTIe5PBUJeSVyQlNrE0a5HULK607BJ1nBunXZNpFE5RHQ0nVPN0VFrJV9ouq37lRNO2rpL /HReyq8Nz7hiXzM9NLcN7aKbZSs+KSJt06gRE5erik7hIFpCiIfBBhhis3vocVAVvCANXpU95wo 0t6B5c5XaCrJ2Uw5s65JrJJ+oRxodDO15fYS2dYKAllQA== X-Received: by 2002:a17:903:178b:b0:2ba:881f:6192 with SMTP id d9443c01a7336-2ba881f63c2mr46188485ad.22.1778110735541; Wed, 06 May 2026 16:38:55 -0700 (PDT) Received: from ryzen ([2601:644:8000:5b5d:7285:c2ff:fe45:8a32]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2babaaef08bsm3471805ad.28.2026.05.06.16.38.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 May 2026 16:38:54 -0700 (PDT) From: Rosen Penev To: linux-clk@vger.kernel.org Cc: Krzysztof Kozlowski , Sylwester Nawrocki , Chanwoo Choi , Alim Akhtar , Michael Turquette , Stephen Boyd , Brian Masney , Kees Cook , "Gustavo A. R. Silva" , linux-samsung-soc@vger.kernel.org (open list:SAMSUNG SOC CLOCK DRIVERS), linux-kernel@vger.kernel.org (open list), linux-hardening@vger.kernel.org (open list:KERNEL HARDENING (not covered by other areas):Keyword:\b__counted_by(_le|_be)?\b) Subject: [PATCHv2 3/3] clk: samsung: pll: use kzalloc_flex Date: Wed, 6 May 2026 16:38:33 -0700 Message-ID: <20260506233833.178357-4-rosenp@gmail.com> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260506233833.178357-1-rosenp@gmail.com> References: <20260506233833.178357-1-rosenp@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Simplify allocation by using a flexible array member to combine allocations and remove a kfree. Use __counted_by for extra runtime analysis. Since rate_table is now a flexible array member, NULL checks don't work. So use the counting variable to check allocation. Signed-off-by: Rosen Penev --- drivers/clk/samsung/clk-pll.c | 56 ++++++++++++++++------------------- 1 file changed, 26 insertions(+), 30 deletions(-) diff --git a/drivers/clk/samsung/clk-pll.c b/drivers/clk/samsung/clk-pll.c index fdb84bcec912..e74552846ba3 100644 --- a/drivers/clk/samsung/clk-pll.c +++ b/drivers/clk/samsung/clk-pll.c @@ -28,7 +28,7 @@ struct samsung_clk_pll { unsigned short lock_offs; enum samsung_pll_type type; unsigned int rate_count; - const struct samsung_pll_rate_table *rate_table; + struct samsung_pll_rate_table rate_table[] __counted_by(rate_count); }; =20 #define to_clk_pll(_hw) container_of(_hw, struct samsung_clk_pll, hw) @@ -1593,35 +1593,32 @@ static void __init _samsung_clk_register_pll(struct= samsung_clk_provider *ctx, { struct samsung_clk_pll *pll; struct clk_init_data init; - int ret, len; + unsigned int len =3D 0; + int ret; =20 - pll =3D kzalloc_obj(*pll); + if (pll_clk->rate_table) { + /* find count of rates in rate_table */ + while (pll_clk->rate_table[len].rate !=3D 0) + len++; + } + + pll =3D kzalloc_flex(*pll, rate_table, len); if (!pll) { pr_err("%s: could not allocate pll clk %s\n", __func__, pll_clk->name); return; } =20 + pll->rate_count =3D len; + if (len) + memcpy(pll->rate_table, pll_clk->rate_table, + len * sizeof(*pll->rate_table)); + init.name =3D pll_clk->name; init.flags =3D pll_clk->flags; init.parent_names =3D &pll_clk->parent_name; init.num_parents =3D 1; =20 - if (pll_clk->rate_table) { - /* find count of rates in rate_table */ - for (len =3D 0; pll_clk->rate_table[len].rate !=3D 0; ) - len++; - - pll->rate_count =3D len; - pll->rate_table =3D kmemdup_array(pll_clk->rate_table, - pll->rate_count, - sizeof(*pll->rate_table), - GFP_KERNEL); - WARN(!pll->rate_table, - "%s: could not allocate rate table for %s\n", - __func__, pll_clk->name); - } - switch (pll_clk->type) { case pll_2126: init.ops =3D &samsung_pll2126_clk_ops; @@ -1640,7 +1637,7 @@ static void __init _samsung_clk_register_pll(struct s= amsung_clk_provider *ctx, case pll_a9fracm: pll->enable_offs =3D PLL35XX_ENABLE_SHIFT; pll->lock_offs =3D PLL35XX_LOCK_STAT_SHIFT; - if (!pll->rate_table) + if (!pll->rate_count) init.ops =3D &samsung_pll35xx_clk_min_ops; else init.ops =3D &samsung_pll35xx_clk_ops; @@ -1659,7 +1656,7 @@ static void __init _samsung_clk_register_pll(struct s= amsung_clk_provider *ctx, case pll_0732x: pll->enable_offs =3D PLL0822X_ENABLE_SHIFT; pll->lock_offs =3D PLL0822X_LOCK_STAT_SHIFT; - if (!pll->rate_table) + if (!pll->rate_count) init.ops =3D &samsung_pll0822x_clk_min_ops; else init.ops =3D &samsung_pll0822x_clk_ops; @@ -1669,7 +1666,7 @@ static void __init _samsung_clk_register_pll(struct s= amsung_clk_provider *ctx, break; case pll_4502: case pll_4508: - if (!pll->rate_table) + if (!pll->rate_count) init.ops =3D &samsung_pll45xx_clk_min_ops; else init.ops =3D &samsung_pll45xx_clk_ops; @@ -1679,7 +1676,7 @@ static void __init _samsung_clk_register_pll(struct s= amsung_clk_provider *ctx, case pll_2650: pll->enable_offs =3D PLL36XX_ENABLE_SHIFT; pll->lock_offs =3D PLL36XX_LOCK_STAT_SHIFT; - if (!pll->rate_table) + if (!pll->rate_count) init.ops =3D &samsung_pll36xx_clk_min_ops; else init.ops =3D &samsung_pll36xx_clk_ops; @@ -1687,7 +1684,7 @@ static void __init _samsung_clk_register_pll(struct s= amsung_clk_provider *ctx, case pll_0831x: pll->enable_offs =3D PLL0831X_ENABLE_SHIFT; pll->lock_offs =3D PLL0831X_LOCK_STAT_SHIFT; - if (!pll->rate_table) + if (!pll->rate_count) init.ops =3D &samsung_pll0831x_clk_min_ops; else init.ops =3D &samsung_pll0831x_clk_ops; @@ -1703,7 +1700,7 @@ static void __init _samsung_clk_register_pll(struct s= amsung_clk_provider *ctx, case pll_4650: case pll_4650c: case pll_1460x: - if (!pll->rate_table) + if (!pll->rate_count) init.ops =3D &samsung_pll46xx_clk_min_ops; else init.ops =3D &samsung_pll46xx_clk_ops; @@ -1712,19 +1709,19 @@ static void __init _samsung_clk_register_pll(struct= samsung_clk_provider *ctx, init.ops =3D &samsung_pll2550x_clk_ops; break; case pll_2550xx: - if (!pll->rate_table) + if (!pll->rate_count) init.ops =3D &samsung_pll2550xx_clk_min_ops; else init.ops =3D &samsung_pll2550xx_clk_ops; break; case pll_2650x: - if (!pll->rate_table) + if (!pll->rate_count) init.ops =3D &samsung_pll2650x_clk_min_ops; else init.ops =3D &samsung_pll2650x_clk_ops; break; case pll_2650xx: - if (!pll->rate_table) + if (!pll->rate_count) init.ops =3D &samsung_pll2650xx_clk_min_ops; else init.ops =3D &samsung_pll2650xx_clk_ops; @@ -1734,7 +1731,7 @@ static void __init _samsung_clk_register_pll(struct s= amsung_clk_provider *ctx, init.ops =3D &samsung_pll531x_clk_ops; break; case pll_1031x: - if (!pll->rate_table) + if (!pll->rate_count) init.ops =3D &samsung_pll1031x_clk_min_ops; else init.ops =3D &samsung_pll1031x_clk_ops; @@ -1742,7 +1739,7 @@ static void __init _samsung_clk_register_pll(struct s= amsung_clk_provider *ctx, case pll_a9fraco: pll->enable_offs =3D PLLA9FRACO_ENABLE_SHIFT; pll->lock_offs =3D PLLA9FRACO_LOCK_STAT_SHIFT; - if (!pll->rate_table) + if (!pll->rate_count) init.ops =3D &samsung_a9fraco_clk_min_ops; else init.ops =3D &samsung_a9fraco_clk_ops; @@ -1761,7 +1758,6 @@ static void __init _samsung_clk_register_pll(struct s= amsung_clk_provider *ctx, if (ret) { pr_err("%s: failed to register pll clock %s : %d\n", __func__, pll_clk->name, ret); - kfree(pll->rate_table); kfree(pll); return; } --=20 2.54.0