Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp2960098pxu; Mon, 14 Dec 2020 16:03:53 -0800 (PST) X-Google-Smtp-Source: ABdhPJycP6+n+ZCXPL6u2o+FTK7Qm9x4lHq08YKNXcp3gYlCXm/WRHkkVusS9esfRgeJPRzC4MLv X-Received: by 2002:a17:906:144e:: with SMTP id q14mr24061684ejc.150.1607990633336; Mon, 14 Dec 2020 16:03:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1607990633; cv=none; d=google.com; s=arc-20160816; b=DmmKK995xWo+BsWhDSr6Jm/NC065RPMi2sKWfkpCN/4q2HUFMn4LAFrFbdxk0YUtvY M2WM3s4blWyMz7GxCEyT5K7CHH0ts6B0QqTtlbkpatjTe3UkDxCS3/OH+gdqzdho/sv+ 6Qj8mhCs+LCo7qgXPm1Ua+hCLwcYlVxdNwbBkrSwsGFiwRZIOZ77BtsWDhCKdsDA1u6O CuH0gnctvYX29WiNosbuxF7ZLBY6v40c/CVItqk15LNEWensx6nIkubjQiFmIhMdj+3W mMfvVLCdTIh7n7RpRCVAecFzhmkf4KPSLTYv5vA5qrHpeLQNgj9W07pOPrFF48qdljJh P6Wg== 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; bh=UeTiDCmEzereHDBOkxLFsv7ipSo1IAODV5CjHxAwD/w=; b=NqUh7q30b2WDswuh7F0ymPmWhcZC3dVQLQxrmO9gssluwVKze5Abcf/qLSbptfjd/M 4HDrx2TMm+UJHV4zj4eD7OytVJl3Gy124njaHFCSinWwb7/JK8wAa2zRVhtVGqVXk3Gw 7f0q9u0+IXjE/zFfr6Joqj655GVD4lHG9Skccpp8x7ZIZ2AktfMSXEoI2eKdmFeCZNgh s5rOvwwwAUeAlTSO6re2fG6eBoHfeur6GJIU1+tAiyAt+6XcmD/mnz/5Yf5IKursIzhk 5L1y8VmjbEPD3sQM4o3qiqEYSAlGfEe07Ejaiyk3gfNlX6OBGFbAHalF7P3FVE0OJWpt f2rg== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (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 s23si30796ejb.443.2020.12.14.16.03.30; Mon, 14 Dec 2020 16:03:53 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2441026AbgLNStp (ORCPT + 99 others); Mon, 14 Dec 2020 13:49:45 -0500 Received: from mail.kernel.org ([198.145.29.99]:45996 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2502266AbgLNRhp (ORCPT ); Mon, 14 Dec 2020 12:37:45 -0500 From: Greg Kroah-Hartman Authentication-Results: mail.kernel.org; dkim=permerror (bad message/signature format) To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Zhang Qilong , Marc Kleine-Budde , Sasha Levin Subject: [PATCH 5.9 027/105] can: c_can: c_can_power_up(): fix error handling Date: Mon, 14 Dec 2020 18:28:01 +0100 Message-Id: <20201214172556.585137877@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201214172555.280929671@linuxfoundation.org> References: <20201214172555.280929671@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 44cef0c0ffbd8d61143712ce874be68a273b7884 ] In the error handling in c_can_power_up(), there are two bugs: 1) c_can_pm_runtime_get_sync() will increase usage counter if device is not empty. Forgetting to call c_can_pm_runtime_put_sync() will result in a reference leak here. 2) c_can_reset_ram() operation will set start bit when enable is true. We should clear it in the error handling. We fix it by adding c_can_pm_runtime_put_sync() for 1), and c_can_reset_ram(enable is false) for 2) in the error handling. Fixes: 8212003260c60 ("can: c_can: Add d_can suspend resume support") Fixes: 52cde85acc23f ("can: c_can: Add d_can raminit support") Signed-off-by: Zhang Qilong Link: https://lore.kernel.org/r/20201128133922.3276973-2-zhangqilong3@huawei.com [mkl: return "0" instead of "ret"] Signed-off-by: Marc Kleine-Budde Signed-off-by: Sasha Levin --- drivers/net/can/c_can/c_can.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/drivers/net/can/c_can/c_can.c b/drivers/net/can/c_can/c_can.c index 8e9f5620c9a21..095505fa09de3 100644 --- a/drivers/net/can/c_can/c_can.c +++ b/drivers/net/can/c_can/c_can.c @@ -1304,12 +1304,22 @@ int c_can_power_up(struct net_device *dev) time_after(time_out, jiffies)) cpu_relax(); - if (time_after(jiffies, time_out)) - return -ETIMEDOUT; + if (time_after(jiffies, time_out)) { + ret = -ETIMEDOUT; + goto err_out; + } ret = c_can_start(dev); - if (!ret) - c_can_irq_control(priv, true); + if (ret) + goto err_out; + + c_can_irq_control(priv, true); + + return 0; + +err_out: + c_can_reset_ram(priv, false); + c_can_pm_runtime_put_sync(priv); return ret; } -- 2.27.0