Skip to content

Commit b7ee5bc

Browse files
Zhang Qilongmarckleinebudde
authored andcommitted
can: flexcan: fix failure handling of pm_runtime_get_sync()
pm_runtime_get_sync() will increment pm usage at first and it will resume the device later. If runtime of the device has error or device is in inaccessible state(or other error state), resume operation will fail. If we do not call put operation to decrease the reference, it will result in reference leak in the two functions flexcan_get_berr_counter() and flexcan_open(). Moreover, this device cannot enter the idle state and always stay busy or other non-idle state later. So we should fix it through adding pm_runtime_put_noidle(). Fixes: ca10989 ("can: flexcan: implement can Runtime PM") Signed-off-by: Zhang Qilong <zhangqilong3@huawei.com> Link: https://lore.kernel.org/r/20201108083000.2599705-1-zhangqilong3@huawei.com Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
1 parent 499aa92 commit b7ee5bc

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

drivers/net/can/flexcan.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -728,8 +728,10 @@ static int flexcan_get_berr_counter(const struct net_device *dev,
728728
int err;
729729

730730
err = pm_runtime_get_sync(priv->dev);
731-
if (err < 0)
731+
if (err < 0) {
732+
pm_runtime_put_noidle(priv->dev);
732733
return err;
734+
}
733735

734736
err = __flexcan_get_berr_counter(dev, bec);
735737

@@ -1654,8 +1656,10 @@ static int flexcan_open(struct net_device *dev)
16541656
}
16551657

16561658
err = pm_runtime_get_sync(priv->dev);
1657-
if (err < 0)
1659+
if (err < 0) {
1660+
pm_runtime_put_noidle(priv->dev);
16581661
return err;
1662+
}
16591663

16601664
err = open_candev(dev);
16611665
if (err)

0 commit comments

Comments
 (0)