From nobody Tue Apr 7 14:36:48 2026 Received: from mail-yx1-f41.google.com (mail-yx1-f41.google.com [74.125.224.41]) (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 B5FC6295DA6 for ; Fri, 13 Mar 2026 00:21:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.224.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773361302; cv=none; b=SKjp5XU6znLeSTj/7l0o0KmJ4f29limsc7AtR5/SIKVtD78TLuWwCqlUk2VSnapwOWDATU1zJi72e1t8baeMTLCWDMTUwWny4JBdPjcKUaGp3lLEN8NhFP7gNprrJZCJVMA2FDje1ODzVzO9bNnjK3yd3Vg1N/Gcmav0kKFaL74= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773361302; c=relaxed/simple; bh=1YMiY7/Zot15ra9DuC1CUpjFsA44TAxwB5BjF3e8+FE=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=mwPpJvxMUDcztj7rfODzN94cNdJEkjTi6jv3npi/TIDgjeKdV53XVzDnd2WplHdWWuupKCL3si2mfGMVlC8CGbqGtmJMK0Z05TE+r4lDztDb0Vkoe7yNJG7OxEVgHAwertsRWHBREGslKEEzB8q5bb4NQB+NMagmnX9H+/y35Wc= 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=JpDjyiOs; arc=none smtp.client-ip=74.125.224.41 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="JpDjyiOs" Received: by mail-yx1-f41.google.com with SMTP id 956f58d0204a3-64c9ebd1369so1676291d50.1 for ; Thu, 12 Mar 2026 17:21:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1773361299; x=1773966099; 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=PeETB9eQltddP5mF2mJA8o9tnQJB7YnT8JvFDCE8DGE=; b=JpDjyiOsfK/apRe83gzVuB21pDPIfiTt/JP41PuJV1odsJv0jQuPsjZUr7PQa7hdCU qJJ1JK+Hsjjt6R54V9zmcb08moedlPSk/8Hbtm58+iGPg8WVxe9IF15b6sowI23hm/Fo xx5dbv4vbWP2va5ZTil1s1Jh7bXmgNlmoEn7Qm2QrI6bjHX1rE2c9twg4fDBFLJVGb1R WTDphYV8ja1+7M4G+5iv5Ofsb0Q08dRDUepVqT2d5VN6UGHnDpiCVjtdliumfhf48h0z aGzwObnN/+jWf6UEbyD8+dFvlqmjax+YK5Tp7P9zG4w1coNt1RcqWhCjUsabLQZgNXIN OGEw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1773361299; x=1773966099; 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=PeETB9eQltddP5mF2mJA8o9tnQJB7YnT8JvFDCE8DGE=; b=tBGM6lBfDzpYZAeEWV1y4+G4OvYWJZWAqeMeX2NH0kVO2e7U1/Jzl6ZUitnELP+ryl pjYr4QnDZiL2iEAA9YcxvkyRBsXJmS6T5YMJAtbbEgt6HKqX2tQlhsWKQHhS+lTb2wz2 IutHYqD/hCgHODYPx5kTXKKKHy3z+czKBpLNLrsesdNXE6F5UWLVM51DHUE5CnYX5T9D JgC7WcedzG0aDqEaU8smGhlXj+sLedX6LU67faKRqCipMB1kVClONQIWvyMf9gLGHPtR nYkyD1aYNcD0VsXWAh0S+zZ8mq+XdzNp69wOt8hygpNzIv3fT6M2zkCo9ZGz529RL2SV qO4Q== X-Forwarded-Encrypted: i=1; AJvYcCXZSX20Akk+NqcHrnvH/ZjkltDrDTZZHy+BviZm8CTH5JqIIXhRUtPDJlxexTohDqNV7YNuVL2xYqldGZI=@vger.kernel.org X-Gm-Message-State: AOJu0Yxv4IX/Fk5yo08V8fLkLZv8ESWZMXmgPYP2MTvewo2w1pYSmqni vU9LLL+Ke59HAYosvTqe7noCbkuqCYBNRQP+Fg7Ov0nZRAe/ypcZLU8v X-Gm-Gg: ATEYQzw6LDSOlJrOoeB5/uhYwPijMyRR950/2WB82mkMbmX/Ij3RJeyA/Icrspo2Erx YH0+A4yDTTDjcPfEF6WclcpF3iyv4tLt0j+2YQjdtIIgy0J0eBAPDvQGda05pTVfmvotGeSp0MS HzgkITrKrjbrlkygopCHc7pnshFHC91rzQpNYQkfBS4j1BUQ/lGb1jipi/1SI+FytymUy+vqIu0 0RtQ8FzxGeaGVAGKxl19jcXzYOYTfuXMbPadg/DLXLBhR6mcmn01CO131VFtPw3N3WFpQErTCI5 dUJwsqcUDr6umdSySJz9hTLKOqHWMYtmBi8n+ysnt3DYT6P7ztu6G1l8mCekWVNwmumaYJbrplT 4jE9WgV7AjasBwElY4U0amThSADPdWtRuOlE7jmvPbF1kNBTvp0ZtWk9EpAyosOzPmnIk0HwyPr mN7riD6MT/9/LiZ3otyQI6qE9SQRV+QM33HI0eWDVnm1nVxqRGQKyTAFsiedsw+0dH X-Received: by 2002:a05:690c:c155:b0:799:182:17bd with SMTP id 00721157ae682-79a1c0e1676mr14239947b3.24.1773361298678; Thu, 12 Mar 2026 17:21:38 -0700 (PDT) Received: from ryzen ([2601:644:8000:56f5::8bd]) by smtp.gmail.com with ESMTPSA id 00721157ae682-79917f1ecd9sm39089407b3.45.2026.03.12.17.21.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Mar 2026 17:21:38 -0700 (PDT) From: Rosen Penev To: linux-clk@vger.kernel.org Cc: Michael Turquette , Stephen Boyd , Nicolas Ferre , Alexandre Belloni , Claudiu Beznea , Kees Cook , "Gustavo A. R. Silva" , linux-arm-kernel@lists.infradead.org (moderated list:ARM/Microchip (AT91) SoC support), 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: at91: use kzalloc_flex Date: Thu, 12 Mar 2026 17:21:19 -0700 Message-ID: <20260313002119.118962-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" Convert kzalloc_obj + kcalloc to kzalloc_flex to save an allocation. Add __counted_by to get extra runtime analysis. Move counting variable assignment immediately after allocation as required by __counted_by. Signed-off-by: Rosen Penev --- drivers/clk/at91/dt-compat.c | 15 ++++----------- drivers/clk/at91/pmc.h | 2 +- 2 files changed, 5 insertions(+), 12 deletions(-) diff --git a/drivers/clk/at91/dt-compat.c b/drivers/clk/at91/dt-compat.c index 5d543e807843..5c88cfafa31f 100644 --- a/drivers/clk/at91/dt-compat.c +++ b/drivers/clk/at91/dt-compat.c @@ -548,7 +548,6 @@ of_at91_clk_pll_get_characteristics(struct device_node = *np) int num_output; u32 num_cells; struct clk_range input; - struct clk_range *output; u8 *out =3D NULL; u16 *icpll =3D NULL; struct clk_pll_characteristics *characteristics; @@ -568,13 +567,11 @@ of_at91_clk_pll_get_characteristics(struct device_nod= e *np) return NULL; num_output /=3D num_cells; =20 - characteristics =3D kzalloc_obj(*characteristics); + characteristics =3D kzalloc_flex(*characteristics, output, num_output); if (!characteristics) return NULL; =20 - output =3D kzalloc_objs(*output, num_output); - if (!output) - goto out_free_characteristics; + characteristics->num_output =3D num_output; =20 if (num_cells > 2) { out =3D kcalloc(num_output, sizeof(*out), GFP_KERNEL); @@ -594,12 +591,12 @@ of_at91_clk_pll_get_characteristics(struct device_nod= e *np) "atmel,pll-clk-output-ranges", offset, &tmp)) goto out_free_output; - output[i].min =3D tmp; + charecteristics->output[i].min =3D tmp; if (of_property_read_u32_index(np, "atmel,pll-clk-output-ranges", offset + 1, &tmp)) goto out_free_output; - output[i].max =3D tmp; + charecteristics->output[i].max =3D tmp; =20 if (num_cells =3D=3D 2) continue; @@ -621,8 +618,6 @@ of_at91_clk_pll_get_characteristics(struct device_node = *np) } =20 characteristics->input =3D input; - characteristics->num_output =3D num_output; - characteristics->output =3D output; characteristics->out =3D out; characteristics->icpll =3D icpll; return characteristics; @@ -630,8 +625,6 @@ of_at91_clk_pll_get_characteristics(struct device_node = *np) out_free_output: kfree(icpll); kfree(out); - kfree(output); -out_free_characteristics: kfree(characteristics); return NULL; } diff --git a/drivers/clk/at91/pmc.h b/drivers/clk/at91/pmc.h index 543d7aee8d24..123050b4356d 100644 --- a/drivers/clk/at91/pmc.h +++ b/drivers/clk/at91/pmc.h @@ -75,12 +75,12 @@ extern const struct clk_pll_layout sama5d3_pll_layout; struct clk_pll_characteristics { struct clk_range input; int num_output; - const struct clk_range *output; const struct clk_range *core_output; u16 *icpll; u8 *out; u8 upll : 1; u32 acr; + struct clk_range output[] __counted_by(num_output); }; =20 struct clk_programmable_layout { --=20 2.53.0