mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2025-01-19 11:43:40 +00:00
pwm: vt8500: Simplify using devm functions
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>
This commit is contained in:
parent
21c0e1aaf7
commit
dfbf937916
@ -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 = devm_pwmchip_add(&pdev->dev, &vt8500->chip);
|
||||
if (ret < 0)
|
||||
return dev_err_probe(&pdev->dev, ret, "failed to add PWM chip\n");
|
||||
|
||||
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);
|
||||
|
||||
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,
|
||||
|
Loading…
x
Reference in New Issue
Block a user