Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp1239011pxu; Mon, 23 Nov 2020 15:37:58 -0800 (PST) X-Google-Smtp-Source: ABdhPJyIU1z8eqdn17F6xnzgX8T35mAZaWepmrdlQk20rp/pYRTKuaL1RgVnXAy0gEcoSg9h/Exr X-Received: by 2002:aa7:c249:: with SMTP id y9mr119101edo.67.1606174678506; Mon, 23 Nov 2020 15:37:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1606174678; cv=none; d=google.com; s=arc-20160816; b=C+wdpNR8a1pD6TorWHT1zJU08T55itL4xwLYQoX4i2qjPHWJvhOevNq3EDRZ6n8kgZ 4uAY8mn+5mAcNY4d4DI9j0LKWc1cNK85kYLTKuVGWrDz1X2ZU3r4ubhuuXgtOOEhBYrL kGGjln835Se+e+8hNrbAKudnnqj2yhsf7Se1OxiuZ5sei5xwfvRfZBzOgQK2/+OuOQ8J 3AXAWgA0FrOIQcdzD8PRaYB/0Rg9thoSpnbgupHxAZRKVIBK8SR861iV+Dt0BVW2NTvI tCWbvEWBwut5uxpsdqjj4UDwqSNI22jtjjOqR1fLhQJrWA0XBbSX8jrA+LfTEZP+E3kd qh7g== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=Y4B4J4EzmNALNKl62/xLtdIty+yu5qSB8KJ8R8krRyg=; b=FlDqE7Pc4gyRoap5Pa1XVIzBsrEVYCpn9na0cUasn72bSQMOYFz2JoizmlVS/9B8QJ G0cQJoAA8orfQ+9ChogcgAWkJgpLN/lX4CsMRZj8i3ggPKpUVhYycFDic5dsrl59e+Z1 UCd3Q1yfPz16/Pu7DoSLVGZeTIMpinPhXeXodG+xa3ogykEp5LmTySVo06hgX1FdG1Fx HYFAFkt3LAqjSR/9Gom0ZhMCiax0HqNKz/rMq6I2mdq1MCHRfKQMjZjjK8vopxMTVOl8 PYRWQMGFplmXi0Xtzh6WbdQBqvDw6xqbTn1UG+dBEpdNU5V5mWR8WY/qutMZg9jU+M7m 8StA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=r55s+8W6; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id o8si7744617edh.211.2020.11.23.15.37.36; Mon, 23 Nov 2020 15:37:58 -0800 (PST) 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; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=r55s+8W6; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732271AbgKWMja (ORCPT + 99 others); Mon, 23 Nov 2020 07:39:30 -0500 Received: from mail.kernel.org ([198.145.29.99]:51606 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732156AbgKWMjA (ORCPT ); Mon, 23 Nov 2020 07:39:00 -0500 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id D6D392065E; Mon, 23 Nov 2020 12:38:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1606135137; bh=7JO9uOpcLBR7PUZiMnMGHVYjoeNjrgGy7T35VmKE4Uk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=r55s+8W6Qmjl8YrQNJXVrO34oI2tLe0HZoHIrn23m7S/GyMTXjHjkisrIsFO265HT FWYAb3F2X/cxCZHHrW/cfcRZEMfU8s4reYhEEACm/HbSaRaqitcPFLoJITBHwIbzae z78wkKJDQAe0CyuQzpTe20nqSUER+eOsqCpq3MMg= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Hulk Robot , Zhang Qilong , Thomas Bogendoerfer , Sasha Levin Subject: [PATCH 5.4 090/158] MIPS: Alchemy: Fix memleak in alchemy_clk_setup_cpu Date: Mon, 23 Nov 2020 13:21:58 +0100 Message-Id: <20201123121824.273280943@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201123121819.943135899@linuxfoundation.org> References: <20201123121819.943135899@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Zhang Qilong [ Upstream commit ac3b57adf87ad9bac7e33ca26bbbb13fae1ed62b ] If the clk_register fails, we should free h before function returns to prevent memleak. Fixes: 474402291a0ad ("MIPS: Alchemy: clock framework integration of onchip clocks") Reported-by: Hulk Robot Signed-off-by: Zhang Qilong Signed-off-by: Thomas Bogendoerfer Signed-off-by: Sasha Levin --- arch/mips/alchemy/common/clock.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/arch/mips/alchemy/common/clock.c b/arch/mips/alchemy/common/clock.c index a95a894aceaf1..f0c8303371047 100644 --- a/arch/mips/alchemy/common/clock.c +++ b/arch/mips/alchemy/common/clock.c @@ -152,6 +152,7 @@ static struct clk __init *alchemy_clk_setup_cpu(const char *parent_name, { struct clk_init_data id; struct clk_hw *h; + struct clk *clk; h = kzalloc(sizeof(*h), GFP_KERNEL); if (!h) @@ -164,7 +165,13 @@ static struct clk __init *alchemy_clk_setup_cpu(const char *parent_name, id.ops = &alchemy_clkops_cpu; h->init = &id; - return clk_register(NULL, h); + clk = clk_register(NULL, h); + if (IS_ERR(clk)) { + pr_err("failed to register clock\n"); + kfree(h); + } + + return clk; } /* AUXPLLs ************************************************************/ -- 2.27.0