From patchwork Mon Oct 17 16:50:28 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dario Binacchi X-Patchwork-Id: 2440 Return-Path: X-Original-To: linux-amarula@patchwork.amarulasolutions.com Delivered-To: linux-amarula@patchwork.amarulasolutions.com Received: from mail-ej1-f70.google.com (mail-ej1-f70.google.com [209.85.218.70]) by ganimede.amarulasolutions.com (Postfix) with ESMTPS id 36F604147A for ; Mon, 17 Oct 2022 18:50:33 +0200 (CEST) Received: by mail-ej1-f70.google.com with SMTP id he6-20020a1709073d8600b0078e20190301sf3893337ejc.22 for ; Mon, 17 Oct 2022 09:50:33 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1666025433; cv=pass; d=google.com; s=arc-20160816; b=Ffay+cxgNpNU4MFEzI5IeetmQUdu0bhTN2LYVfl56R6RO68WBMWhBahmqBKLAR87JB wEgUSyii2uHcGBm8kE+ca+AoMiLXFM8SEyXyAQdGKJ0d/uEBhDgJk4cbp3lpAuuVpvtq BUCUFyAwMWSqwYLoTLYcqJ/vHb7fvyPO2br+RhVssDAl490b7uR3IL+gxx/zF8GrMBmm S1RSclcBjSaK8qEVLOxbY9JeEV3cmUozw9J60CWKm3i9VPUIjEP5W4MvvgBD/ZarSaoZ ZGs24gU2aJfVNIWIwfZO7f78RxOt0PQjCoavu/AtaBEGKWkdYs6W7n62r8SyhXlmFYMw 2oKw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-unsubscribe:list-archive:list-help:list-post:list-id :mailing-list:precedence:mime-version:message-id:date:subject:cc:to :from:dkim-signature; bh=iMDdvVFXJqAWLiPxGaHz8YyAb0VjGrgDHokpM4xv1hw=; b=rimltKTAJUJuw6F8wBo+Ghg+zbR8Lh3wlMO6NF4pLzc+d3dvYu/80OY94Gv2dgN3ui ILVOiza7sopUBp89NyQVVr8S77vGvQCkudHfq1JJWiDtbVlt+L8r4V3Osbe6io/PF1P6 aZMV5beaF+qJg8WCNk1sWg5h3OpywBxSW80YRSOwYns2auTlVdD2Vp2+O28OBKLibPYn MhQw+czlQWTTBRTKygdSV3IqsVS8qhcvuRy4o07msde0XBAor3TdWMe56xMkE2wMKII1 z68f1JtBijxwLW6/+L4HXJRrJe3+aYDFeXzZmtV5s5uajYY9qI6kgbhKqb42isRLhyDQ fMtg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=KuVlSmIb; spf=pass (google.com: domain of dario.binacchi@amarulasolutions.com designates 209.85.220.41 as permitted sender) smtp.mailfrom=dario.binacchi@amarulasolutions.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=amarulasolutions.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amarulasolutions.com; s=google; h=list-unsubscribe:list-archive:list-help:list-post:list-id :mailing-list:precedence:x-original-authentication-results :x-original-sender:mime-version:message-id:date:subject:cc:to:from :from:to:cc:subject:date:message-id:reply-to; bh=iMDdvVFXJqAWLiPxGaHz8YyAb0VjGrgDHokpM4xv1hw=; b=rGAesh9rHFyoq6miP3LVyz77YbtGD3LGad0N+Lf4DZ07epNcrc16lTMhjblJUG18pM /zdUcc+aIH3geWJHTnFac3FhLFbVh4fOVA186xdJOKOdIciIH5AJaQY3vqBscxvhgWGu z/j2NsOqlnZLtiqv3NdSxlBEp3pBQEGwQEaqc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=list-unsubscribe:list-archive:list-help:list-post :x-spam-checked-in-group:list-id:mailing-list:precedence :x-original-authentication-results:x-original-sender:mime-version :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=iMDdvVFXJqAWLiPxGaHz8YyAb0VjGrgDHokpM4xv1hw=; b=Bn2b9N3AmVMIx8p+zGP/ot75YboXb1IRg/mFRDlZfpYm3bH/mcWRi5X8Ccg/oNa0Al XIThc7SNtPKnyltMRc/E4nKdnDtgciVBsTvm1wEJHAEFwQTuPClFVC2YDl2T/u/4J8rd nVlyJlNrcRZzr1JM7QejXYsr29lGSFzz8oc5jaqZynxLclNux9DQdaERDnhxSaA7Ghzr GPAvdSZKwQLOKcNwE4fbnkBoep/VrjOit5WjL+0EhOD+sQXIIZlsx+5YnLiFd9mtajnm cdTcnh6zlauId8DnA5j+SrMhVRz9PmXHl/WiyBIACx1KQtdCo7/5mvfxx2egQWwL8K94 ZWtg== X-Gm-Message-State: ACrzQf2hZKF/yAkwO+Mg+MrS1q3AhsRqaEZRrjveODJ6JD46GsWfzR5j xMxZH8hjUJlmTjZpaSyhvtkD/Xy8 X-Google-Smtp-Source: AMsMyM5pEJm1Vt2BDpApQElvMs3GpTFBBEKV+DrCsO8ZxVIGUNmxRqrHHelOdzWL6gbVeb9N7dULyg== X-Received: by 2002:a05:6402:ca:b0:45c:dbdd:8143 with SMTP id i10-20020a05640200ca00b0045cdbdd8143mr11103308edu.213.1666025433003; Mon, 17 Oct 2022 09:50:33 -0700 (PDT) X-BeenThere: linux-amarula@amarulasolutions.com Received: by 2002:a17:906:c301:b0:783:b20:46a0 with SMTP id s1-20020a170906c30100b007830b2046a0ls6057093ejz.6.-pod-prod-gmail; Mon, 17 Oct 2022 09:50:32 -0700 (PDT) X-Received: by 2002:a17:907:daa:b0:78d:9bc9:7d7a with SMTP id go42-20020a1709070daa00b0078d9bc97d7amr9175806ejc.567.1666025431941; Mon, 17 Oct 2022 09:50:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666025431; cv=none; d=google.com; s=arc-20160816; b=Lx3Zit1lw4HScRKKQQ7DPdnoy/eloR155vEBSoj5yMnM2Vc85OLru1cheCf8OuFJyQ F6lvaxDg51xLwLRgr9bqFdLQy8m6ibv7HA9hQ2n0rYSmJXJpMMysEv8iuPQyuPP6Wu+4 j21a/bAVaoo9gbynkwaLgSR1A69sKh36/RBv4f/Ahp7MvXG2wA1o31JTmXt16LAvq+tU RizJzD8DJ5LkQlHYrMRtt0bC16t8EdpvXJBO7GNnAFag4sbHJcts/QzXyH4PlTi3e1CI wUzd1vuu2dPsg0OmjlY6jXnsg1Jg+Oti6JHh/ptOrKAQM6czG6oASCMst/Qc+sU2B3kv VYGg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:dkim-signature; bh=drbnWG6FnPMKy+1KjZWfuBI6Wm/8lttgnizdA5I4wh0=; b=DbCtcXX2pF2tHCdeIWMpF+TlB0A/jEp7wvcycEpQNLtNX7Qf25S+9t37bMJX+i2Fds 2OgfEHTXlr2t+wUvDSI5JR2lhHHmwZvan262uldHya/gtzRIlGvplqqWhWg/Mv1EW3xx o9I5EW7T/cHIWDenGlOP3zSOEl8vYb0nozzcnhdC93LPfLgnVZi3mY76gATBjVc41q1Z 5WGSY5N3Je+g49G7Mn8OCDJdK7RNGEBaG8NITuqFYXkt+iv3TFiqVoht9Q8aEuq0ruok eNv7TZTg1ZRaxi66om1sO5EGpUxVXWjaOhfLi4L8pVo1NQr5b1j9Luc3b0VOwcBWi9XE uX1w== 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 dario.binacchi@amarulasolutions.com designates 209.85.220.41 as permitted sender) smtp.mailfrom=dario.binacchi@amarulasolutions.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=amarulasolutions.com Received: from mail-sor-f41.google.com (mail-sor-f41.google.com. [209.85.220.41]) by mx.google.com with SMTPS id b25-20020a17090630d900b0078da3cc381esor3892683ejb.112.2022.10.17.09.50.31 for (Google Transport Security); Mon, 17 Oct 2022 09:50:31 -0700 (PDT) Received-SPF: pass (google.com: domain of dario.binacchi@amarulasolutions.com designates 209.85.220.41 as permitted sender) client-ip=209.85.220.41; 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 To: linux-kernel@vger.kernel.org Cc: michael@amarulasolutions.com, Amarula patchwork , Dario Binacchi , Allison Randal , Miaoqian Lin , Michael Turquette , Stephen Boyd , Tero Kristo , Thomas Gleixner , Tony Lindgren , 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 X-Original-Sender: dario.binacchi@amarulasolutions.com X-Original-Authentication-Results: mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=KuVlSmIb; spf=pass (google.com: domain of dario.binacchi@amarulasolutions.com designates 209.85.220.41 as permitted sender) smtp.mailfrom=dario.binacchi@amarulasolutions.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=amarulasolutions.com Content-Type: text/plain; charset="UTF-8" Precedence: list Mailing-list: list linux-amarula@amarulasolutions.com; contact linux-amarula+owners@amarulasolutions.com List-ID: X-Spam-Checked-In-Group: linux-amarula@amarulasolutions.com X-Google-Group-Id: 476853432473 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , 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 --- drivers/clk/ti/clk-dra7-atl.c | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) 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);