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: ad29937e20 ("counter: Add STM32 Timer quadrature encoder")
Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Acked-by: William Breathitt Gray <vilhelm.gray@gmail.com>
Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
Link: https://lore.kernel.org/r/20211230150300.72196-21-u.kleine-koenig@pengutronix.de
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
Uwe Kleine-König
2021-12-30 16:02:57 +01:00
committed by Greg Kroah-Hartman
parent 5998ea6214
commit e1717d2ea0
+18 -12
View File
@@ -29,7 +29,6 @@ struct stm32_timer_regs {
}; };
struct stm32_timer_cnt { struct stm32_timer_cnt {
struct counter_device counter;
struct regmap *regmap; struct regmap *regmap;
struct clk *clk; struct clk *clk;
u32 max_arr; u32 max_arr;
@@ -317,31 +316,38 @@ static int stm32_timer_cnt_probe(struct platform_device *pdev)
struct stm32_timers *ddata = dev_get_drvdata(pdev->dev.parent); struct stm32_timers *ddata = dev_get_drvdata(pdev->dev.parent);
struct device *dev = &pdev->dev; struct device *dev = &pdev->dev;
struct stm32_timer_cnt *priv; struct stm32_timer_cnt *priv;
struct counter_device *counter;
int ret;
if (IS_ERR_OR_NULL(ddata)) if (IS_ERR_OR_NULL(ddata))
return -EINVAL; return -EINVAL;
priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); counter = devm_counter_alloc(dev, sizeof(*priv));
if (!priv) if (!counter)
return -ENOMEM; return -ENOMEM;
priv = counter_priv(counter);
priv->regmap = ddata->regmap; priv->regmap = ddata->regmap;
priv->clk = ddata->clk; priv->clk = ddata->clk;
priv->max_arr = ddata->max_arr; priv->max_arr = ddata->max_arr;
priv->counter.name = dev_name(dev); counter->name = dev_name(dev);
priv->counter.parent = dev; counter->parent = dev;
priv->counter.ops = &stm32_timer_cnt_ops; counter->ops = &stm32_timer_cnt_ops;
priv->counter.counts = &stm32_counts; counter->counts = &stm32_counts;
priv->counter.num_counts = 1; counter->num_counts = 1;
priv->counter.signals = stm32_signals; counter->signals = stm32_signals;
priv->counter.num_signals = ARRAY_SIZE(stm32_signals); counter->num_signals = ARRAY_SIZE(stm32_signals);
priv->counter.priv = priv;
platform_set_drvdata(pdev, priv); platform_set_drvdata(pdev, priv);
/* Register Counter device */ /* Register Counter device */
return devm_counter_register(dev, &priv->counter); ret = devm_counter_add(dev, counter);
if (ret < 0)
dev_err_probe(dev, ret, "Failed to add counter\n");
return ret;
} }
static int __maybe_unused stm32_timer_cnt_suspend(struct device *dev) static int __maybe_unused stm32_timer_cnt_suspend(struct device *dev)