Skip to content

Commit 5998ea6

Browse files
Uwe Kleine-Königgregkh
authored andcommitted
counter: microchip-tcb-capture: Convert to new counter registration
This fixes device lifetime issues where it was possible to free a live struct device. Fixes: 106b104 ("counter: Add microchip TCB capture counter") 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 b5d6547 commit 5998ea6

File tree

1 file changed

+17
-13
lines changed

1 file changed

+17
-13
lines changed

drivers/counter/microchip-tcb-capture.c

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424

2525
struct mchp_tc_data {
2626
const struct atmel_tcb_config *tc_cfg;
27-
struct counter_device counter;
2827
struct regmap *regmap;
2928
int qdec_mode;
3029
int num_channels;
@@ -296,16 +295,18 @@ static int mchp_tc_probe(struct platform_device *pdev)
296295
struct device_node *np = pdev->dev.of_node;
297296
const struct atmel_tcb_config *tcb_config;
298297
const struct of_device_id *match;
298+
struct counter_device *counter;
299299
struct mchp_tc_data *priv;
300300
char clk_name[7];
301301
struct regmap *regmap;
302302
struct clk *clk[3];
303303
int channel;
304304
int ret, i;
305305

306-
priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL);
307-
if (!priv)
306+
counter = devm_counter_alloc(&pdev->dev, sizeof(*priv));
307+
if (!counter)
308308
return -ENOMEM;
309+
priv = counter_priv(counter);
309310

310311
match = of_match_node(atmel_tc_of_match, np->parent);
311312
tcb_config = match->data;
@@ -360,16 +361,19 @@ static int mchp_tc_probe(struct platform_device *pdev)
360361

361362
priv->tc_cfg = tcb_config;
362363
priv->regmap = regmap;
363-
priv->counter.name = dev_name(&pdev->dev);
364-
priv->counter.parent = &pdev->dev;
365-
priv->counter.ops = &mchp_tc_ops;
366-
priv->counter.num_counts = ARRAY_SIZE(mchp_tc_counts);
367-
priv->counter.counts = mchp_tc_counts;
368-
priv->counter.num_signals = ARRAY_SIZE(mchp_tc_count_signals);
369-
priv->counter.signals = mchp_tc_count_signals;
370-
priv->counter.priv = priv;
371-
372-
return devm_counter_register(&pdev->dev, &priv->counter);
364+
counter->name = dev_name(&pdev->dev);
365+
counter->parent = &pdev->dev;
366+
counter->ops = &mchp_tc_ops;
367+
counter->num_counts = ARRAY_SIZE(mchp_tc_counts);
368+
counter->counts = mchp_tc_counts;
369+
counter->num_signals = ARRAY_SIZE(mchp_tc_count_signals);
370+
counter->signals = mchp_tc_count_signals;
371+
372+
ret = devm_counter_add(&pdev->dev, counter);
373+
if (ret < 0)
374+
return dev_err_probe(&pdev->dev, ret, "Failed to add counter\n");
375+
376+
return 0;
373377
}
374378

375379
static const struct of_device_id mchp_tc_dt_ids[] = {

0 commit comments

Comments
 (0)