From nobody Thu Apr 2 23:54:11 2026 Received: from mail-pl1-f171.google.com (mail-pl1-f171.google.com [209.85.214.171]) (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 E24673191D0 for ; Thu, 26 Mar 2026 04:23:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774499017; cv=none; b=QNhO4nLg8d4FlWa7Vgb+kD/a5Sa1ar0AwyIgoIV35TERmk/i3BIAAu3MSHsHZd90KpFymK0SUPLMwKR6s/Gpwn7bxsPP8BAKPr357bek/6HsT6xC7DEsql70HbdRBMN+ADqZESRJUju1RcQiyO+pIZGwWQlIyOD6RBDj3CuGVxo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774499017; c=relaxed/simple; bh=9aXpIYHxEZve/zODLL3ErK9l7SJiyftQgW265r3QNo0=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=O0ogiiUhQzcdNOwK3lpF46rT31VkMrg2G7GjSPMkhcOmf/s3e3hy7ApQwoVEvpJxucMB6PN2ARxl73yAzQ30zMF6RjAH+g8s8eeTz4MOv5nSxGeLPhkSUz19OkZMV6ieEs4oasrKlxVcrlItodbeaSu6WdcCtKUSh0dIQgdwwdg= 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=UK4jyelZ; arc=none smtp.client-ip=209.85.214.171 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="UK4jyelZ" Received: by mail-pl1-f171.google.com with SMTP id d9443c01a7336-2ad9f316d68so2582485ad.2 for ; Wed, 25 Mar 2026 21:23:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1774499015; x=1775103815; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=uePC4t9zYdAqfWmLVP6FLg/cJ2NqG/wiW8h1ArBlvSo=; b=UK4jyelZdP0Eb6vUdPuGFatpW/rxaJ8Ao76PGrQE8yY7h2qxQJriM3JZ02O7CemOCl 5QF5pCCy9jPUaM0JNt4Vj1+F74SSu/vYJDmFUXaIszEbmdlWQgWm6A/mJexUqXtBwbGA kHZPTgsp+8jqnLQ+sqJDU3L3lsnqsgbgN24SHzRnl+5ySGbO789qdSZyYKM9e0Z9LJqn QhNyu90hsKcTjzeqxmPnZUNq2gI4I9TIuqqPHQjiIrky7LWPH5912B9WhOeUrxA6S9Dd 2BeT5ehUICDfpbTLqpB0R9oKvWfafJ6O2QzOQ6zGUycAi+52AyGmrEndG+N6Ys3ls0bc ZvVw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1774499015; x=1775103815; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=uePC4t9zYdAqfWmLVP6FLg/cJ2NqG/wiW8h1ArBlvSo=; b=RCIU1c9twcgUyu8xWSGoBqc1+Ll+jS2kTZxsi8ZcdQpdfUHL6xYzPkq37ePwZw970+ 7vACtwwogWtffhZJ1l0LW0md0ld5NSQ/OVo86/4zcEdjurUI5Qomh/nY4B5TRA5XUi4K HTCo+W6tVc8cpjGrFUre537I1z1rPdaRrlo4bbW8W/HfjK6UyoY1vrWyvdQyytzVsd3D GhA9aPmM+o0oLcjtCW12iJBDbSvsKMB2EhtbUiDVkUiexyw7rptedhoHeJSc7GWQmGPR /nOMH5+Q0RD7sGYp+rSqzoOAHFO3dVbMMWcP9xKTbXhOzoTAHmjIwbioxwihQET6Y/D0 AVPA== X-Forwarded-Encrypted: i=1; AJvYcCXBbD0ZiK/xxkRf8tpsij5lBWQOsj5IFOcVbYOf+f6vpbS4fUdwkafPon3qIy4POWNnGW0ehm4PWNuU9Q4=@vger.kernel.org X-Gm-Message-State: AOJu0YzFoEeSjy332fmSIOGo9h7J803jN2QsoRgTsOuvSOWuxKKdtpHN 7FOcQuaZIQwgcuBsAE8RpM5aVBGb/VXw1mkGDeocdvhKK4z+FCklM2F3 X-Gm-Gg: ATEYQzy4RWbFh/cQH8Fz7WZ4hUCPeCU8H4UkW1w3ntfvMcp9/ucHH3BYUwLXMijmsK8 vK4iq13grqzPQKsGMkITvAFfL5wU9oxg7iMIIGC4SvFdcbS089un84vETuxrCQUm3LRN9RRvC3p o37fG7par4KdkMttUHcZKElNJXlj2q0X1YASxa1TYFn2B3ZPJXPbXBGVqicEEAeIFoOMJSjdJHo eb37QBHW3tH7L/sCUzHrMBPjBuXWmkH59lMsJ9JWzcNNrblte3COrVcCCKfRXqLEON1HbXdgfwo s5eJRoQGaNhPiXWuTcx9y/b8fuPiNEFG81Y2GWhPTVruGbrna0Dh/9VIJoVsv1AM3Jx5IWeDX28 JJEno/CjzWEXFyAb3HEQgODF5DV/lwxgEeE+K7/aFYrWFFlsCi/or9EA/P2Q9x/By5gf9GfORpW HxnrpJi41qlLBmW6RhPFspHYb/oFd+VaI46MVAv5CRh+PHRkMib/nOT6M= X-Received: by 2002:a17:903:3b84:b0:2ad:da28:98d with SMTP id d9443c01a7336-2b0b0aa685fmr63377505ad.37.1774499015189; Wed, 25 Mar 2026 21:23:35 -0700 (PDT) Received: from ryzen ([2601:644:8000:5b5d::8bd]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2b0bc883c0asm15566685ad.45.2026.03.25.21.23.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Mar 2026 21:23:34 -0700 (PDT) From: Rosen Penev To: linux-clk@vger.kernel.org Cc: Michael Turquette , Stephen Boyd , Nobuhiro Iwamatsu , Kees Cook , "Gustavo A. R. Silva" , linux-arm-kernel@lists.infradead.org (moderated list:ARM/TOSHIBA VISCONTI ARCHITECTURE), 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: [PATCH] clk: visconti: pll: use kzalloc_flex Date: Wed, 25 Mar 2026 21:23:17 -0700 Message-ID: <20260326042317.122536-1-rosenp@gmail.com> X-Mailer: git-send-email 2.53.0 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 and kzalloc_flex. Add __counted_by for extra runtime analysis. Assign after allocation as required by __counted_by. Signed-off-by: Rosen Penev Reviewed-by: Brian Masney --- drivers/clk/visconti/pll.c | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/drivers/clk/visconti/pll.c b/drivers/clk/visconti/pll.c index 6fd02c4b641e..ca29d12f9316 100644 --- a/drivers/clk/visconti/pll.c +++ b/drivers/clk/visconti/pll.c @@ -21,9 +21,9 @@ struct visconti_pll { void __iomem *pll_base; spinlock_t *lock; unsigned long flags; - const struct visconti_pll_rate_table *rate_table; size_t rate_count; struct visconti_pll_provider *ctx; + struct visconti_pll_rate_table rate_table[] __counted_by(rate_count); }; #define PLL_CONF_REG 0x0000 @@ -255,10 +255,6 @@ static struct clk_hw *visconti_register_pll(struct vis= conti_pll_provider *ctx, size_t len; int ret; - pll =3D kzalloc_obj(*pll); - if (!pll) - return ERR_PTR(-ENOMEM); - init.name =3D name; init.flags =3D CLK_IGNORE_UNUSED; init.parent_names =3D &parent_name; @@ -266,11 +262,13 @@ static struct clk_hw *visconti_register_pll(struct vi= sconti_pll_provider *ctx, for (len =3D 0; rate_table[len].rate !=3D 0; ) len++; + + pll =3D kzalloc_flex(*pll, rate_table, len); + if (!pll) + return ERR_PTR(-ENOMEM); + pll->rate_count =3D len; - pll->rate_table =3D kmemdup_array(rate_table, - pll->rate_count, sizeof(*pll->rate_table), - GFP_KERNEL); - WARN(!pll->rate_table, "%s: could not allocate rate table for %s\n", __fu= nc__, name); + memcpy(pll->rate_table, rate_table, len * sizeof(*pll->rate_table)); init.ops =3D &visconti_pll_ops; pll->hw.init =3D &init; @@ -282,7 +280,6 @@ static struct clk_hw *visconti_register_pll(struct visc= onti_pll_provider *ctx, ret =3D clk_hw_register(NULL, &pll->hw); if (ret) { pr_err("failed to register pll clock %s : %d\n", name, ret); - kfree(pll->rate_table); kfree(pll); pll_hw_clk =3D ERR_PTR(ret); } -- 2.53.0