From patchwork Fri Apr 23 06:25:01 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe JAILLET X-Patchwork-Id: 12219713 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 072F2C433B4 for ; Fri, 23 Apr 2021 06:25:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id DBB0061154 for ; Fri, 23 Apr 2021 06:25:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230113AbhDWGZk (ORCPT ); Fri, 23 Apr 2021 02:25:40 -0400 Received: from smtp02.smtpout.orange.fr ([80.12.242.124]:31495 "EHLO smtp.smtpout.orange.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240641AbhDWGZj (ORCPT ); Fri, 23 Apr 2021 02:25:39 -0400 Received: from localhost.localdomain ([86.243.172.93]) by mwinf5d49 with ME id w6R22400i21Fzsu036R3ju; Fri, 23 Apr 2021 08:25:03 +0200 X-ME-Helo: localhost.localdomain X-ME-Auth: Y2hyaXN0b3BoZS5qYWlsbGV0QHdhbmFkb28uZnI= X-ME-Date: Fri, 23 Apr 2021 08:25:03 +0200 X-ME-IP: 86.243.172.93 From: Christophe JAILLET To: mturquette@baylibre.com, sboyd@kernel.org, gregory.clement@bootlin.com, thomas.petazzoni@free-electrons.com Cc: linux-clk@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org, Christophe JAILLET Subject: [PATCH 1/4] clk: mvebu: Fix a memory leak in an error handling path Date: Fri, 23 Apr 2021 08:25:01 +0200 Message-Id: <27db232fdd14e14d493f29a5404d9e643f09cc96.1619157996.git.christophe.jaillet@wanadoo.fr> X-Mailer: git-send-email 2.27.0 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-clk@vger.kernel.org If an error occurs in the for_each loop, clk_name must be freed. In order to do so, sightly rearrange the code: - move the allocation to simplify error handling - use kasprintf instead of kzalloc/sprintf to simplify code and avoid a magic number Fixes: ab8ba01b3fe5 ("clk: mvebu: add armada-370-xp CPU specific clocks") Signed-off-by: Christophe JAILLET --- The { } around the 1 line block after kasprintf is intentional and makes sense with 2/2 --- drivers/clk/mvebu/clk-cpu.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/drivers/clk/mvebu/clk-cpu.c b/drivers/clk/mvebu/clk-cpu.c index c2af3395cf13..a11d7273fcc7 100644 --- a/drivers/clk/mvebu/clk-cpu.c +++ b/drivers/clk/mvebu/clk-cpu.c @@ -195,17 +195,17 @@ static void __init of_cpu_clk_setup(struct device_node *node) for_each_of_cpu_node(dn) { struct clk_init_data init; struct clk *clk; - char *clk_name = kzalloc(5, GFP_KERNEL); + char *clk_name; int cpu, err; - if (WARN_ON(!clk_name)) - goto bail_out; - err = of_property_read_u32(dn, "reg", &cpu); if (WARN_ON(err)) goto bail_out; - sprintf(clk_name, "cpu%d", cpu); + clk_name = kasprintf(GFP_KERNEL, "cpu%d", cpu); + if (WARN_ON(!clk_name)) { + goto bail_out; + } cpuclk[cpu].parent_name = of_clk_get_parent_name(node, 0); cpuclk[cpu].clk_name = clk_name; From patchwork Fri Apr 23 06:25:10 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe JAILLET X-Patchwork-Id: 12219715 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id DD689C433ED for ; Fri, 23 Apr 2021 06:25:22 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B235061458 for ; Fri, 23 Apr 2021 06:25:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240729AbhDWGZz (ORCPT ); Fri, 23 Apr 2021 02:25:55 -0400 Received: from smtp02.smtpout.orange.fr ([80.12.242.124]:38242 "EHLO smtp.smtpout.orange.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236961AbhDWGZt (ORCPT ); Fri, 23 Apr 2021 02:25:49 -0400 Received: from localhost.localdomain ([86.243.172.93]) by mwinf5d49 with ME id w6RC2400421Fzsu036RCl9; Fri, 23 Apr 2021 08:25:12 +0200 X-ME-Helo: localhost.localdomain X-ME-Auth: Y2hyaXN0b3BoZS5qYWlsbGV0QHdhbmFkb28uZnI= X-ME-Date: Fri, 23 Apr 2021 08:25:12 +0200 X-ME-IP: 86.243.172.93 From: Christophe JAILLET To: mturquette@baylibre.com, sboyd@kernel.org, gregory.clement@bootlin.com, thomas.petazzoni@free-electrons.com Cc: linux-clk@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org, Christophe JAILLET Subject: [PATCH 2/4] clk: mvebu: Fix a another memory leak in an error handling path Date: Fri, 23 Apr 2021 08:25:10 +0200 Message-Id: <5f1ba3fb1950a2743ec8c4baa4b4925f134c0f28.1619157996.git.christophe.jaillet@wanadoo.fr> X-Mailer: git-send-email 2.27.0 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-clk@vger.kernel.org If we exit the for_each_of_cpu_node loop early, the reference on the current node must be decremented, otherwise there is a leak. Fixes: ab8ba01b3fe5 ("clk: mvebu: add armada-370-xp CPU specific clocks") Signed-off-by: Christophe JAILLET --- drivers/clk/mvebu/clk-cpu.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/drivers/clk/mvebu/clk-cpu.c b/drivers/clk/mvebu/clk-cpu.c index a11d7273fcc7..9a5c2aec6ec2 100644 --- a/drivers/clk/mvebu/clk-cpu.c +++ b/drivers/clk/mvebu/clk-cpu.c @@ -199,11 +199,14 @@ static void __init of_cpu_clk_setup(struct device_node *node) int cpu, err; err = of_property_read_u32(dn, "reg", &cpu); - if (WARN_ON(err)) + if (WARN_ON(err)) { + of_node_put(dn); goto bail_out; + } clk_name = kasprintf(GFP_KERNEL, "cpu%d", cpu); if (WARN_ON(!clk_name)) { + of_node_put(dn); goto bail_out; } @@ -222,8 +225,10 @@ static void __init of_cpu_clk_setup(struct device_node *node) init.num_parents = 1; clk = clk_register(NULL, &cpuclk[cpu].hw); - if (WARN_ON(IS_ERR(clk))) + if (WARN_ON(IS_ERR(clk))) { + of_node_put(dn); goto bail_out; + } clks[cpu] = clk; } clk_data.clk_num = MAX_CPU; From patchwork Fri Apr 23 06:25:18 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe JAILLET X-Patchwork-Id: 12219717 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C7AEBC433B4 for ; Fri, 23 Apr 2021 06:25:32 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id AAA9E6144A for ; Fri, 23 Apr 2021 06:25:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240756AbhDWG0H (ORCPT ); Fri, 23 Apr 2021 02:26:07 -0400 Received: from smtp02.smtpout.orange.fr ([80.12.242.124]:27719 "EHLO smtp.smtpout.orange.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240752AbhDWGZ5 (ORCPT ); Fri, 23 Apr 2021 02:25:57 -0400 Received: from localhost.localdomain ([86.243.172.93]) by mwinf5d49 with ME id w6RL2400421Fzsu036RLls; Fri, 23 Apr 2021 08:25:20 +0200 X-ME-Helo: localhost.localdomain X-ME-Auth: Y2hyaXN0b3BoZS5qYWlsbGV0QHdhbmFkb28uZnI= X-ME-Date: Fri, 23 Apr 2021 08:25:20 +0200 X-ME-IP: 86.243.172.93 From: Christophe JAILLET To: mturquette@baylibre.com, sboyd@kernel.org, gregory.clement@bootlin.com, thomas.petazzoni@free-electrons.com Cc: linux-clk@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org, Christophe JAILLET Subject: [PATCH 3/4] clk: mvebu: Add a missing space Date: Fri, 23 Apr 2021 08:25:18 +0200 Message-Id: <39826a4aaf2b1769d7ff95301a25eab4adc98535.1619157996.git.christophe.jaillet@wanadoo.fr> X-Mailer: git-send-email 2.27.0 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-clk@vger.kernel.org Fix a checkpatch warning. Add a missing space. Signed-off-by: Christophe JAILLET --- drivers/clk/mvebu/clk-cpu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/clk/mvebu/clk-cpu.c b/drivers/clk/mvebu/clk-cpu.c index 9a5c2aec6ec2..55a8486f665f 100644 --- a/drivers/clk/mvebu/clk-cpu.c +++ b/drivers/clk/mvebu/clk-cpu.c @@ -238,7 +238,7 @@ static void __init of_cpu_clk_setup(struct device_node *node) return; bail_out: kfree(clks); - while(ncpus--) + while (ncpus--) kfree(cpuclk[ncpus].clk_name); clks_out: kfree(cpuclk); From patchwork Fri Apr 23 06:25:26 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe JAILLET X-Patchwork-Id: 12219719 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 034F8C433B4 for ; Fri, 23 Apr 2021 06:25:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id CEE726144D for ; Fri, 23 Apr 2021 06:25:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240770AbhDWG0I (ORCPT ); Fri, 23 Apr 2021 02:26:08 -0400 Received: from smtp02.smtpout.orange.fr ([80.12.242.124]:53938 "EHLO smtp.smtpout.orange.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240708AbhDWG0F (ORCPT ); Fri, 23 Apr 2021 02:26:05 -0400 Received: from localhost.localdomain ([86.243.172.93]) by mwinf5d49 with ME id w6RT2400Y21Fzsu036RUmj; Fri, 23 Apr 2021 08:25:28 +0200 X-ME-Helo: localhost.localdomain X-ME-Auth: Y2hyaXN0b3BoZS5qYWlsbGV0QHdhbmFkb28uZnI= X-ME-Date: Fri, 23 Apr 2021 08:25:28 +0200 X-ME-IP: 86.243.172.93 From: Christophe JAILLET To: mturquette@baylibre.com, sboyd@kernel.org, gregory.clement@bootlin.com, thomas.petazzoni@free-electrons.com Cc: linux-clk@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org, Christophe JAILLET Subject: [PATCH 4/4] clk: mvebu: Remove an unneeded include Date: Fri, 23 Apr 2021 08:25:26 +0200 Message-Id: <0dfcf67d0afe0cd58fd267ef0c4ec0d0414b6fe7.1619157996.git.christophe.jaillet@wanadoo.fr> X-Mailer: git-send-email 2.27.0 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-clk@vger.kernel.org Compiling without just works fine, so remove it Signed-off-by: Christophe JAILLET --- Completely speculative, but compilation works for me without this include --- drivers/clk/mvebu/clk-cpu.c | 1 - 1 file changed, 1 deletion(-) diff --git a/drivers/clk/mvebu/clk-cpu.c b/drivers/clk/mvebu/clk-cpu.c index 55a8486f665f..4879458c768a 100644 --- a/drivers/clk/mvebu/clk-cpu.c +++ b/drivers/clk/mvebu/clk-cpu.c @@ -16,7 +16,6 @@ #include #include #include -#include #define SYS_CTRL_CLK_DIVIDER_CTRL_OFFSET 0x0 #define SYS_CTRL_CLK_DIVIDER_CTRL_RESET_ALL 0xff