[PATCH net-next] can: ctucanfd: use pm_runtime_resume_and_get() to balance reference count

From: Shitalkumar Gandhi

Date: Fri May 01 2026 - 15:01:17 EST


pm_runtime_get_sync() increments the runtime PM usage counter even when
it returns an error code, which forces every caller to handle the error
path by manually invoking pm_runtime_put_noidle(). In ctucanfd this is
done in three places (ctucan_open(), ctucan_get_berr_counter() and
ctucan_probe_common()), but the open-coded pattern is error-prone and
needlessly verbose.

pm_runtime_resume_and_get() was introduced specifically to solve this:
on failure it drops the usage count itself, so the caller only has to
return the error code. Convert all three call sites and adjust the
matching error message strings.

No functional change other than dropping the unbalanced
pm_runtime_put_noidle() that was already paired with a failure path
where the resume failed -- the new helper handles that internally.

Signed-off-by: Shitalkumar Gandhi <shitalkumar.gandhi@xxxxxxxxxxxxxxxxxxx>
---
drivers/net/can/ctucanfd/ctucanfd_base.c | 15 ++++++---------
1 file changed, 6 insertions(+), 9 deletions(-)

diff --git a/drivers/net/can/ctucanfd/ctucanfd_base.c b/drivers/net/can/ctucanfd/ctucanfd_base.c
index 0ea1ff28dfce..961c24494984 100644
--- a/drivers/net/can/ctucanfd/ctucanfd_base.c
+++ b/drivers/net/can/ctucanfd/ctucanfd_base.c
@@ -1202,11 +1202,10 @@ static int ctucan_open(struct net_device *ndev)
struct ctucan_priv *priv = netdev_priv(ndev);
int ret;

- ret = pm_runtime_get_sync(priv->dev);
+ ret = pm_runtime_resume_and_get(priv->dev);
if (ret < 0) {
- netdev_err(ndev, "%s: pm_runtime_get failed(%d)\n",
+ netdev_err(ndev, "%s: pm_runtime_resume_and_get failed(%d)\n",
__func__, ret);
- pm_runtime_put_noidle(priv->dev);
return ret;
}

@@ -1284,10 +1283,9 @@ static int ctucan_get_berr_counter(const struct net_device *ndev, struct can_ber
struct ctucan_priv *priv = netdev_priv(ndev);
int ret;

- ret = pm_runtime_get_sync(priv->dev);
+ ret = pm_runtime_resume_and_get(priv->dev);
if (ret < 0) {
- netdev_err(ndev, "%s: pm_runtime_get failed(%d)\n", __func__, ret);
- pm_runtime_put_noidle(priv->dev);
+ netdev_err(ndev, "%s: pm_runtime_resume_and_get failed(%d)\n", __func__, ret);
return ret;
}

@@ -1401,11 +1399,10 @@ int ctucan_probe_common(struct device *dev, void __iomem *addr, int irq, unsigne

if (pm_enable_call)
pm_runtime_enable(dev);
- ret = pm_runtime_get_sync(dev);
+ ret = pm_runtime_resume_and_get(dev);
if (ret < 0) {
- netdev_err(ndev, "%s: pm_runtime_get failed(%d)\n",
+ netdev_err(ndev, "%s: pm_runtime_resume_and_get failed(%d)\n",
__func__, ret);
- pm_runtime_put_noidle(priv->dev);
goto err_pmdisable;
}

--
2.25.1