Skip to content

Commit aefc7e1

Browse files
Uwe Kleine-Königgregkh
authored andcommitted
counter: interrupt-cnt: Convert to new counter registration
This fixes device lifetime issues where it was possible to free a live struct device. Fixes: a55ebd4 ("counter: add IRQ or GPIO based 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 9e884bb commit aefc7e1

File tree

1 file changed

+16
-12
lines changed

1 file changed

+16
-12
lines changed

drivers/counter/interrupt-cnt.c

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
struct interrupt_cnt_priv {
1818
atomic_t count;
19-
struct counter_device counter;
2019
struct gpio_desc *gpio;
2120
int irq;
2221
bool enabled;
@@ -148,12 +147,14 @@ static const struct counter_ops interrupt_cnt_ops = {
148147
static int interrupt_cnt_probe(struct platform_device *pdev)
149148
{
150149
struct device *dev = &pdev->dev;
150+
struct counter_device *counter;
151151
struct interrupt_cnt_priv *priv;
152152
int ret;
153153

154-
priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
155-
if (!priv)
154+
counter = devm_counter_alloc(dev, sizeof(*priv));
155+
if (!counter)
156156
return -ENOMEM;
157+
priv = counter_priv(counter);
157158

158159
priv->irq = platform_get_irq_optional(pdev, 0);
159160
if (priv->irq == -ENXIO)
@@ -184,8 +185,8 @@ static int interrupt_cnt_probe(struct platform_device *pdev)
184185
if (!priv->signals.name)
185186
return -ENOMEM;
186187

187-
priv->counter.signals = &priv->signals;
188-
priv->counter.num_signals = 1;
188+
counter->signals = &priv->signals;
189+
counter->num_signals = 1;
189190

190191
priv->synapses.actions_list = interrupt_cnt_synapse_actions;
191192
priv->synapses.num_actions = ARRAY_SIZE(interrupt_cnt_synapse_actions);
@@ -199,12 +200,11 @@ static int interrupt_cnt_probe(struct platform_device *pdev)
199200
priv->cnts.ext = interrupt_cnt_ext;
200201
priv->cnts.num_ext = ARRAY_SIZE(interrupt_cnt_ext);
201202

202-
priv->counter.priv = priv;
203-
priv->counter.name = dev_name(dev);
204-
priv->counter.parent = dev;
205-
priv->counter.ops = &interrupt_cnt_ops;
206-
priv->counter.counts = &priv->cnts;
207-
priv->counter.num_counts = 1;
203+
counter->name = dev_name(dev);
204+
counter->parent = dev;
205+
counter->ops = &interrupt_cnt_ops;
206+
counter->counts = &priv->cnts;
207+
counter->num_counts = 1;
208208

209209
irq_set_status_flags(priv->irq, IRQ_NOAUTOEN);
210210
ret = devm_request_irq(dev, priv->irq, interrupt_cnt_isr,
@@ -213,7 +213,11 @@ static int interrupt_cnt_probe(struct platform_device *pdev)
213213
if (ret)
214214
return ret;
215215

216-
return devm_counter_register(dev, &priv->counter);
216+
ret = devm_counter_add(dev, counter);
217+
if (ret < 0)
218+
return dev_err_probe(dev, ret, "Failed to add counter\n");
219+
220+
return 0;
217221
}
218222

219223
static const struct of_device_id interrupt_cnt_of_match[] = {

0 commit comments

Comments
 (0)