From: Zhang Qilong <zhangqilong3@huawei.com>
To: <wg@grandegger.com>, <mkl@pengutronix.de>, <davem@davemloft.net>,
<kuba@kernel.org>
Cc: <netdev@vger.kernel.org>, <linux-can@vger.kernel.org>
Subject: [PATCH 1/2] can: c_can: Fix error handling in c_can_power_up
Date: Sat, 28 Nov 2020 21:39:21 +0800 [thread overview]
Message-ID: <20201128133922.3276973-2-zhangqilong3@huawei.com> (raw)
In-Reply-To: <20201128133922.3276973-1-zhangqilong3@huawei.com>
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 <zhangqilong3@huawei.com>
---
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 0420f09f2b70..becfdff7f3fd 100644
--- a/drivers/net/can/c_can/c_can.c
+++ b/drivers/net/can/c_can/c_can.c
@@ -1295,12 +1295,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 ret;
+
+err_out:
+ c_can_reset_ram(priv, false);
+ c_can_pm_runtime_put_sync(priv);
return ret;
}
--
2.25.4
next prev parent reply other threads:[~2020-11-28 22:12 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-11-28 13:39 [PATCH 0/2] can: Fix the error handling in c_can_power_up and kvaser_pciefd_open Zhang Qilong
2020-11-28 13:39 ` Zhang Qilong [this message]
2020-11-28 13:39 ` [PATCH 2/2] can: kvaser_pciefd: Fix error handling in kvaser_pciefd_open Zhang Qilong
2020-11-30 11:49 ` [PATCH 0/2] can: Fix the error handling in c_can_power_up and kvaser_pciefd_open Marc Kleine-Budde
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20201128133922.3276973-2-zhangqilong3@huawei.com \
--to=zhangqilong3@huawei.com \
--cc=davem@davemloft.net \
--cc=kuba@kernel.org \
--cc=linux-can@vger.kernel.org \
--cc=mkl@pengutronix.de \
--cc=netdev@vger.kernel.org \
--cc=wg@grandegger.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.