Skip to content

Commit 02758cb

Browse files
Uwe Kleine-Königgregkh
authored andcommitted
counter: ti-eqep: Convert to new counter registration
This fixes device lifetime issues where it was possible to free a live struct device. Fixes: f213729 ("counter: new TI eQEP driver") Reviewed-by: Jonathan Cameron <[email protected]> Acked-by: William Breathitt Gray <[email protected]> Acked-by: David Lechner <[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 e75d678 commit 02758cb

File tree

1 file changed

+15
-14
lines changed

1 file changed

+15
-14
lines changed

drivers/counter/ti-eqep.c

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -373,13 +373,15 @@ static const struct regmap_config ti_eqep_regmap16_config = {
373373
static int ti_eqep_probe(struct platform_device *pdev)
374374
{
375375
struct device *dev = &pdev->dev;
376+
struct counter_device *counter;
376377
struct ti_eqep_cnt *priv;
377378
void __iomem *base;
378379
int err;
379380

380-
priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
381-
if (!priv)
381+
counter = devm_counter_alloc(dev, sizeof(*priv));
382+
if (!counter)
382383
return -ENOMEM;
384+
priv = counter_priv(counter);
383385

384386
base = devm_platform_ioremap_resource(pdev, 0);
385387
if (IS_ERR(base))
@@ -395,16 +397,15 @@ static int ti_eqep_probe(struct platform_device *pdev)
395397
if (IS_ERR(priv->regmap16))
396398
return PTR_ERR(priv->regmap16);
397399

398-
priv->counter.name = dev_name(dev);
399-
priv->counter.parent = dev;
400-
priv->counter.ops = &ti_eqep_counter_ops;
401-
priv->counter.counts = ti_eqep_counts;
402-
priv->counter.num_counts = ARRAY_SIZE(ti_eqep_counts);
403-
priv->counter.signals = ti_eqep_signals;
404-
priv->counter.num_signals = ARRAY_SIZE(ti_eqep_signals);
405-
priv->counter.priv = priv;
400+
counter->name = dev_name(dev);
401+
counter->parent = dev;
402+
counter->ops = &ti_eqep_counter_ops;
403+
counter->counts = ti_eqep_counts;
404+
counter->num_counts = ARRAY_SIZE(ti_eqep_counts);
405+
counter->signals = ti_eqep_signals;
406+
counter->num_signals = ARRAY_SIZE(ti_eqep_signals);
406407

407-
platform_set_drvdata(pdev, priv);
408+
platform_set_drvdata(pdev, counter);
408409

409410
/*
410411
* Need to make sure power is turned on. On AM33xx, this comes from the
@@ -414,7 +415,7 @@ static int ti_eqep_probe(struct platform_device *pdev)
414415
pm_runtime_enable(dev);
415416
pm_runtime_get_sync(dev);
416417

417-
err = counter_register(&priv->counter);
418+
err = counter_add(counter);
418419
if (err < 0) {
419420
pm_runtime_put_sync(dev);
420421
pm_runtime_disable(dev);
@@ -426,10 +427,10 @@ static int ti_eqep_probe(struct platform_device *pdev)
426427

427428
static int ti_eqep_remove(struct platform_device *pdev)
428429
{
429-
struct ti_eqep_cnt *priv = platform_get_drvdata(pdev);
430+
struct counter_device *counter = platform_get_drvdata(pdev);
430431
struct device *dev = &pdev->dev;
431432

432-
counter_unregister(&priv->counter);
433+
counter_unregister(counter);
433434
pm_runtime_put_sync(dev);
434435
pm_runtime_disable(dev);
435436

0 commit comments

Comments
 (0)