Message ID | 20221017165028.4194254-1-dario.binacchi@amarulasolutions.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp1551062wrs; Mon, 17 Oct 2022 10:02:08 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4nQ+8O5UsAaicAdYSiOFTx/fxiZyKUkz+mV5CJIbLp/8OhejLU2MNwFkGrVZKP3qUuezlA X-Received: by 2002:a17:902:708a:b0:183:88dd:1d36 with SMTP id z10-20020a170902708a00b0018388dd1d36mr12435070plk.166.1666026128436; Mon, 17 Oct 2022 10:02:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666026128; cv=none; d=google.com; s=arc-20160816; b=gkGF/tunnKFYm817e5sXDBp/b6H6vtEqzuofkNoDR3zfExS1f/on5movepsnu1Wzot 6GAiZ2h7fDDokXMZmgLZ3ue4Jor2ThLvTf0SHLX9uBgS1vyMJt3A5+9IFXetkbxxDxNq Qv60LEITpRO5HnhSnSHcta1kqMLv5i6zzvKqwb8LaIg5oNDnvZNBW5ShulvLZm7peRsv 4v9Z3b3kmI31kyi4yMP+m3D1KaJeR8/Q3p5U084AhyI7izvNs7UI4a5Lp4VXvf1vIfRe GkpufYl6RxjvZ0j1EY4kGHHd96osG/LSw+8vLJ644JuiaMNSpSqef/ijaHyPzxP3+NiC vxDA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=drbnWG6FnPMKy+1KjZWfuBI6Wm/8lttgnizdA5I4wh0=; b=q1+GmOOzbb9DP+hpzOgt6d+G+lR8zDHAHoXv7R9B4Or8I7vwo3UlNU35nshggWC97s AxyypPckYRFWeb22TVRHhdHHZzP7INzRctE78EYQ1BK8VECSZMKKJSD3cOHteikSGNew 2tSHtDhNCAk7L3t/EftNvl7V2KncWBcUiEsoGOP+raWrxAsN20Bpb29BhDQgwYIyfiW+ 9pdc/6loyaCeV5rr/m7GI+CXIajzvUmPfznVeLk9OwNwzVFqYOzNJ07HJND72Gn4l7NG 6NLIJhLZqoOJIdRqi/m1Z0GzEUHSdEVx+SExiSMWHPggRbN0pvenVVTJf+kvDwR2jcV8 UYVQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=KuVlSmIb; 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=amarulasolutions.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q10-20020a056a00084a00b00561c2d86801si13182153pfk.315.2022.10.17.10.01.54; Mon, 17 Oct 2022 10:02:08 -0700 (PDT) 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=@amarulasolutions.com header.s=google header.b=KuVlSmIb; 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=amarulasolutions.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229780AbiJQQui (ORCPT <rfc822;kernel.ruili@gmail.com> + 99 others); Mon, 17 Oct 2022 12:50:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34888 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229787AbiJQQuf (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Mon, 17 Oct 2022 12:50:35 -0400 Received: from mail-ej1-x62f.google.com (mail-ej1-x62f.google.com [IPv6:2a00:1450:4864:20::62f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 559AC5AC53 for <linux-kernel@vger.kernel.org>; Mon, 17 Oct 2022 09:50:33 -0700 (PDT) Received: by mail-ej1-x62f.google.com with SMTP id y14so26255627ejd.9 for <linux-kernel@vger.kernel.org>; Mon, 17 Oct 2022 09:50:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amarulasolutions.com; s=google; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=drbnWG6FnPMKy+1KjZWfuBI6Wm/8lttgnizdA5I4wh0=; b=KuVlSmIb+mR5CV6eITXFG6u2+ges8sQgbxnm+3vT1lBOjzQyKbr7eP/m0ySlkX1gPv yqRF3Zo8/T7hNqNhLfcWvnEEoYlhY4e6I+bT2Mfh1zGb5qHdQs9PpcpjOrF/mLdw3YtZ 4R153dfRrrKX3ZgPrqYnNF/NRVzUiyp09gv7w= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=drbnWG6FnPMKy+1KjZWfuBI6Wm/8lttgnizdA5I4wh0=; b=eS+/L5CeoKPBoIIQeee1WUxHALwpNS1Ksbc1MXJ9lUXfLqAkKaZL8+o7VCCbWbqrek xUPLH0EW7Tkh8/jU/9A0Y5hpmyCCBua2ohaUfDo308u+VqwYaira3G3Q8VgCu1clET+Z nxPp+gzfLKQ9Y2nbBZbscCc2eW2Ho3rvB76bhhCllFZw3LNwIgpvi0PuMG5yZeZYc9mG L8knTkkHPqUxylb9wlB5+6JVsDEF/jRNLV9TDToUMMmZXRNT0TjknAZgNZH56gmbajFb rvDDqt8EAh+Zg1VCfw0dUvVOCLfm3KTudIT3oenY/uoFcU6YRkBtSQ+fal1P3T1rFBY6 GlJw== X-Gm-Message-State: ACrzQf1LbxHnsKiilXFMkNz4QLiNnbg6GXtIwR+AYWwzFn5SoFudgLtT NNtGG+x7lTcg9et9M3v+G4i40vczZmMGIA== X-Received: by 2002:a17:907:2d1e:b0:78e:2c3b:559f with SMTP id gs30-20020a1709072d1e00b0078e2c3b559fmr9375041ejc.435.1666025431720; Mon, 17 Oct 2022 09:50:31 -0700 (PDT) Received: from dario-ThinkPad-T14s-Gen-2i.homenet.telecomitalia.it (host-95-244-101-110.retail.telecomitalia.it. [95.244.101.110]) by smtp.gmail.com with ESMTPSA id o7-20020a170906774700b0077086d2db8esm6473027ejn.140.2022.10.17.09.50.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Oct 2022 09:50:31 -0700 (PDT) From: Dario Binacchi <dario.binacchi@amarulasolutions.com> To: linux-kernel@vger.kernel.org Cc: michael@amarulasolutions.com, Amarula patchwork <linux-amarula@amarulasolutions.com>, Dario Binacchi <dario.binacchi@amarulasolutions.com>, Allison Randal <allison@lohutok.net>, Miaoqian Lin <linmq006@gmail.com>, Michael Turquette <mturquette@baylibre.com>, Stephen Boyd <sboyd@kernel.org>, Tero Kristo <kristo@kernel.org>, Thomas Gleixner <tglx@linutronix.de>, Tony Lindgren <tony@atomide.com>, linux-clk@vger.kernel.org, linux-omap@vger.kernel.org Subject: [PATCH] clk: ti: dra7-atl: don't allocate `parent_names' variable Date: Mon, 17 Oct 2022 18:50:28 +0200 Message-Id: <20221017165028.4194254-1-dario.binacchi@amarulasolutions.com> X-Mailer: git-send-email 2.32.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS autolearn=unavailable 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: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1746955013802553065?= X-GMAIL-MSGID: =?utf-8?q?1746955013802553065?= |
Series |
clk: ti: dra7-atl: don't allocate `parent_names' variable
|
|
Commit Message
Dario Binacchi
Oct. 17, 2022, 4:50 p.m. UTC
The `parent_names' variable was freed also in case of kzalloc() error.
Instead of modifying the code to perform a proper memory release, I
decided to fix the bug by not allocating memory.
Since only one parent name is referenced, it is not necessary to
allocate this variable at runtime and therefore you can avoid calling
the kzalloc() function. This simplifies the code (even calls to kfree
can be removed) and improves the performance of the routine.
Note: Although no operation is performed by kfree() on a NULL pointer,
it was however suboptimal and semantically wrong doing it.
Signed-off-by: Dario Binacchi <dario.binacchi@amarulasolutions.com>
---
drivers/clk/ti/clk-dra7-atl.c | 14 ++------------
1 file changed, 2 insertions(+), 12 deletions(-)
Comments
Hi Dario, I love your patch! Yet something to improve: [auto build test ERROR on clk/clk-next] [also build test ERROR on linus/master v6.1-rc1 next-20221017] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in https://git-scm.com/docs/git-format-patch#_base_tree_information] url: https://github.com/intel-lab-lkp/linux/commits/Dario-Binacchi/clk-ti-dra7-atl-don-t-allocate-parent_names-variable/20221018-005059 base: https://git.kernel.org/pub/scm/linux/kernel/git/clk/linux.git clk-next patch link: https://lore.kernel.org/r/20221017165028.4194254-1-dario.binacchi%40amarulasolutions.com patch subject: [PATCH] clk: ti: dra7-atl: don't allocate `parent_names' variable config: arm-defconfig compiler: arm-linux-gnueabi-gcc (GCC) 12.1.0 reproduce (this is a W=1 build): wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross # https://github.com/intel-lab-lkp/linux/commit/9eca9eab009687ea2b8cc0d262de7786b6d449b9 git remote add linux-review https://github.com/intel-lab-lkp/linux git fetch --no-tags linux-review Dario-Binacchi/clk-ti-dra7-atl-don-t-allocate-parent_names-variable/20221018-005059 git checkout 9eca9eab009687ea2b8cc0d262de7786b6d449b9 # save the config file mkdir build_dir && cp config build_dir/.config COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.1.0 make.cross W=1 O=build_dir ARCH=arm SHELL=/bin/bash If you fix the issue, kindly add following tag where applicable | Reported-by: kernel test robot <lkp@intel.com> All errors (new ones prefixed by >>): drivers/clk/ti/clk-dra7-atl.c: In function 'of_dra7_atl_clock_setup': >> drivers/clk/ti/clk-dra7-atl.c:190:27: error: assignment to 'const char * const*' from incompatible pointer type 'const char *' [-Werror=incompatible-pointer-types] 190 | init.parent_names = of_clk_get_parent_name(node, 0); | ^ cc1: some warnings being treated as errors vim +190 drivers/clk/ti/clk-dra7-atl.c 162 163 static void __init of_dra7_atl_clock_setup(struct device_node *node) 164 { 165 struct dra7_atl_desc *clk_hw = NULL; 166 struct clk_init_data init = { NULL }; 167 const char *name; 168 struct clk *clk; 169 170 clk_hw = kzalloc(sizeof(*clk_hw), GFP_KERNEL); 171 if (!clk_hw) { 172 pr_err("%s: could not allocate dra7_atl_desc\n", __func__); 173 return; 174 } 175 176 clk_hw->hw.init = &init; 177 clk_hw->divider = 1; 178 name = ti_dt_clk_name(node); 179 init.name = name; 180 init.ops = &atl_clk_ops; 181 init.flags = CLK_IGNORE_UNUSED; 182 init.num_parents = of_clk_get_parent_count(node); 183 184 if (init.num_parents != 1) { 185 pr_err("%s: atl clock %pOFn must have 1 parent\n", __func__, 186 node); 187 goto cleanup; 188 } 189 > 190 init.parent_names = of_clk_get_parent_name(node, 0); 191 192 clk = ti_clk_register(NULL, &clk_hw->hw, name); 193 if (!IS_ERR(clk)) { 194 of_clk_add_provider(node, of_clk_src_simple_get, clk); 195 return; 196 } 197 198 cleanup: 199 kfree(clk_hw); 200 } 201 CLK_OF_DECLARE(dra7_atl_clock, "ti,dra7-atl-clock", of_dra7_atl_clock_setup); 202
diff --git a/drivers/clk/ti/clk-dra7-atl.c b/drivers/clk/ti/clk-dra7-atl.c index ff4d6a951681..ec2473069143 100644 --- a/drivers/clk/ti/clk-dra7-atl.c +++ b/drivers/clk/ti/clk-dra7-atl.c @@ -164,7 +164,6 @@ static void __init of_dra7_atl_clock_setup(struct device_node *node) { struct dra7_atl_desc *clk_hw = NULL; struct clk_init_data init = { NULL }; - const char **parent_names = NULL; const char *name; struct clk *clk; @@ -188,24 +187,15 @@ static void __init of_dra7_atl_clock_setup(struct device_node *node) goto cleanup; } - parent_names = kzalloc(sizeof(char *), GFP_KERNEL); - - if (!parent_names) - goto cleanup; - - parent_names[0] = of_clk_get_parent_name(node, 0); - - init.parent_names = parent_names; + init.parent_names = of_clk_get_parent_name(node, 0); clk = ti_clk_register(NULL, &clk_hw->hw, name); - if (!IS_ERR(clk)) { of_clk_add_provider(node, of_clk_src_simple_get, clk); - kfree(parent_names); return; } + cleanup: - kfree(parent_names); kfree(clk_hw); } CLK_OF_DECLARE(dra7_atl_clock, "ti,dra7-atl-clock", of_dra7_atl_clock_setup);