From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pf1-f169.google.com (mail-pf1-f169.google.com [209.85.210.169]) (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 E2D7437F731 for ; Mon, 29 Jun 2026 03:25:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.169 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782703548; cv=none; b=CS63QBCXaab+y4+46DEsv4sa8Uy74VBxrkhpJ6KEZf3YZ7/6XNF9uu1fi/75QQQGQTNImPCvxfUUXsVk4taVjyUrxqy1c9T0bfwJuQHywf+pRvqyJxpss5zjso0EyNVqfSKrOz6ZrrulIm6pAEu8Y0S0ITxYPRWwDFVGXHoKIqo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782703548; c=relaxed/simple; bh=JXP8l6SZOlYJ3RZ86oWzg8ag9M+Lc2vnpFBpDW52rRs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Ixd1T6pJH47LUco5qLqFY5Fwc6soIWnFGucKN+mOHb5gUwHCcdubxTxZGcdZxY/B6CP1thmxJkKQ5bU06N144ZNgStMbLitvcaKnHjgS0Z8go5Vg5swAksdsduxxrMATEttDLAy4u8ABlmiW8oRDyf+/v2Rs3tUrqw4ioDnSdrM= 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=ZjfTpbM2; arc=none smtp.client-ip=209.85.210.169 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="ZjfTpbM2" Received: by mail-pf1-f169.google.com with SMTP id d2e1a72fcca58-8475eca3a66so639146b3a.2 for ; Sun, 28 Jun 2026 20:25:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1782703546; x=1783308346; 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=ZjfTpbM2M/CUQT/bbrx7V6a1X5PgPt8xFgCQDbW5ZV7ZgqH3EeX79H+yG9KbBvqZ3u FosDl0qkUuQlVsSrcZs2fscAIW6JnFAdYVxItTR3OIu8AfIdHuLHF9w3fFbBnBlR+Gbo 4lPFV2yRBl4vpfOqaEtJx6eSaFoLNhCOaV4AKYlaQ+8JwlIs9CS8c6m2dt5G5aRPvSoT wcpQBPI3wx1uLBXmd4lu2N5df+tgrtIfGOedOKbTMhHf0emlN9WjQzLpOOp7yV+R4IJc EKCUhr8gLxBOAzLiMGnFzYxx6fr3lwPhRpxDEviw3eePlV2snmT3oiCaBE/OqtYwie5l yCfQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1782703546; x=1783308346; 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=g4gJ835e7/a8y/rECl3Boi6aGAMWiAcNWTnWm4LneRpwVfAbYYQIEWmQdtCoT4m4lT MmmMna9mX2BHarQtagAuXwbV/I9W97NXrzhRDLgOu01d7iexSZe35pjuYtF1Hjk1aXO6 YxWvb58+54/6z/iyjruISLwtuls0ZrAngqMtuJyOUoSeZ9T1jLwVbSEUq1mCCBMO++jp GbcNizE8N2a0OpIt6dCo4WaIdM6n/Tk8/ENJlVmkRSWlTqqCi1S19varRfPE6RFkqcaZ 1OHRpXoTJBnHO7IYl9FrT2gnm0cqTiHN/NzICcdzX67mmE/dCJw8yDDS12R7VCH5IUGA lmlQ== X-Forwarded-Encrypted: i=1; AFNElJ+QYN0z5c8ghzIpS3KGtKuhoeEiCSl32GnCUghng194gJ7L7J62CKusuMMMVtZtVzrXXB7QXVZigIrcZMg=@vger.kernel.org X-Gm-Message-State: AOJu0Ywu/VIbVZzQdZee4l0pWtn1rjI82M+Snlmv3/BQ8J3x9SkvAzjb 1ALT3JAPFmopi8Qe8NoIZuLqWBkSqGWZFGfdQ8SWxL50Si71O9nJTRKs X-Gm-Gg: AfdE7cnDqaRnnfs5l/Jd5oj1iF8nHR6NbiACApCb0BujILxPKAc9j8eIB5tViOjM9LF hGPe3tz9U4S7d6cd8s8n1RYZQqHILXyVpMWOeWpMLOGikb6C3eO5nAJ9POGiurry6AYhUyGgslz 4Rry0PRnW0LcGf5c9d2OwiHy7jNvCF2wj+Dac54q6M83C+kD8IkG3sH3jNuuAdibu6zTts/kYPe IWbmvfK9kBp5eYJ4h0xreLCeFu28YRE3SYLadbYWNnetc1daRL+sNnIXACcD51pM3TNLE/RCtmE JVm5cAVSmaD03evrLpqRX7GamNCMaIIARLIvR68y2OJByrfSw8T2bv4OWrSgN9uZP1pnNSecT3T Q6IIEWh3ckz3195xZ7Ye486+bZXckBJxVs7g73CfOZmmL4dHaRvS17gYUElrV1yVbkJqPuei4Ww 5QzMdFPLbyeOjYa/70kWCN97eow2wYlcpIeLofSD/FSU/xF9Z1F1Ah917z5G5ARO5OZm3/rqWNf EiqI3o2Ug== X-Received: by 2002:a05:6a00:ad06:b0:82f:9407:d167 with SMTP id d2e1a72fcca58-845b3b89881mr15596736b3a.38.1782703546147; Sun, 28 Jun 2026 20:25:46 -0700 (PDT) Received: from ryzen.lan ([2601:644:8000:7a86::e34]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-846c7f659ddsm1921771b3a.32.2026.06.28.20.25.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 28 Jun 2026 20:25:45 -0700 (PDT) From: Rosen Penev To: linux-clk@vger.kernel.org Cc: Krzysztof Kozlowski , Sylwester Nawrocki , Chanwoo Choi , Peter Griffin , 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|_ptr)?\b) Subject: [PATCHv3 2/3] clk: samsung: cpu: use kzalloc_flex Date: Sun, 28 Jun 2026 20:25:39 -0700 Message-ID: <20260629032540.2331559-3-rosenp@gmail.com> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260629032540.2331559-1-rosenp@gmail.com> References: <20260629032540.2331559-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: 8bit 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); }; /* ---- Common code --------------------------------------------------------- */ @@ -660,10 +660,6 @@ static int __init exynos_register_cpu_clock(struct samsung_clk_provider *ctx, return -EINVAL; } - cpuclk = kzalloc_obj(*cpuclk); - if (!cpuclk) - return -ENOMEM; - parent_name = clk_hw_get_name(parent); init.name = clk_data->name; @@ -672,6 +668,17 @@ static int __init exynos_register_cpu_clock(struct samsung_clk_provider *ctx, init.num_parents = 1; init.ops = &exynos_cpuclk_clk_ops; + /* Find count of configuration rates in cfg */ + for (num_cfgs = 0; clk_data->cfg[num_cfgs].prate != 0; ) + num_cfgs++; + + cpuclk = kzalloc_flex(*cpuclk, cfg, num_cfgs); + if (!cpuclk) + return -ENOMEM; + + cpuclk->num_cfgs = num_cfgs; + + memcpy(cpuclk->cfg, clk_data->cfg, num_cfgs * sizeof(*cpuclk->cfg)); cpuclk->alt_parent = alt_parent; cpuclk->hw.init = &init; cpuclk->base = ctx->reg_base + clk_data->offset; @@ -687,29 +694,16 @@ static int __init exynos_register_cpu_clock(struct samsung_clk_provider *ctx, goto free_cpuclk; } - /* Find count of configuration rates in cfg */ - for (num_cfgs = 0; clk_data->cfg[num_cfgs].prate != 0; ) - num_cfgs++; - - cpuclk->cfg = kmemdup_array(clk_data->cfg, num_cfgs, sizeof(*cpuclk->cfg), - GFP_KERNEL); - if (!cpuclk->cfg) { - ret = -ENOMEM; - goto unregister_clk_nb; - } - ret = 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; } samsung_clk_add_lookup(ctx, &cpuclk->hw, clk_data->id); return 0; -free_cpuclk_data: - kfree(cpuclk->cfg); unregister_clk_nb: clk_notifier_unregister(parent->clk, &cpuclk->clk_nb); free_cpuclk: -- 2.54.0