Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp9116673pxu; Mon, 28 Dec 2020 07:04:13 -0800 (PST) X-Google-Smtp-Source: ABdhPJxPc8u1O2lkdFL4hrihGhxHqDcGDaHlSF/idAF17QW5fwoYwyrBWQcQ0w+uby1vJpW35nhB X-Received: by 2002:a50:8b02:: with SMTP id l2mr28014360edl.322.1609167852893; Mon, 28 Dec 2020 07:04:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1609167852; cv=none; d=google.com; s=arc-20160816; b=Em4vnDNv6j/E5zh03pqVzj2OyNV0UlAKM72BnJ5thcbTVbSUQnhKbk82U47SpTCBwQ VPnumoPrUtFu1Wws4/gZSPLBD60OKj/zVYzraxpcktElJ9ZXnpt2cxxaE33IsiBmJCSk kB161q//3yXFWZkiv/G7V/KJYuhCWBzj62FSbO0sJX+BFmyDe32qTQbjlWujlkkJCEWm X68S3MuVMD/FIi4jmZ1qhVRXtJnK9ok+UCtl4b4UxnW0mmVP8AK70E5TyNqSBeECek0F RWHKmwWdXJa3b1gZ2PHPhG+FftRnK1EbCEk7Xi4v9/7i2csQy7GIVXrh7Nb4XqtvIcQc zCWg== 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=iKsvNvwN7G1KfLsatNdPTQvcU0oW5S8BcPjRBAWOxNg=; b=JiX74Wb6X8F5DJqvf1tP870VlHKNL7ogBWyWhP3EBOHbWUguy1gO1kbtuZ8QwgjkJx zXSonp5dYmavmU75u6C3x+q+wozN35RcMn9i9Wj0gEYBlGEmzCb3IS5T+bIDq9rw5XDA upNAe256bAPU+in6i509X3WrZJEALkO762EVeZGiAkSLalyoIL4CLHIsiCsjBnMx4aRR lTN9ZSollLPKnE/7NU5K7sfWiuatbMEEcBuG5sMNmFU9ul4dDRAAh/+M8c30PNgwoUCN rQ+dCuXHrwEcJvrFVGy2ko9UTeq/rNF6Q9d72Fep2cmFPPqW4jg3X0cMfbtk+/QHBGQD 1anA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=RY7KiiAR; 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 k18si19658949ejv.477.2020.12.28.07.03.48; Mon, 28 Dec 2020 07:04:12 -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=RY7KiiAR; 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 S2439322AbgL1PBx (ORCPT + 99 others); Mon, 28 Dec 2020 10:01:53 -0500 Received: from mail.kernel.org ([198.145.29.99]:47866 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2440087AbgL1ONL (ORCPT ); Mon, 28 Dec 2020 09:13:11 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 5EB2F20731; Mon, 28 Dec 2020 14:12:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1609164750; bh=2absCxdBc9lJty/YezEDc/n0soFzIq7TEMfSH+GwguM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=RY7KiiAR+es7yq2TC4/S09i7E7engqzWZpFw6VsA/5RKwAX67b1sB1vQs8GUyer42 nohnNS6qofLzMqWpyXJByLBooSVjzaLn5sa5JWdYAGFMHcTEP0iSFjlFBBl+/57BGu h7mj5wZCfVyolsnHAGbDPyDApsdgQLDlHTdHZgUA= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Hulk Robot , Yu Kuai , Daniel Lezcano , Sasha Levin Subject: [PATCH 5.10 286/717] clocksource/drivers/cadence_ttc: Fix memory leak in ttc_setup_clockevent() Date: Mon, 28 Dec 2020 13:44:44 +0100 Message-Id: <20201228125034.731697892@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201228125020.963311703@linuxfoundation.org> References: <20201228125020.963311703@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: Yu Kuai [ Upstream commit eee422c46e6840a81c9db18a497b74387a557b29 ] If clk_notifier_register() failed, ttc_setup_clockevent() will return without freeing 'ttcce', which will leak memory. Fixes: 70504f311d4b ("clocksource/drivers/cadence_ttc: Convert init function to return error") Reported-by: Hulk Robot Signed-off-by: Yu Kuai Signed-off-by: Daniel Lezcano Link: https://lore.kernel.org/r/20201116135123.2164033-1-yukuai3@huawei.com Signed-off-by: Sasha Levin --- drivers/clocksource/timer-cadence-ttc.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/drivers/clocksource/timer-cadence-ttc.c b/drivers/clocksource/timer-cadence-ttc.c index 80e9606020307..4efd0cf3b602d 100644 --- a/drivers/clocksource/timer-cadence-ttc.c +++ b/drivers/clocksource/timer-cadence-ttc.c @@ -413,10 +413,8 @@ static int __init ttc_setup_clockevent(struct clk *clk, ttcce->ttc.clk = clk; err = clk_prepare_enable(ttcce->ttc.clk); - if (err) { - kfree(ttcce); - return err; - } + if (err) + goto out_kfree; ttcce->ttc.clk_rate_change_nb.notifier_call = ttc_rate_change_clockevent_cb; @@ -426,7 +424,7 @@ static int __init ttc_setup_clockevent(struct clk *clk, &ttcce->ttc.clk_rate_change_nb); if (err) { pr_warn("Unable to register clock notifier.\n"); - return err; + goto out_kfree; } ttcce->ttc.freq = clk_get_rate(ttcce->ttc.clk); @@ -455,15 +453,17 @@ static int __init ttc_setup_clockevent(struct clk *clk, err = request_irq(irq, ttc_clock_event_interrupt, IRQF_TIMER, ttcce->ce.name, ttcce); - if (err) { - kfree(ttcce); - return err; - } + if (err) + goto out_kfree; clockevents_config_and_register(&ttcce->ce, ttcce->ttc.freq / PRESCALE, 1, 0xfffe); return 0; + +out_kfree: + kfree(ttcce); + return err; } static int __init ttc_timer_probe(struct platform_device *pdev) -- 2.27.0