From nobody Tue Sep 16 12:50:37 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id BCA01C3DA7D for ; Tue, 3 Jan 2023 16:45:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233656AbjACQpi (ORCPT ); Tue, 3 Jan 2023 11:45:38 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59914 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237907AbjACQpf (ORCPT ); Tue, 3 Jan 2023 11:45:35 -0500 Received: from michel.telenet-ops.be (michel.telenet-ops.be [IPv6:2a02:1800:110:4::f00:18]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C09B8DA0 for ; Tue, 3 Jan 2023 08:45:34 -0800 (PST) Received: from ramsan.of.borg ([IPv6:2a02:1810:ac12:ed10:f1ca:ff0d:9dea:806e]) by michel.telenet-ops.be with bizsmtp id 4GlY2900w2YHDVW06GlYRb; Tue, 03 Jan 2023 17:45:33 +0100 Received: from rox.of.borg ([192.168.97.57]) by ramsan.of.borg with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.93) (envelope-from ) id 1pCkPs-00203S-LF; Tue, 03 Jan 2023 17:45:32 +0100 Received: from geert by rox.of.borg with local (Exim 4.93) (envelope-from ) id 1pCkPs-001TJk-68; Tue, 03 Jan 2023 17:45:32 +0100 From: Geert Uytterhoeven To: Michael Turquette , Stephen Boyd , Claudiu Beznea , Conor Dooley Cc: linux-clk@vger.kernel.org, linux-kernel@vger.kernel.org, Geert Uytterhoeven Subject: [PATCH] clk: microchip: mpfs-ccc: Use devm_kasprintf() for allocating formatted strings Date: Tue, 3 Jan 2023 17:45:30 +0100 Message-Id: X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" In various places, string buffers of a fixed size are allocated, and filled using snprintf() with the same fixed size, which is error-prone. Replace this by calling devm_kasprintf() instead, which always uses the appropriate size. While at it, remove an unneeded intermediate variable, which allows us to drop a cast as a bonus. Signed-off-by: Geert Uytterhoeven Reviewed-by: Conor Dooley Tested-by: Conor Dooley --- drivers/clk/microchip/clk-mpfs-ccc.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/drivers/clk/microchip/clk-mpfs-ccc.c b/drivers/clk/microchip/c= lk-mpfs-ccc.c index 32aae880a14f3b1c..0ddc73e07be42973 100644 --- a/drivers/clk/microchip/clk-mpfs-ccc.c +++ b/drivers/clk/microchip/clk-mpfs-ccc.c @@ -164,12 +164,11 @@ static int mpfs_ccc_register_outputs(struct device *d= ev, struct mpfs_ccc_out_hw_ =20 for (unsigned int i =3D 0; i < num_clks; i++) { struct mpfs_ccc_out_hw_clock *out_hw =3D &out_hws[i]; - char *name =3D devm_kzalloc(dev, 23, GFP_KERNEL); + char *name =3D devm_kasprintf(dev, GFP_KERNEL, "%s_out%u", parent->name,= i); =20 if (!name) return -ENOMEM; =20 - snprintf(name, 23, "%s_out%u", parent->name, i); out_hw->divider.hw.init =3D CLK_HW_INIT_HW(name, &parent->hw, &clk_divid= er_ops, 0); out_hw->divider.reg =3D data->pll_base[i / MPFS_CCC_OUTPUTS_PER_PLL] + out_hw->reg_offset; @@ -201,14 +200,13 @@ static int mpfs_ccc_register_plls(struct device *dev,= struct mpfs_ccc_pll_hw_clo =20 for (unsigned int i =3D 0; i < num_clks; i++) { struct mpfs_ccc_pll_hw_clock *pll_hw =3D &pll_hws[i]; - char *name =3D devm_kzalloc(dev, 18, GFP_KERNEL); =20 - if (!name) + pll_hw->name =3D devm_kasprintf(dev, GFP_KERNEL, "ccc%s_pll%u", + strchrnul(dev->of_node->full_name, '@'), i); + if (!pll_hw->name) return -ENOMEM; =20 pll_hw->base =3D data->pll_base[i]; - snprintf(name, 18, "ccc%s_pll%u", strchrnul(dev->of_node->full_name, '@'= ), i); - pll_hw->name =3D (const char *)name; pll_hw->hw.init =3D CLK_HW_INIT_PARENTS_DATA_FIXED_SIZE(pll_hw->name, pll_hw->parents, &mpfs_ccc_pll_ops, 0); --=20 2.25.1