linux-can.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/2] can: Fix the error handling in c_can_power_up and kvaser_pciefd_open
@ 2020-11-28 13:39 Zhang Qilong
  2020-11-28 13:39 ` [PATCH 1/2] can: c_can: Fix error handling in c_can_power_up Zhang Qilong
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Zhang Qilong @ 2020-11-28 13:39 UTC (permalink / raw)
  To: wg, mkl, davem, kuba; +Cc: netdev, linux-can

The patch series fix the error handling to avoid the reference
leak and wrong state for the net device.

Zhang Qilong (2):
  can: c_can: Fix error handling in c_can_power_up
  can: kvaser_pciefd: Fix error handling in kvaser_pciefd_open

 drivers/net/can/c_can/c_can.c   | 18 ++++++++++++++----
 drivers/net/can/kvaser_pciefd.c |  4 +++-
 2 files changed, 17 insertions(+), 5 deletions(-)

-- 
2.25.4


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 1/2] can: c_can: Fix error handling in c_can_power_up
  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
  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
  2 siblings, 0 replies; 4+ messages in thread
From: Zhang Qilong @ 2020-11-28 13:39 UTC (permalink / raw)
  To: wg, mkl, davem, kuba; +Cc: netdev, linux-can

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


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 2/2] can: kvaser_pciefd: Fix error handling in kvaser_pciefd_open
  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 ` [PATCH 1/2] can: c_can: Fix error handling in c_can_power_up Zhang Qilong
@ 2020-11-28 13:39 ` 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
  2 siblings, 0 replies; 4+ messages in thread
From: Zhang Qilong @ 2020-11-28 13:39 UTC (permalink / raw)
  To: wg, mkl, davem, kuba; +Cc: netdev, linux-can

If kvaser_pciefd_bus_on failed, we should call close_candev
to avoid reference leak.

Fixes: 26ad340e582d3 ("can: kvaser_pciefd: Add driver for Kvaser PCIEcan devices")
Signed-off-by: Zhang Qilong <zhangqilong3@huawei.com>
---
 drivers/net/can/kvaser_pciefd.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/net/can/kvaser_pciefd.c b/drivers/net/can/kvaser_pciefd.c
index 1bafa614950e..969cedb9b0b6 100644
--- a/drivers/net/can/kvaser_pciefd.c
+++ b/drivers/net/can/kvaser_pciefd.c
@@ -692,8 +692,10 @@ static int kvaser_pciefd_open(struct net_device *netdev)
 		return err;
 
 	err = kvaser_pciefd_bus_on(can);
-	if (err)
+	if (err) {
+		close_candev(netdev);
 		return err;
+	}
 
 	return 0;
 }
-- 
2.25.4


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH 0/2] can: Fix the error handling in c_can_power_up and kvaser_pciefd_open
  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 ` [PATCH 1/2] can: c_can: Fix error handling in c_can_power_up Zhang Qilong
  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 ` Marc Kleine-Budde
  2 siblings, 0 replies; 4+ messages in thread
From: Marc Kleine-Budde @ 2020-11-30 11:49 UTC (permalink / raw)
  To: Zhang Qilong, wg, davem, kuba; +Cc: netdev, linux-can


[-- Attachment #1.1: Type: text/plain, Size: 781 bytes --]

On 11/28/20 2:39 PM, Zhang Qilong wrote:
> The patch series fix the error handling to avoid the reference
> leak and wrong state for the net device.
> 
> Zhang Qilong (2):
>   can: c_can: Fix error handling in c_can_power_up
>   can: kvaser_pciefd: Fix error handling in kvaser_pciefd_open
> 
>  drivers/net/can/c_can/c_can.c   | 18 ++++++++++++++----
>  drivers/net/can/kvaser_pciefd.c |  4 +++-
>  2 files changed, 17 insertions(+), 5 deletions(-)

Applied to linux-can/testing.

Tnx,
Marc

-- 
Pengutronix e.K.                 | Marc Kleine-Budde           |
Embedded Linux                   | https://www.pengutronix.de  |
Vertretung West/Dortmund         | Phone: +49-231-2826-924     |
Amtsgericht Hildesheim, HRA 2686 | Fax:   +49-5121-206917-5555 |


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2020-11-30 11:50 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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 ` [PATCH 1/2] can: c_can: Fix error handling in c_can_power_up Zhang Qilong
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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).