[PATCH 1/2] can: c_can: Fix error handling in c_can_power_up

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxx>
---
 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




[Index of Archives]     [Automotive Discussions]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux]     [Linux OMAP]     [Linux MIPS]     [eCos]     [Asterisk Internet PBX]     [Linux API]     [CAN Bus]

  Powered by Linux