Skip to content

Commit

Permalink
can: flexcan: fix failure handling of pm_runtime_get_sync()
Browse files Browse the repository at this point in the history
[ Upstream commit b7ee5bc ]

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>
Signed-off-by: Sasha Levin <sashal@kernel.org>
  • Loading branch information
Zhang Qilong authored and gregkh committed Nov 24, 2020
1 parent 2dce84c commit 46b6cf1
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions drivers/net/can/flexcan.c
Original file line number Diff line number Diff line change
Expand Up @@ -614,8 +614,10 @@ static int flexcan_get_berr_counter(const struct net_device *dev,
int err;

err = pm_runtime_get_sync(priv->dev);
if (err < 0)
if (err < 0) {
pm_runtime_put_noidle(priv->dev);
return err;
}

err = __flexcan_get_berr_counter(dev, bec);

Expand Down Expand Up @@ -1310,8 +1312,10 @@ static int flexcan_open(struct net_device *dev)
int err;

err = pm_runtime_get_sync(priv->dev);
if (err < 0)
if (err < 0) {
pm_runtime_put_noidle(priv->dev);
return err;
}

err = open_candev(dev);
if (err)
Expand Down

0 comments on commit 46b6cf1

Please sign in to comment.