Received: by 2002:a05:6a10:a841:0:0:0:0 with SMTP id d1csp1096599pxy; Thu, 22 Apr 2021 23:26:04 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzg6eIRMut2VzYjpNgdIpnP1gprihq4JVvsZEfloeRYQL4GZcf0XjyeicYSpaYYGfEHbQmT X-Received: by 2002:a17:90a:b78d:: with SMTP id m13mr4185481pjr.47.1619159163996; Thu, 22 Apr 2021 23:26:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1619159163; cv=none; d=google.com; s=arc-20160816; b=hCIB31rbGLyrdhVXntKx+0OiobJT91by4GlxZ2daBo/2YMapUWiuFSt0j9CgGbURYb wB2vVky5MyVKNzXUMbz3ChngzwSmYaEtKoa8AlENi+HGCXF9yUqNmhBopfzvcJXV1JG7 WiZKoefwBd7h0Jh7hnXpLSPIwKV+LHgNcFa8oQ5wxsxqe3v4J/vmKTdtViUNwXmH2iGC ZL1lPzj5p7H+P3IePuKNgnOKjPRZSDvEdf07kNqenEMj3nzBkA/RT+9BShD+bc3JF+NY BpgZ6ELguognbCLuUcz/C9CRafPP5ca+svD8y2BEBvC/d6zGFvO9qPNPIfbU/YZ0jyPe Qi6w== 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 :references:in-reply-to:message-id:date:subject:cc:to:from; bh=z1J5YWrEltkKgwnOIBWLJDhg3mmdoS6Gdcvi8HnVrIY=; b=R2Udeq8/fntu+geDEsy5qPdHPxwemKMOKehDoIBUnzhVMi0NN301EvN3Hd04sJJwjQ GrEf1IpUUQMUsHWmezBkUVTaAghQ58TDR/vKZoC5GS+eOV4sEruWwR18ZZI3q2F7T064 YSjoJapfKfedBSqBad9Ga/N1FzKYj+HS7JXirLvEKKpEHfs6vGcY05iQIL7gK4wENSjx ka3EvmWOPyr8T+rS7YTOArhBLXRR5yhZa6mQpYnL9S7iga7TI2+WJftQBa56X8DMbbPk mRkOVzE5OnKdllYGuv9mGEpgO83RkcjhHXflPMe/wWmZMIjfAJP1FYlJa4Agrn35W8Hy i1Cg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id d15si8775703pji.84.2021.04.22.23.25.52; Thu, 22 Apr 2021 23:26:03 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240647AbhDWGZl (ORCPT + 99 others); Fri, 23 Apr 2021 02:25:41 -0400 Received: from smtp02.smtpout.orange.fr ([80.12.242.124]:50770 "EHLO smtp.smtpout.orange.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240645AbhDWGZj (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 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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; -- 2.27.0