Skip to content

Commit e75d678

Browse files
Uwe Kleine-Königgregkh
authored andcommitted
counter: stm32-lptimer-cnt: Convert to new counter registration
This fixes device lifetime issues where it was possible to free a live struct device. Fixes: 597f55e ("counter: stm32-lptimer: add counter device") Reviewed-by: Jonathan Cameron <[email protected]> Acked-by: William Breathitt Gray <[email protected]> Signed-off-by: Uwe Kleine-König <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent e1717d2 commit e75d678

File tree

1 file changed

+19
-14
lines changed

1 file changed

+19
-14
lines changed

drivers/counter/stm32-lptimer-cnt.c

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
#include <linux/types.h>
2121

2222
struct stm32_lptim_cnt {
23-
struct counter_device counter;
2423
struct device *dev;
2524
struct regmap *regmap;
2625
struct clk *clk;
@@ -411,38 +410,44 @@ static struct counter_count stm32_lptim_in1_counts = {
411410
static int stm32_lptim_cnt_probe(struct platform_device *pdev)
412411
{
413412
struct stm32_lptimer *ddata = dev_get_drvdata(pdev->dev.parent);
413+
struct counter_device *counter;
414414
struct stm32_lptim_cnt *priv;
415+
int ret;
415416

416417
if (IS_ERR_OR_NULL(ddata))
417418
return -EINVAL;
418419

419-
priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL);
420-
if (!priv)
420+
counter = devm_counter_alloc(&pdev->dev, sizeof(*priv));
421+
if (!counter)
421422
return -ENOMEM;
423+
priv = counter_priv(counter);
422424

423425
priv->dev = &pdev->dev;
424426
priv->regmap = ddata->regmap;
425427
priv->clk = ddata->clk;
426428
priv->ceiling = STM32_LPTIM_MAX_ARR;
427429

428430
/* Initialize Counter device */
429-
priv->counter.name = dev_name(&pdev->dev);
430-
priv->counter.parent = &pdev->dev;
431-
priv->counter.ops = &stm32_lptim_cnt_ops;
431+
counter->name = dev_name(&pdev->dev);
432+
counter->parent = &pdev->dev;
433+
counter->ops = &stm32_lptim_cnt_ops;
432434
if (ddata->has_encoder) {
433-
priv->counter.counts = &stm32_lptim_enc_counts;
434-
priv->counter.num_signals = ARRAY_SIZE(stm32_lptim_cnt_signals);
435+
counter->counts = &stm32_lptim_enc_counts;
436+
counter->num_signals = ARRAY_SIZE(stm32_lptim_cnt_signals);
435437
} else {
436-
priv->counter.counts = &stm32_lptim_in1_counts;
437-
priv->counter.num_signals = 1;
438+
counter->counts = &stm32_lptim_in1_counts;
439+
counter->num_signals = 1;
438440
}
439-
priv->counter.num_counts = 1;
440-
priv->counter.signals = stm32_lptim_cnt_signals;
441-
priv->counter.priv = priv;
441+
counter->num_counts = 1;
442+
counter->signals = stm32_lptim_cnt_signals;
442443

443444
platform_set_drvdata(pdev, priv);
444445

445-
return devm_counter_register(&pdev->dev, &priv->counter);
446+
ret = devm_counter_add(&pdev->dev, counter);
447+
if (ret < 0)
448+
return dev_err_probe(&pdev->dev, ret, "Failed to add counter\n");
449+
450+
return 0;
446451
}
447452

448453
#ifdef CONFIG_PM_SLEEP

0 commit comments

Comments
 (0)