Skip to content

Commit b5d6547

Browse files
Uwe Kleine-Königgregkh
authored andcommitted
counter: ftm-quaddec: Convert to new counter registration
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]>
1 parent e99dec8 commit b5d6547

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

drivers/counter/ftm-quaddec.c

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
})
2727

2828
struct ftm_quaddec {
29-
struct counter_device counter;
3029
struct platform_device *pdev;
3130
void __iomem *ftm_base;
3231
bool big_endian;
@@ -259,15 +258,17 @@ static struct counter_count ftm_quaddec_counts = {
259258

260259
static int ftm_quaddec_probe(struct platform_device *pdev)
261260
{
261+
struct counter_device *counter;
262262
struct ftm_quaddec *ftm;
263263

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

268-
ftm = devm_kzalloc(&pdev->dev, sizeof(*ftm), GFP_KERNEL);
269-
if (!ftm)
268+
counter = devm_counter_alloc(&pdev->dev, sizeof(*ftm));
269+
if (!counter)
270270
return -ENOMEM;
271+
ftm = counter_priv(counter);
271272

272273
io = platform_get_resource(pdev, IORESOURCE_MEM, 0);
273274
if (!io) {
@@ -283,14 +284,13 @@ static int ftm_quaddec_probe(struct platform_device *pdev)
283284
dev_err(&pdev->dev, "Failed to map memory region\n");
284285
return -EINVAL;
285286
}
286-
ftm->counter.name = dev_name(&pdev->dev);
287-
ftm->counter.parent = &pdev->dev;
288-
ftm->counter.ops = &ftm_quaddec_cnt_ops;
289-
ftm->counter.counts = &ftm_quaddec_counts;
290-
ftm->counter.num_counts = 1;
291-
ftm->counter.signals = ftm_quaddec_signals;
292-
ftm->counter.num_signals = ARRAY_SIZE(ftm_quaddec_signals);
293-
ftm->counter.priv = ftm;
287+
counter->name = dev_name(&pdev->dev);
288+
counter->parent = &pdev->dev;
289+
counter->ops = &ftm_quaddec_cnt_ops;
290+
counter->counts = &ftm_quaddec_counts;
291+
counter->num_counts = 1;
292+
counter->signals = ftm_quaddec_signals;
293+
counter->num_signals = ARRAY_SIZE(ftm_quaddec_signals);
294294

295295
mutex_init(&ftm->ftm_quaddec_mutex);
296296

@@ -300,9 +300,9 @@ static int ftm_quaddec_probe(struct platform_device *pdev)
300300
if (ret)
301301
return ret;
302302

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

307307
return 0;
308308
}

0 commit comments

Comments
 (0)