Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

counter: ti-eqep: Convert to new counter registration

This fixes device lifetime issues where it was possible to free a live
struct device.

Fixes: f213729f6796 ("counter: new TI eQEP driver")
Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Acked-by: William Breathitt Gray <vilhelm.gray@gmail.com>
Acked-by: David Lechner <david@lechnology.com>
Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
Link: https://lore.kernel.org/r/20211230150300.72196-23-u.kleine-koenig@pengutronix.de
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Uwe Kleine-König and committed by
Greg Kroah-Hartman
02758cb2 e75d678d

+15 -14
+15 -14
drivers/counter/ti-eqep.c
··· 373 373 static int ti_eqep_probe(struct platform_device *pdev) 374 374 { 375 375 struct device *dev = &pdev->dev; 376 + struct counter_device *counter; 376 377 struct ti_eqep_cnt *priv; 377 378 void __iomem *base; 378 379 int err; 379 380 380 - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); 381 - if (!priv) 381 + counter = devm_counter_alloc(dev, sizeof(*priv)); 382 + if (!counter) 382 383 return -ENOMEM; 384 + priv = counter_priv(counter); 383 385 384 386 base = devm_platform_ioremap_resource(pdev, 0); 385 387 if (IS_ERR(base)) ··· 397 395 if (IS_ERR(priv->regmap16)) 398 396 return PTR_ERR(priv->regmap16); 399 397 400 - priv->counter.name = dev_name(dev); 401 - priv->counter.parent = dev; 402 - priv->counter.ops = &ti_eqep_counter_ops; 403 - priv->counter.counts = ti_eqep_counts; 404 - priv->counter.num_counts = ARRAY_SIZE(ti_eqep_counts); 405 - priv->counter.signals = ti_eqep_signals; 406 - priv->counter.num_signals = ARRAY_SIZE(ti_eqep_signals); 407 - priv->counter.priv = priv; 398 + counter->name = dev_name(dev); 399 + counter->parent = dev; 400 + counter->ops = &ti_eqep_counter_ops; 401 + counter->counts = ti_eqep_counts; 402 + counter->num_counts = ARRAY_SIZE(ti_eqep_counts); 403 + counter->signals = ti_eqep_signals; 404 + counter->num_signals = ARRAY_SIZE(ti_eqep_signals); 408 405 409 - platform_set_drvdata(pdev, priv); 406 + platform_set_drvdata(pdev, counter); 410 407 411 408 /* 412 409 * Need to make sure power is turned on. On AM33xx, this comes from the ··· 415 414 pm_runtime_enable(dev); 416 415 pm_runtime_get_sync(dev); 417 416 418 - err = counter_register(&priv->counter); 417 + err = counter_add(counter); 419 418 if (err < 0) { 420 419 pm_runtime_put_sync(dev); 421 420 pm_runtime_disable(dev); ··· 427 426 428 427 static int ti_eqep_remove(struct platform_device *pdev) 429 428 { 430 - struct ti_eqep_cnt *priv = platform_get_drvdata(pdev); 429 + struct counter_device *counter = platform_get_drvdata(pdev); 431 430 struct device *dev = &pdev->dev; 432 431 433 - counter_unregister(&priv->counter); 432 + counter_unregister(counter); 434 433 pm_runtime_put_sync(dev); 435 434 pm_runtime_disable(dev); 436 435