diff mbox series

[01/14] Input: samsung-keypad - switch to using devm_clk_get_prepared()

Message ID 20240819045813.2154642-2-dmitry.torokhov@gmail.com (mailing list archive)
State New, archived
Headers show
Series Remove support for platform data from samsung keypad | expand

Commit Message

Dmitry Torokhov Aug. 19, 2024, 4:57 a.m. UTC
Switch to using devm_clk_get_prepared() instead of combining
devm_clk_get() with clk_prepare(), which simplifies the code and
ensures that the clock is unprepared at the right time relative to
releasing other managed resources.

Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
---
 drivers/input/keyboard/samsung-keypad.c | 22 ++++------------------
 1 file changed, 4 insertions(+), 18 deletions(-)

Comments

Krzysztof Kozlowski Aug. 19, 2024, 12:51 p.m. UTC | #1
On Sun, Aug 18, 2024 at 09:57:58PM -0700, Dmitry Torokhov wrote:
> Switch to using devm_clk_get_prepared() instead of combining
> devm_clk_get() with clk_prepare(), which simplifies the code and
> ensures that the clock is unprepared at the right time relative to
> releasing other managed resources.

...

>  	device_init_wakeup(&pdev->dev, pdata->wakeup);
> @@ -439,20 +433,12 @@ static int samsung_keypad_probe(struct platform_device *pdev)
>  
>  err_disable_runtime_pm:
>  	pm_runtime_disable(&pdev->dev);
> -err_unprepare_clk:
> -	clk_unprepare(keypad->clk);
>  	return error;
>  }
>  
>  static void samsung_keypad_remove(struct platform_device *pdev)
>  {
> -	struct samsung_keypad *keypad = platform_get_drvdata(pdev);
> -
>  	pm_runtime_disable(&pdev->dev);
> -
> -	input_unregister_device(keypad->input_dev);

This looks unrelated.

Best regards,
Krzysztof
Dmitry Torokhov Aug. 19, 2024, 2:46 p.m. UTC | #2
On Mon, Aug 19, 2024 at 02:51:09PM +0200, Krzysztof Kozlowski wrote:
> On Sun, Aug 18, 2024 at 09:57:58PM -0700, Dmitry Torokhov wrote:
> > Switch to using devm_clk_get_prepared() instead of combining
> > devm_clk_get() with clk_prepare(), which simplifies the code and
> > ensures that the clock is unprepared at the right time relative to
> > releasing other managed resources.
> 
> ...
> 
> >  	device_init_wakeup(&pdev->dev, pdata->wakeup);
> > @@ -439,20 +433,12 @@ static int samsung_keypad_probe(struct platform_device *pdev)
> >  
> >  err_disable_runtime_pm:
> >  	pm_runtime_disable(&pdev->dev);
> > -err_unprepare_clk:
> > -	clk_unprepare(keypad->clk);
> >  	return error;
> >  }
> >  
> >  static void samsung_keypad_remove(struct platform_device *pdev)
> >  {
> > -	struct samsung_keypad *keypad = platform_get_drvdata(pdev);
> > -
> >  	pm_runtime_disable(&pdev->dev);
> > -
> > -	input_unregister_device(keypad->input_dev);
> 
> This looks unrelated.

It actually is related: with clk moved to devm we no longer need to
unregister input device by hand to keep the right ordering and we can
rely on devm to clean the input device as well (it already is being
allocated with devm_input_allocate_device()).

Thanks.
diff mbox series

Patch

diff --git a/drivers/input/keyboard/samsung-keypad.c b/drivers/input/keyboard/samsung-keypad.c
index e212eff7687c..a5fac7de8b5d 100644
--- a/drivers/input/keyboard/samsung-keypad.c
+++ b/drivers/input/keyboard/samsung-keypad.c
@@ -361,18 +361,12 @@  static int samsung_keypad_probe(struct platform_device *pdev)
 	if (!keypad->base)
 		return -EBUSY;
 
-	keypad->clk = devm_clk_get(&pdev->dev, "keypad");
+	keypad->clk = devm_clk_get_prepared(&pdev->dev, "keypad");
 	if (IS_ERR(keypad->clk)) {
 		dev_err(&pdev->dev, "failed to get keypad clk\n");
 		return PTR_ERR(keypad->clk);
 	}
 
-	error = clk_prepare(keypad->clk);
-	if (error) {
-		dev_err(&pdev->dev, "keypad clock prepare failed\n");
-		return error;
-	}
-
 	keypad->input_dev = input_dev;
 	keypad->pdev = pdev;
 	keypad->row_shift = row_shift;
@@ -399,7 +393,7 @@  static int samsung_keypad_probe(struct platform_device *pdev)
 					   keypad->keycodes, input_dev);
 	if (error) {
 		dev_err(&pdev->dev, "failed to build keymap\n");
-		goto err_unprepare_clk;
+		return error;
 	}
 
 	input_set_capability(input_dev, EV_MSC, MSC_SCAN);
@@ -411,7 +405,7 @@  static int samsung_keypad_probe(struct platform_device *pdev)
 	keypad->irq = platform_get_irq(pdev, 0);
 	if (keypad->irq < 0) {
 		error = keypad->irq;
-		goto err_unprepare_clk;
+		return error;
 	}
 
 	error = devm_request_threaded_irq(&pdev->dev, keypad->irq, NULL,
@@ -419,7 +413,7 @@  static int samsung_keypad_probe(struct platform_device *pdev)
 					  dev_name(&pdev->dev), keypad);
 	if (error) {
 		dev_err(&pdev->dev, "failed to register keypad interrupt\n");
-		goto err_unprepare_clk;
+		return error;
 	}
 
 	device_init_wakeup(&pdev->dev, pdata->wakeup);
@@ -439,20 +433,12 @@  static int samsung_keypad_probe(struct platform_device *pdev)
 
 err_disable_runtime_pm:
 	pm_runtime_disable(&pdev->dev);
-err_unprepare_clk:
-	clk_unprepare(keypad->clk);
 	return error;
 }
 
 static void samsung_keypad_remove(struct platform_device *pdev)
 {
-	struct samsung_keypad *keypad = platform_get_drvdata(pdev);
-
 	pm_runtime_disable(&pdev->dev);
-
-	input_unregister_device(keypad->input_dev);
-
-	clk_unprepare(keypad->clk);
 }
 
 static int samsung_keypad_runtime_suspend(struct device *dev)