All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] Input: omap-keypad: Fix error goto and handling in omap4_keypad_probe
@ 2020-11-19  7:01 Zhang Qilong
  2020-11-20  7:25 ` Dmitry Torokhov
  0 siblings, 1 reply; 3+ messages in thread
From: Zhang Qilong @ 2020-11-19  7:01 UTC (permalink / raw)
  To: dmitry.torokhov; +Cc: linux-input

In omap4_keypad_probe, the patch fix several bugs.

  1) pm_runtime_get_sync will increment pm usage counter even it
     failed. Forgetting to pm_runtime_put_noidle will result in
     reference leak.

  2) In err_unmap, forget to disable runtime of device,
     pm_runtime_enable will increase power disable depth. Thus a
     pairing decrement is needed on the error handling path to keep
     it balanced.

  3) In err_pm_disable, it will call pm_runtime_put_sync twice not
     one time.

And we add the pm_runtime_put_noidle when pm_runtime_get_sync failed
for 1). Move pm_runtime_disable to the err_unmap branch for 2). Move
the input_register_device ahead for 3).

Fixes: f77621cc640a7 ("Input: omap-keypad - dynamically handle register offsets")
Fixes: 5ad567ffbaf20 ("Input: Input: omap4-keypad - wire up runtime PM handling")
Signed-off-by: Zhang Qilong <zhangqilong3@huawei.com>
---
 drivers/input/keyboard/omap4-keypad.c | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/drivers/input/keyboard/omap4-keypad.c b/drivers/input/keyboard/omap4-keypad.c
index d6c924032aaa..17abc8434af5 100644
--- a/drivers/input/keyboard/omap4-keypad.c
+++ b/drivers/input/keyboard/omap4-keypad.c
@@ -277,6 +277,7 @@ static int omap4_keypad_probe(struct platform_device *pdev)
 	pm_runtime_enable(&pdev->dev);
 	error = pm_runtime_get_sync(&pdev->dev);
 	if (error) {
+		pm_runtime_put_noidle(&pdev->dev);
 		dev_err(&pdev->dev, "pm_runtime_get_sync() failed\n");
 		goto err_unmap;
 	}
@@ -349,20 +350,19 @@ static int omap4_keypad_probe(struct platform_device *pdev)
 		goto err_free_keymap;
 	}
 
-	device_init_wakeup(&pdev->dev, true);
-	pm_runtime_put_sync(&pdev->dev);
-
 	error = input_register_device(keypad_data->input);
 	if (error < 0) {
 		dev_err(&pdev->dev, "failed to register input device\n");
-		goto err_pm_disable;
+		goto err_free_irq;
 	}
 
+	device_init_wakeup(&pdev->dev, true);
+	pm_runtime_put_sync(&pdev->dev);
+
 	platform_set_drvdata(pdev, keypad_data);
 	return 0;
 
-err_pm_disable:
-	pm_runtime_disable(&pdev->dev);
+err_free_irq:
 	free_irq(keypad_data->irq, keypad_data);
 err_free_keymap:
 	kfree(keypad_data->keymap);
@@ -371,6 +371,7 @@ static int omap4_keypad_probe(struct platform_device *pdev)
 err_pm_put_sync:
 	pm_runtime_put_sync(&pdev->dev);
 err_unmap:
+	pm_runtime_disable(&pdev->dev);
 	iounmap(keypad_data->base);
 err_release_mem:
 	release_mem_region(res->start, resource_size(res));
-- 
2.25.4


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-11-20 12:32 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-19  7:01 [PATCH] Input: omap-keypad: Fix error goto and handling in omap4_keypad_probe Zhang Qilong
2020-11-20  7:25 ` Dmitry Torokhov
2020-11-20 12:32   ` 答复: " zhangqilong

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.