pwm: vt8500: Simplify using devm functions
authorUwe Kleine-König <u.kleine-koenig@pengutronix.de>
Fri, 29 Sep 2023 16:19:16 +0000 (18:19 +0200)
committerThierry Reding <thierry.reding@gmail.com>
Fri, 13 Oct 2023 08:07:18 +0000 (10:07 +0200)
With devm_clk_get_prepared() the call to clk_unprepare() can be dropped
from the error path and the remove callback. With devm_pwmchip_add()
pwmchip_remove() can be dropped. Then the remove callback is empty and
can go away, too. With vt8500_pwm_remove() the last user of
platform_get_drvdata() is gone and so platform_set_drvdata() can be
dropped, too.

Also use dev_err_probe() for simplified (and improved) error reporting.

Link: https://lore.kernel.org/r/20230929161918.2410424-10-u.kleine-koenig@pengutronix.de
Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
Signed-off-by: Thierry Reding <thierry.reding@gmail.com>
drivers/pwm/pwm-vt8500.c

index a96c7f5d909993f49770e4896fc10a33cb812202..5568d5312d3caf4d148692fd4a383053c1576747 100644 (file)
@@ -235,10 +235,8 @@ static int vt8500_pwm_probe(struct platform_device *pdev)
        struct device_node *np = pdev->dev.of_node;
        int ret;
 
-       if (!np) {
-               dev_err(&pdev->dev, "invalid devicetree node\n");
-               return -EINVAL;
-       }
+       if (!np)
+               return dev_err_probe(&pdev->dev, -EINVAL, "invalid devicetree node\n");
 
        vt8500 = devm_kzalloc(&pdev->dev, sizeof(*vt8500), GFP_KERNEL);
        if (vt8500 == NULL)
@@ -248,45 +246,23 @@ static int vt8500_pwm_probe(struct platform_device *pdev)
        vt8500->chip.ops = &vt8500_pwm_ops;
        vt8500->chip.npwm = VT8500_NR_PWMS;
 
-       vt8500->clk = devm_clk_get(&pdev->dev, NULL);
-       if (IS_ERR(vt8500->clk)) {
-               dev_err(&pdev->dev, "clock source not specified\n");
-               return PTR_ERR(vt8500->clk);
-       }
+       vt8500->clk = devm_clk_get_prepared(&pdev->dev, NULL);
+       if (IS_ERR(vt8500->clk))
+               return dev_err_probe(&pdev->dev, PTR_ERR(vt8500->clk), "clock source not specified\n");
 
        vt8500->base = devm_platform_ioremap_resource(pdev, 0);
        if (IS_ERR(vt8500->base))
                return PTR_ERR(vt8500->base);
 
-       ret = clk_prepare(vt8500->clk);
-       if (ret < 0) {
-               dev_err(&pdev->dev, "failed to prepare clock\n");
-               return ret;
-       }
-
-       ret = pwmchip_add(&vt8500->chip);
-       if (ret < 0) {
-               dev_err(&pdev->dev, "failed to add PWM chip\n");
-               clk_unprepare(vt8500->clk);
-               return ret;
-       }
-
-       platform_set_drvdata(pdev, vt8500);
-       return ret;
-}
-
-static void vt8500_pwm_remove(struct platform_device *pdev)
-{
-       struct vt8500_chip *vt8500 = platform_get_drvdata(pdev);
-
-       pwmchip_remove(&vt8500->chip);
+       ret = devm_pwmchip_add(&pdev->dev, &vt8500->chip);
+       if (ret < 0)
+               return dev_err_probe(&pdev->dev, ret, "failed to add PWM chip\n");
 
-       clk_unprepare(vt8500->clk);
+       return 0;
 }
 
 static struct platform_driver vt8500_pwm_driver = {
        .probe          = vt8500_pwm_probe,
-       .remove_new     = vt8500_pwm_remove,
        .driver         = {
                .name   = "vt8500-pwm",
                .of_match_table = vt8500_pwm_dt_ids,