Skip to content

Commit 0323e8f

Browse files
Uwe Kleine-Königthierryreding
authored andcommitted
pwm: atmel-tcb: Harmonize resource allocation order
Allocate driver data as first resource in the probe function. This way it can be used during allocation of the other resources (instead of assigning these to local variables first and update driver data only when it's allocated). Also as driver data is allocated using a devm function this should happen first to have the order of freeing resources in the error path and the remove function in reverse. Signed-off-by: Uwe Kleine-König <[email protected]> Signed-off-by: Thierry Reding <[email protected]>
1 parent 84c33f4 commit 0323e8f

File tree

1 file changed

+20
-29
lines changed

1 file changed

+20
-29
lines changed

drivers/pwm/pwm-atmel-tcb.c

Lines changed: 20 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -421,13 +421,14 @@ static int atmel_tcb_pwm_probe(struct platform_device *pdev)
421421
struct atmel_tcb_pwm_chip *tcbpwm;
422422
const struct atmel_tcb_config *config;
423423
struct device_node *np = pdev->dev.of_node;
424-
struct regmap *regmap;
425-
struct clk *clk, *gclk = NULL;
426-
struct clk *slow_clk;
427424
char clk_name[] = "t0_clk";
428425
int err;
429426
int channel;
430427

428+
tcbpwm = devm_kzalloc(&pdev->dev, sizeof(*tcbpwm), GFP_KERNEL);
429+
if (tcbpwm == NULL)
430+
return -ENOMEM;
431+
431432
err = of_property_read_u32(np, "reg", &channel);
432433
if (err < 0) {
433434
dev_err(&pdev->dev,
@@ -436,47 +437,37 @@ static int atmel_tcb_pwm_probe(struct platform_device *pdev)
436437
return err;
437438
}
438439

439-
regmap = syscon_node_to_regmap(np->parent);
440-
if (IS_ERR(regmap))
441-
return PTR_ERR(regmap);
440+
tcbpwm->regmap = syscon_node_to_regmap(np->parent);
441+
if (IS_ERR(tcbpwm->regmap))
442+
return PTR_ERR(tcbpwm->regmap);
442443

443-
slow_clk = of_clk_get_by_name(np->parent, "slow_clk");
444-
if (IS_ERR(slow_clk))
445-
return PTR_ERR(slow_clk);
444+
tcbpwm->slow_clk = of_clk_get_by_name(np->parent, "slow_clk");
445+
if (IS_ERR(tcbpwm->slow_clk))
446+
return PTR_ERR(tcbpwm->slow_clk);
446447

447448
clk_name[1] += channel;
448-
clk = of_clk_get_by_name(np->parent, clk_name);
449-
if (IS_ERR(clk))
450-
clk = of_clk_get_by_name(np->parent, "t0_clk");
451-
if (IS_ERR(clk))
452-
return PTR_ERR(clk);
449+
tcbpwm->clk = of_clk_get_by_name(np->parent, clk_name);
450+
if (IS_ERR(tcbpwm->clk))
451+
tcbpwm->clk = of_clk_get_by_name(np->parent, "t0_clk");
452+
if (IS_ERR(tcbpwm->clk))
453+
return PTR_ERR(tcbpwm->clk);
453454

454455
match = of_match_node(atmel_tcb_of_match, np->parent);
455456
config = match->data;
456457

457458
if (config->has_gclk) {
458-
gclk = of_clk_get_by_name(np->parent, "gclk");
459-
if (IS_ERR(gclk))
460-
return PTR_ERR(gclk);
461-
}
462-
463-
tcbpwm = devm_kzalloc(&pdev->dev, sizeof(*tcbpwm), GFP_KERNEL);
464-
if (tcbpwm == NULL) {
465-
err = -ENOMEM;
466-
goto err_slow_clk;
459+
tcbpwm->gclk = of_clk_get_by_name(np->parent, "gclk");
460+
if (IS_ERR(tcbpwm->gclk))
461+
return PTR_ERR(tcbpwm->gclk);
467462
}
468463

469464
tcbpwm->chip.dev = &pdev->dev;
470465
tcbpwm->chip.ops = &atmel_tcb_pwm_ops;
471466
tcbpwm->chip.npwm = NPWM;
472467
tcbpwm->channel = channel;
473-
tcbpwm->regmap = regmap;
474-
tcbpwm->clk = clk;
475-
tcbpwm->gclk = gclk;
476-
tcbpwm->slow_clk = slow_clk;
477468
tcbpwm->width = config->counter_width;
478469

479-
err = clk_prepare_enable(slow_clk);
470+
err = clk_prepare_enable(tcbpwm->slow_clk);
480471
if (err)
481472
goto err_slow_clk;
482473

@@ -494,7 +485,7 @@ static int atmel_tcb_pwm_probe(struct platform_device *pdev)
494485
clk_disable_unprepare(tcbpwm->slow_clk);
495486

496487
err_slow_clk:
497-
clk_put(slow_clk);
488+
clk_put(tcbpwm->slow_clk);
498489

499490
return err;
500491
}

0 commit comments

Comments
 (0)