Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp9038099pxu; Mon, 28 Dec 2020 05:07:10 -0800 (PST) X-Google-Smtp-Source: ABdhPJzPS+W6rFZE0RpW7vi9cujINb7D6RuhVDO/Qyv5CFMtIan6LeLvmH7Q2L99SedXR8JOjPix X-Received: by 2002:a05:6402:8d9:: with SMTP id d25mr41791513edz.278.1609160830514; Mon, 28 Dec 2020 05:07:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1609160830; cv=none; d=google.com; s=arc-20160816; b=tw9o0+AJbyQQVdntqwh+SkmebjUqRrCw+r4ZwYUqTFiSYKk4CHH8BEViHWS9vkEUA6 +1kg3U7GCvGkHVcS1ShRyAmWGuHsCtoyRQpxW12B4lo9Yt6ggyUy+41wYaYiyv8JrfWT 2UwX6qLevG5sxvooJKJDZStBNn2TC85/zWMWjydDdgLDBhFO1E0p3v4bDNW4CCDpjXEw mPNkXUGZsRJ6BI1S1kFc7OmC9awO/fLY5D2IPRXxsONDsg7A86i9JEm1URqkORjYxnCv wRq70Aetu+hU+QA8L0YbacO2RYFC2f/lB5qGGewGQ/FTcFEex9a2xf9/KzKUw1TEw5dg sxbw== 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=DeQNnhKLq20hKjofNapFLG+353TuYuJEywF7xzU7E1U=; b=NXAZyefLWm8UH4ggeSEsy2XKriKeNBDPvDGT5qdo+7k/hUhCG8JWw1Wbgks8aZathi ZXXCHAWH2gBUUYnfq3rA5jcb/HKAk66MF4L5fZ2zpIpP9P8oLPmAmdYaZtTMDxIOnZ+l Y6Eoba+o94wrViydWiX6LF3Mq4Ub6gkIKXB38Mx8wwZDGlwEVUjrR+cakGxEOU+LxfZ/ 6oSV1iZju6lFuWWtyrJlnhv4ye6hTq07TrDc3Krq/Tx2E/utTikpoIpjOf0kgZ6khK7I iyUUgqHQStJuCcylyIrT7bQXpzHPCoT7FNwC2t5IORVoIvNLe5bJO/STpFUM97SoUmpP 6SGQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=b7cxoU5I; 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 jo16si18693828ejb.86.2020.12.28.05.06.46; Mon, 28 Dec 2020 05:07:10 -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=b7cxoU5I; 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 S1730469AbgL1NEf (ORCPT + 99 others); Mon, 28 Dec 2020 08:04:35 -0500 Received: from mail.kernel.org ([198.145.29.99]:59368 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730423AbgL1NEX (ORCPT ); Mon, 28 Dec 2020 08:04:23 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 06F00208BA; Mon, 28 Dec 2020 13:04:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1609160647; bh=LGYcnPgQ1+cnAP7AIx6BdKtJSMm1IwzMJKnzmIIGa/k=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=b7cxoU5IwDwz2jvkEOpdsxSlIMVLJ1sgFu7wFCFfWUaP5NWNQ2pLgHOF3oQnSkgsy lhjboIL02IByIOHNUA3ihrXzSYmypo6rxuKTVCPpGM7CtvKd565hnqVtxilC+IHs6N yLbs0TC67AikxK/5jvOSiua0GbqUwgU3TlvTVdx8= 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 4.9 092/175] clocksource/drivers/cadence_ttc: Fix memory leak in ttc_setup_clockevent() Date: Mon, 28 Dec 2020 13:49:05 +0100 Message-Id: <20201228124857.705023177@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201228124853.216621466@linuxfoundation.org> References: <20201228124853.216621466@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/cadence_ttc_timer.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/drivers/clocksource/cadence_ttc_timer.c b/drivers/clocksource/cadence_ttc_timer.c index fbfbdec13b081..7cddc54be96cc 100644 --- a/drivers/clocksource/cadence_ttc_timer.c +++ b/drivers/clocksource/cadence_ttc_timer.c @@ -418,10 +418,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; @@ -431,7 +429,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); @@ -460,15 +458,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; } /** -- 2.27.0