Skip to content

Commit dfbf937

Browse files
Uwe Kleine-Königthierryreding
authored andcommitted
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/[email protected] Signed-off-by: Uwe Kleine-König <[email protected]> Signed-off-by: Thierry Reding <[email protected]>
1 parent 21c0e1a commit dfbf937

File tree

1 file changed

+9
-33
lines changed

1 file changed

+9
-33
lines changed

drivers/pwm/pwm-vt8500.c

Lines changed: 9 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -235,10 +235,8 @@ static int vt8500_pwm_probe(struct platform_device *pdev)
235235
struct device_node *np = pdev->dev.of_node;
236236
int ret;
237237

238-
if (!np) {
239-
dev_err(&pdev->dev, "invalid devicetree node\n");
240-
return -EINVAL;
241-
}
238+
if (!np)
239+
return dev_err_probe(&pdev->dev, -EINVAL, "invalid devicetree node\n");
242240

243241
vt8500 = devm_kzalloc(&pdev->dev, sizeof(*vt8500), GFP_KERNEL);
244242
if (vt8500 == NULL)
@@ -248,45 +246,23 @@ static int vt8500_pwm_probe(struct platform_device *pdev)
248246
vt8500->chip.ops = &vt8500_pwm_ops;
249247
vt8500->chip.npwm = VT8500_NR_PWMS;
250248

251-
vt8500->clk = devm_clk_get(&pdev->dev, NULL);
252-
if (IS_ERR(vt8500->clk)) {
253-
dev_err(&pdev->dev, "clock source not specified\n");
254-
return PTR_ERR(vt8500->clk);
255-
}
249+
vt8500->clk = devm_clk_get_prepared(&pdev->dev, NULL);
250+
if (IS_ERR(vt8500->clk))
251+
return dev_err_probe(&pdev->dev, PTR_ERR(vt8500->clk), "clock source not specified\n");
256252

257253
vt8500->base = devm_platform_ioremap_resource(pdev, 0);
258254
if (IS_ERR(vt8500->base))
259255
return PTR_ERR(vt8500->base);
260256

261-
ret = clk_prepare(vt8500->clk);
262-
if (ret < 0) {
263-
dev_err(&pdev->dev, "failed to prepare clock\n");
264-
return ret;
265-
}
266-
267-
ret = pwmchip_add(&vt8500->chip);
268-
if (ret < 0) {
269-
dev_err(&pdev->dev, "failed to add PWM chip\n");
270-
clk_unprepare(vt8500->clk);
271-
return ret;
272-
}
273-
274-
platform_set_drvdata(pdev, vt8500);
275-
return ret;
276-
}
277-
278-
static void vt8500_pwm_remove(struct platform_device *pdev)
279-
{
280-
struct vt8500_chip *vt8500 = platform_get_drvdata(pdev);
281-
282-
pwmchip_remove(&vt8500->chip);
257+
ret = devm_pwmchip_add(&pdev->dev, &vt8500->chip);
258+
if (ret < 0)
259+
return dev_err_probe(&pdev->dev, ret, "failed to add PWM chip\n");
283260

284-
clk_unprepare(vt8500->clk);
261+
return 0;
285262
}
286263

287264
static struct platform_driver vt8500_pwm_driver = {
288265
.probe = vt8500_pwm_probe,
289-
.remove_new = vt8500_pwm_remove,
290266
.driver = {
291267
.name = "vt8500-pwm",
292268
.of_match_table = vt8500_pwm_dt_ids,

0 commit comments

Comments
 (0)