Skip to content

Commit

Permalink
counter: ftm-quaddec: Convert to new counter registration
Browse files Browse the repository at this point in the history
This fixes device lifetime issues where it was possible to free a live
struct device.

Fixes: a3b9a99 ("counter: add FlexTimer Module Quadrature decoder counter driver")
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]>
  • Loading branch information
Uwe Kleine-König authored and gregkh committed Dec 30, 2021
1 parent e99dec8 commit b5d6547
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions drivers/counter/ftm-quaddec.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
})

struct ftm_quaddec {
struct counter_device counter;
struct platform_device *pdev;
void __iomem *ftm_base;
bool big_endian;
Expand Down Expand Up @@ -259,15 +258,17 @@ static struct counter_count ftm_quaddec_counts = {

static int ftm_quaddec_probe(struct platform_device *pdev)
{
struct counter_device *counter;
struct ftm_quaddec *ftm;

struct device_node *node = pdev->dev.of_node;
struct resource *io;
int ret;

ftm = devm_kzalloc(&pdev->dev, sizeof(*ftm), GFP_KERNEL);
if (!ftm)
counter = devm_counter_alloc(&pdev->dev, sizeof(*ftm));
if (!counter)
return -ENOMEM;
ftm = counter_priv(counter);

io = platform_get_resource(pdev, IORESOURCE_MEM, 0);
if (!io) {
Expand All @@ -283,14 +284,13 @@ static int ftm_quaddec_probe(struct platform_device *pdev)
dev_err(&pdev->dev, "Failed to map memory region\n");
return -EINVAL;
}
ftm->counter.name = dev_name(&pdev->dev);
ftm->counter.parent = &pdev->dev;
ftm->counter.ops = &ftm_quaddec_cnt_ops;
ftm->counter.counts = &ftm_quaddec_counts;
ftm->counter.num_counts = 1;
ftm->counter.signals = ftm_quaddec_signals;
ftm->counter.num_signals = ARRAY_SIZE(ftm_quaddec_signals);
ftm->counter.priv = ftm;
counter->name = dev_name(&pdev->dev);
counter->parent = &pdev->dev;
counter->ops = &ftm_quaddec_cnt_ops;
counter->counts = &ftm_quaddec_counts;
counter->num_counts = 1;
counter->signals = ftm_quaddec_signals;
counter->num_signals = ARRAY_SIZE(ftm_quaddec_signals);

mutex_init(&ftm->ftm_quaddec_mutex);

Expand All @@ -300,9 +300,9 @@ static int ftm_quaddec_probe(struct platform_device *pdev)
if (ret)
return ret;

ret = devm_counter_register(&pdev->dev, &ftm->counter);
ret = devm_counter_add(&pdev->dev, counter);
if (ret)
return ret;
return dev_err_probe(&pdev->dev, ret, "Failed to add counter\n");

return 0;
}
Expand Down

0 comments on commit b5d6547

Please sign in to comment.