Skip to content

Commit e1717d2

Browse files
Uwe Kleine-Königgregkh
authored andcommitted
counter: stm32-timer-cnt: Convert to new counter registration
This fixes device lifetime issues where it was possible to free a live struct device. Fixes: ad29937 ("counter: Add STM32 Timer quadrature encoder") 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 5998ea6 commit e1717d2

File tree

1 file changed

+18
-12
lines changed

1 file changed

+18
-12
lines changed

drivers/counter/stm32-timer-cnt.c

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ struct stm32_timer_regs {
2929
};
3030

3131
struct stm32_timer_cnt {
32-
struct counter_device counter;
3332
struct regmap *regmap;
3433
struct clk *clk;
3534
u32 max_arr;
@@ -317,31 +316,38 @@ static int stm32_timer_cnt_probe(struct platform_device *pdev)
317316
struct stm32_timers *ddata = dev_get_drvdata(pdev->dev.parent);
318317
struct device *dev = &pdev->dev;
319318
struct stm32_timer_cnt *priv;
319+
struct counter_device *counter;
320+
int ret;
320321

321322
if (IS_ERR_OR_NULL(ddata))
322323
return -EINVAL;
323324

324-
priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
325-
if (!priv)
325+
counter = devm_counter_alloc(dev, sizeof(*priv));
326+
if (!counter)
326327
return -ENOMEM;
327328

329+
priv = counter_priv(counter);
330+
328331
priv->regmap = ddata->regmap;
329332
priv->clk = ddata->clk;
330333
priv->max_arr = ddata->max_arr;
331334

332-
priv->counter.name = dev_name(dev);
333-
priv->counter.parent = dev;
334-
priv->counter.ops = &stm32_timer_cnt_ops;
335-
priv->counter.counts = &stm32_counts;
336-
priv->counter.num_counts = 1;
337-
priv->counter.signals = stm32_signals;
338-
priv->counter.num_signals = ARRAY_SIZE(stm32_signals);
339-
priv->counter.priv = priv;
335+
counter->name = dev_name(dev);
336+
counter->parent = dev;
337+
counter->ops = &stm32_timer_cnt_ops;
338+
counter->counts = &stm32_counts;
339+
counter->num_counts = 1;
340+
counter->signals = stm32_signals;
341+
counter->num_signals = ARRAY_SIZE(stm32_signals);
340342

341343
platform_set_drvdata(pdev, priv);
342344

343345
/* Register Counter device */
344-
return devm_counter_register(dev, &priv->counter);
346+
ret = devm_counter_add(dev, counter);
347+
if (ret < 0)
348+
dev_err_probe(dev, ret, "Failed to add counter\n");
349+
350+
return ret;
345351
}
346352

347353
static int __maybe_unused stm32_timer_cnt_suspend(struct device *dev)

0 commit comments

Comments
 (0)