[PATCH] can: flexcan: fix runtime PM reference imbalance on probe failure

Guangshuo Li posted 1 patch 1 week, 2 days ago
drivers/net/can/flexcan/flexcan-core.c | 2 ++
1 file changed, 2 insertions(+)
[PATCH] can: flexcan: fix runtime PM reference imbalance on probe failure
Posted by Guangshuo Li 1 week, 2 days ago
flexcan_probe() increments the runtime PM usage counter with
pm_runtime_get_noresume() before registering the CAN device.

On successful registration, register_flexcandev() drops this reference
with pm_runtime_put(). However, if flexcan_setup_stop_mode() subsequently
fails, the error path unregisters the CAN device and falls through to
failed_register, where pm_runtime_put_noidle() drops the same reference
again.

This results in an unbalanced runtime PM usage counter on the stop mode
setup failure path.

Skip pm_runtime_put_noidle() after a successful register_flexcandev()
and only disable runtime PM before freeing the CAN device.

This issue was found by manual code inspection.

Fixes: 812f0116c66a ("can: flexcan: add CAN wakeup function for i.MX8QM")
Cc: stable@vger.kernel.org
Signed-off-by: Guangshuo Li <lgs201920130244@gmail.com>
---
 drivers/net/can/flexcan/flexcan-core.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/net/can/flexcan/flexcan-core.c b/drivers/net/can/flexcan/flexcan-core.c
index f5d22c61503f..7d675696797f 100644
--- a/drivers/net/can/flexcan/flexcan-core.c
+++ b/drivers/net/can/flexcan/flexcan-core.c
@@ -2266,8 +2266,10 @@ static int flexcan_probe(struct platform_device *pdev)
 
  failed_setup_stop_mode:
 	unregister_flexcandev(dev);
+	goto failed_pm_runtime_disable;
  failed_register:
 	pm_runtime_put_noidle(&pdev->dev);
+failed_pm_runtime_disable:
 	pm_runtime_disable(&pdev->dev);
  failed_platform_get_irq:
 	free_candev(dev);
-- 
2.43.0