Skip to content

Commit

Permalink
can: c_can: c_can_power_up(): fix error handling
Browse files Browse the repository at this point in the history
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: 8212003 ("can: c_can: Add d_can suspend resume support")
Fixes: 52cde85 ("can: c_can: Add d_can raminit support")
Signed-off-by: Zhang Qilong <zhangqilong3@huawei.com>
Link: https://lore.kernel.org/r/20201128133922.3276973-2-zhangqilong3@huawei.com
[mkl: return "0" instead of "ret"]
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
  • Loading branch information
Zhang Qilong authored and Marc Kleine-Budde committed Nov 30, 2020
1 parent c2d095e commit 44cef0c
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions drivers/net/can/c_can/c_can.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 0;

err_out:
c_can_reset_ram(priv, false);
c_can_pm_runtime_put_sync(priv);

return ret;
}
Expand Down

0 comments on commit 44cef0c

Please sign in to comment.