Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp835317pxu; Mon, 23 Nov 2020 05:30:34 -0800 (PST) X-Google-Smtp-Source: ABdhPJymDk00cA5mKhkLzIJYgPELLLZx/ERMwWsmIwe2/aN52BaDDhicPXyzC6qvytrnjcYVZo8s X-Received: by 2002:aa7:d8c4:: with SMTP id k4mr46134004eds.248.1606138233743; Mon, 23 Nov 2020 05:30:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1606138233; cv=none; d=google.com; s=arc-20160816; b=BWrqBGvZjaemx2ZTx4kYf5DBMVrlCrx3ZFBzYibSSVfk5nHKfVECocqJJlIiuF+Kmw yUFErV621crBNLrpLMXsTqF7SmJTO4wDSv5BCe8I4IBSOfkifjW0OddERXTWMQAskRVq elIkKsr1SN2Y2OJMIsEVJZ9HLZ2p6xt8R2doeYSNYnTcpGSi7ADVx67duMBirzgzg5JZ UP3dNWCisB/8knhcAv6djyVfgn1JLvPbJveI9uSFg1W499pDi3gjZYr9c0HqdVQOWwjd nXxpQVNrPViwJGpK/HhG/rXM/f3gySaNz0+lB0CJ5OmOwSPQ3aDc2XdINhvgIZfP/z8H Q40Q== 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=58MdWlGB0PC6hBybkFmA+kr5cnV2ZObmWwbEyvCX8kc=; b=ls7WKLp/Ho3CpFceJf55qT8hjG6uD3pwDc+aTlMPqi4jWzLNCky3ie+mOu72u6z9f1 hX3yyLEPi53BnIz0GYgghdLc2j7HalhgfwL765z3bzWWxcE6uDAWYLgQoZUITohQIBum B+Vibv9TghUBK4vc2QX51a6/RYCpez4rAu0T2/QBwA5Oh3MvtZPz64cO5LRU0AUEn13H VnRKypI+ntQ6JoQGvHrQJ9m/lCcD6dyN8dJcguXtoQ/sZVGjsSsAjqHEz0iGnkzMymhI qVy5mNO2WlyfUktQ0hxBfP82TIMXwM3oLXUeBFx9wkaHzqhMAmHKvdfASuxAB/29BSv9 kerg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=xDgfZGQs; 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 z4si3246457edx.259.2020.11.23.05.30.10; Mon, 23 Nov 2020 05:30:33 -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=xDgfZGQs; 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 S1731010AbgKWN1W (ORCPT + 99 others); Mon, 23 Nov 2020 08:27:22 -0500 Received: from mail.kernel.org ([198.145.29.99]:43090 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730982AbgKWMb4 (ORCPT ); Mon, 23 Nov 2020 07:31:56 -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 2EF44208DB; Mon, 23 Nov 2020 12:31:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1606134715; bh=EXU7sJnhAg4IF3h+mZOvVZLTcZwlXfQZiFgdO0i1qCE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=xDgfZGQsA6ZD5x1iop+kDi1NgKw5jzDGCN7MuzNYFQt1ZW8ilVzzLZ8/mrmW3T7Ei TCHVPI5A7GNC14l5dXs1jrYc+rWvuRDsf8Iio0vG+AuJlH3vzvEX7r9UK4CTte89LF r1OdqOnX9cpedwBU86jIfdtB2QRiFwh+h/FcKhK8= 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 4.19 56/91] MIPS: Alchemy: Fix memleak in alchemy_clk_setup_cpu Date: Mon, 23 Nov 2020 13:22:16 +0100 Message-Id: <20201123121812.045541763@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201123121809.285416732@linuxfoundation.org> References: <20201123121809.285416732@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 d129475fd40de..4254ba13c5c51 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