Received: by 2002:a05:6358:16cc:b0:ea:6187:17c9 with SMTP id r12csp12198282rwl; Tue, 3 Jan 2023 10:25:58 -0800 (PST) X-Google-Smtp-Source: AMrXdXuuTIjlufBMokF3cyDPt5gzaOKk1ZK/SkrrFdTnvtWC/3Et3R4QnpepVLZjAJyIenwchYh3 X-Received: by 2002:a17:906:2349:b0:7c1:844d:7447 with SMTP id m9-20020a170906234900b007c1844d7447mr38353643eja.35.1672770357888; Tue, 03 Jan 2023 10:25:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672770357; cv=none; d=google.com; s=arc-20160816; b=oeJj9UruLepV/8zT5On6vKxmb+G5idE5SiFBXiqmAMVKeLU5fUBFB96vXBzPKpjgGw uVYoM/JbJD3U3gOqGxSaHwEigiaQzE++eVx2eF226POjFWggMvD+B4HfruSEbHfxaZey koxsDeFW29CXqj/oxRaX1ZOHGW/D5GN4HdClKmcJksb2KDE+37DG79mmCjhL8mDBycAw hsiYvjH6TDFTcVgLwZ9qzGCdshNz2rnMCgl5d1KJCv3+LxA/j4ZkMVJ0iRxTOwDeAMYg S7g+VPbUF0FxHrzPTdp3S13nvHYXva3syiB+7hoG3p72Dvhp/foG/piuvm+mxR1P3/CS Hxig== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=sI8JAG7nAfOS7xM8TCzyaD/yPENHF3AAx2vtRvyhTuU=; b=KYWBLdbxfq4Tzm1uhrk1+8QIz+fMvWJXMkRswGrbxMcWgxW3HyZCGX+rEZX8VV0E9z cOZkEvIxUA+4IObR+dv625de229N1U8Jngj+BKygiAEWqx6op5L6fb22eZBykGLyhUt2 MckM74gpVDIUFwmXwP01Wwg5kNDPqSA2VKe6UeVKtWYZc0beQSvqQdqDrGOWSuZjiFqd 0wFFPjpJhMTr8eZXTo+pMHgxee5DbX2G46u+OCGzaWyrdub3NzG2ZJO1s5WPmUIkuG8r crVu3F2tQbK6g5VLbUBYDg50hhSi6Gq5bY2hMS4Gu1AzcGyV11LxUnW8zFTbdqC0/3nn j2eA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=myWGraxT; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id gt30-20020a1709072d9e00b007c118b2d91dsi31141898ejc.248.2023.01.03.10.25.42; Tue, 03 Jan 2023 10:25:57 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=myWGraxT; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238581AbjACRdC (ORCPT + 61 others); Tue, 3 Jan 2023 12:33:02 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36428 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238579AbjACRcf (ORCPT ); Tue, 3 Jan 2023 12:32:35 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8B71112605; Tue, 3 Jan 2023 09:32:19 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id A42B161488; Tue, 3 Jan 2023 17:32:18 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 862D8C433EF; Tue, 3 Jan 2023 17:32:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1672767138; bh=A5nDrEpe1e6m7M5sQQYdF7NrGQIutL/ZR2MPitemRS0=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=myWGraxTzypbHe8tgM/PuXAcZye01rJD00pPoC+mrHZqWeCK9RSgbqbhHT0VzGhOW /ZIt8opb9Y+sj5GfDHoD9Ae3NEYmHzFoWAY3mx9KxoK3fauQZtu8n2miYHl0qMUk88 56RxoI/e/WpF/55KjOseZZgKdeJB37Denm40Q+P8DqCEc0CDbqOBouDTnVofaQ9Fpc 5oXY/f0FxJnvpLW6UcPLUngeXpokSsJ/M6uXV+X1xZkARvtB1j2T3slX3MB+ZQVclS 5K0c6fmQdqAQtPGRMxzCU4nu/BttnTqSV0NZ9GiQEy2+2su8e3N0ylMmdUuDyD1TcR IphHTOxZGGeTQ== Date: Tue, 3 Jan 2023 17:32:14 +0000 From: Conor Dooley To: Geert Uytterhoeven Cc: Michael Turquette , Stephen Boyd , Claudiu Beznea , Conor Dooley , linux-clk@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] clk: microchip: mpfs-ccc: Use devm_kasprintf() for allocating formatted strings Message-ID: References: MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="YvKQCHSpAD8v+v18" Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org --YvKQCHSpAD8v+v18 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Tue, Jan 03, 2023 at 05:45:30PM +0100, Geert Uytterhoeven wrote: > In various places, string buffers of a fixed size are allocated, and > filled using snprintf() with the same fixed size, which is error-prone. >=20 > Replace this by calling devm_kasprintf() instead, which always uses the > appropriate size. >=20 > While at it, remove an unneeded intermediate variable, which allows us > to drop a cast as a bonus. >=20 > Signed-off-by: Geert Uytterhoeven Reviewed-by: Conor Dooley Tested-by: Conor Dooley I half wonder if this should actually have a fixes tag too. Since it used what came after the @ in $full_name, it'd be possible to create (an incorrect) DTS that would lead to a clash between pll names & therefore probe would fail. The tag would be: Fixes: d39fb172760e ("clk: microchip: add PolarFire SoC fabric clock suppor= t") Either way, thanks for pointing out a function that does exactly what I initially wanted to do but could not find! Glad to be rid of those "oddly specific" allocations. Thanks, Conor. > --- > drivers/clk/microchip/clk-mpfs-ccc.c | 10 ++++------ > 1 file changed, 4 insertions(+), 6 deletions(-) >=20 > diff --git a/drivers/clk/microchip/clk-mpfs-ccc.c b/drivers/clk/microchip= /clk-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 = *dev, 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->nam= e, 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_div= ider_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 *de= v, 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 >=20 >=20 --YvKQCHSpAD8v+v18 Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iHUEABYIAB0WIQRh246EGq/8RLhDjO14tDGHoIJi0gUCY7RmnQAKCRB4tDGHoIJi 0qXMAQCbwp9Fb8Bmn3P56tCHIvNpx+ztMfDWLVpz7Z8bMSjQFgEAiilrMNqmAtuY O4NG4cOO6rC5q55zrR2qsL2ccp0+LwI= =loe4 -----END PGP SIGNATURE----- --YvKQCHSpAD8v+v18--