Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp9172908pxu; Mon, 28 Dec 2020 08:23:09 -0800 (PST) X-Google-Smtp-Source: ABdhPJxxSw5n8oWeXM03zSGAaXb6bRqmHbd4+w0Pm2w328j/sp+dGJuLginfiwJSxooYGsHuyq69 X-Received: by 2002:a17:906:add7:: with SMTP id lb23mr44357410ejb.352.1609172589363; Mon, 28 Dec 2020 08:23:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1609172589; cv=none; d=google.com; s=arc-20160816; b=ry6Cc8KJ69HC0HcmVU0LXqKYAJ5yjdqdw5jTF+soI42MeEOcx57BLx1Lvum1hRpDto sSVxDlQYNmlDTW6D6UCA+QQIScCdjEDs48M/rQVkf5ZBY4zg/fM0ocLY7dHYjRtpftbJ CnD1en8Yso9O1yfjtT3Yce8bppqv99W/wfP1zjGaicCNEHlay9TI4utTGJ6dm7YfadE5 Gs6x9AsIPftzq34CdHGxMT4KZiriMlnLDIvT9bY42kD/ot6CGST+eOWPAENP4rrh18yX Ad7N7dmlZiQRVoFBFSLl6iBMpBFj4CwhaCWgLCnMuQf+age+H0t4GjRsvJHgpHgu2PDo QYtg== 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=+0agqGUbZxwYeRlQXNzcJ3z074mAWEWLpVAVP0B0dCg=; b=xHLIZDyv7EW32YWHiggovodDMadzI5fHl1mXOgKvSa2UtwOjS9bmUHVp4I6Ien3V9r 2HBQkzUIRaIETC/hMkVBDX2WJINpGZkKDFUg2GLdQTek1sV5YMQ7xGZj8wxL4aBpzXfv BDlVVqz3RNoy+SmSjehCqp3kIHyCY7ho7sI579KJhYISEAUcQjucKIt79knx5wMqSfho nkWdql+IPa1s2Aw6xQKkwDWoypEHB0xe19GQ/gFxOErA6eoYDlcsjah92nhLgBlewdMk Rd4xC36E/UwkKdhJzQwkk2bTxXs3N53piG6ecosl63X9uq9OZGjbuafoLk1Tw4uLErEx NUUA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=clTOPJgx; 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 s21si20727233edc.368.2020.12.28.08.22.46; Mon, 28 Dec 2020 08:23:09 -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=clTOPJgx; 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 S1732304AbgL1NNr (ORCPT + 99 others); Mon, 28 Dec 2020 08:13:47 -0500 Received: from mail.kernel.org ([198.145.29.99]:41908 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732263AbgL1NNq (ORCPT ); Mon, 28 Dec 2020 08:13:46 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id BB9332076D; Mon, 28 Dec 2020 13:13:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1609161186; bh=VeHRtpoquhQQYA5JHb3VFW5DjNs3ejr8fduawio3IEo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=clTOPJgxoSHXHIpP5cvITWMqfDVYnWCU6VhVOGjEZMmU4F3iIt7oOyfEfsxqz159W Dq4E28S3WgfAdnTk968h6LTgPmr3cetEOo270I/xQuF7gWDJWDcUhuT4ARw6ayaosL j1ZI2SIBXftSHfEKXIYCjrZrJ5yhi0LzP64A3sOk= 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.14 130/242] clocksource/drivers/cadence_ttc: Fix memory leak in ttc_setup_clockevent() Date: Mon, 28 Dec 2020 13:48:55 +0100 Message-Id: <20201228124911.099785735@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201228124904.654293249@linuxfoundation.org> References: <20201228124904.654293249@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 29d51755e18b2..a7eb858a84a0f 100644 --- a/drivers/clocksource/cadence_ttc_timer.c +++ b/drivers/clocksource/cadence_ttc_timer.c @@ -419,10 +419,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; @@ -432,7 +430,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); @@ -461,15 +459,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