Skip to content

Commit 9e884bb

Browse files
Uwe Kleine-Königgregkh
authored andcommitted
counter: 104-quad-8: Convert to new counter registration
This fixes device lifetime issues where it was possible to free a live struct device. Fixes: f1d8a07 ("counter: 104-quad-8: Add Generic Counter interface support") 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 9864472 commit 9e884bb

File tree

1 file changed

+20
-15
lines changed

1 file changed

+20
-15
lines changed

drivers/counter/104-quad-8.c

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ MODULE_PARM_DESC(irq, "ACCES 104-QUAD-8 interrupt line numbers");
5252
*/
5353
struct quad8 {
5454
spinlock_t lock;
55-
struct counter_device counter;
5655
unsigned int fck_prescaler[QUAD8_NUM_COUNTERS];
5756
unsigned int preset[QUAD8_NUM_COUNTERS];
5857
unsigned int count_mode[QUAD8_NUM_COUNTERS];
@@ -1083,7 +1082,8 @@ static struct counter_count quad8_counts[] = {
10831082

10841083
static irqreturn_t quad8_irq_handler(int irq, void *private)
10851084
{
1086-
struct quad8 *const priv = private;
1085+
struct counter_device *counter = private;
1086+
struct quad8 *const priv = counter_priv(counter);
10871087
const unsigned long base = priv->base;
10881088
unsigned long irq_status;
10891089
unsigned long channel;
@@ -1114,7 +1114,7 @@ static irqreturn_t quad8_irq_handler(int irq, void *private)
11141114
continue;
11151115
}
11161116

1117-
counter_push_event(&priv->counter, event, channel);
1117+
counter_push_event(counter, event, channel);
11181118
}
11191119

11201120
/* Clear pending interrupts on device */
@@ -1125,6 +1125,7 @@ static irqreturn_t quad8_irq_handler(int irq, void *private)
11251125

11261126
static int quad8_probe(struct device *dev, unsigned int id)
11271127
{
1128+
struct counter_device *counter;
11281129
struct quad8 *priv;
11291130
int i, j;
11301131
unsigned int base_offset;
@@ -1136,19 +1137,19 @@ static int quad8_probe(struct device *dev, unsigned int id)
11361137
return -EBUSY;
11371138
}
11381139

1139-
priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
1140-
if (!priv)
1140+
counter = devm_counter_alloc(dev, sizeof(*priv));
1141+
if (!counter)
11411142
return -ENOMEM;
1143+
priv = counter_priv(counter);
11421144

11431145
/* Initialize Counter device and driver data */
1144-
priv->counter.name = dev_name(dev);
1145-
priv->counter.parent = dev;
1146-
priv->counter.ops = &quad8_ops;
1147-
priv->counter.counts = quad8_counts;
1148-
priv->counter.num_counts = ARRAY_SIZE(quad8_counts);
1149-
priv->counter.signals = quad8_signals;
1150-
priv->counter.num_signals = ARRAY_SIZE(quad8_signals);
1151-
priv->counter.priv = priv;
1146+
counter->name = dev_name(dev);
1147+
counter->parent = dev;
1148+
counter->ops = &quad8_ops;
1149+
counter->counts = quad8_counts;
1150+
counter->num_counts = ARRAY_SIZE(quad8_counts);
1151+
counter->signals = quad8_signals;
1152+
counter->num_signals = ARRAY_SIZE(quad8_signals);
11521153
priv->base = base[id];
11531154

11541155
spin_lock_init(&priv->lock);
@@ -1188,11 +1189,15 @@ static int quad8_probe(struct device *dev, unsigned int id)
11881189
outb(QUAD8_CHAN_OP_ENABLE_INTERRUPT_FUNC, base[id] + QUAD8_REG_CHAN_OP);
11891190

11901191
err = devm_request_irq(dev, irq[id], quad8_irq_handler, IRQF_SHARED,
1191-
priv->counter.name, priv);
1192+
counter->name, counter);
11921193
if (err)
11931194
return err;
11941195

1195-
return devm_counter_register(dev, &priv->counter);
1196+
err = devm_counter_add(dev, counter);
1197+
if (err < 0)
1198+
return dev_err_probe(dev, err, "Failed to add counter\n");
1199+
1200+
return 0;
11961201
}
11971202

11981203
static struct isa_driver quad8_driver = {

0 commit comments

Comments
 (0)