Skip to content

Commit e99dec8

Browse files
Uwe Kleine-Königgregkh
authored andcommitted
counter: intel-qep: Convert to new counter registration
This fixes device lifetime issues where it was possible to free a live struct device. Fixes: b711f68 ("counter: Add support for Intel Quadrature Encoder Peripheral") Tested-by: Jarkko Nikula <[email protected]> Reviewed-by: Jonathan Cameron <[email protected]> Acked-by: William Breathitt Gray <[email protected]> Acked-by: Jarkko Nikula <[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 aefc7e1 commit e99dec8

File tree

1 file changed

+16
-12
lines changed

1 file changed

+16
-12
lines changed

drivers/counter/intel-qep.c

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@
6363
#define INTEL_QEP_CLK_PERIOD_NS 10
6464

6565
struct intel_qep {
66-
struct counter_device counter;
6766
struct mutex lock;
6867
struct device *dev;
6968
void __iomem *regs;
@@ -392,14 +391,16 @@ static struct counter_count intel_qep_counter_count[] = {
392391

393392
static int intel_qep_probe(struct pci_dev *pci, const struct pci_device_id *id)
394393
{
394+
struct counter_device *counter;
395395
struct intel_qep *qep;
396396
struct device *dev = &pci->dev;
397397
void __iomem *regs;
398398
int ret;
399399

400-
qep = devm_kzalloc(dev, sizeof(*qep), GFP_KERNEL);
401-
if (!qep)
400+
counter = devm_counter_alloc(dev, sizeof(*qep));
401+
if (!counter)
402402
return -ENOMEM;
403+
qep = counter_priv(counter);
403404

404405
ret = pcim_enable_device(pci);
405406
if (ret)
@@ -422,20 +423,23 @@ static int intel_qep_probe(struct pci_dev *pci, const struct pci_device_id *id)
422423
intel_qep_init(qep);
423424
pci_set_drvdata(pci, qep);
424425

425-
qep->counter.name = pci_name(pci);
426-
qep->counter.parent = dev;
427-
qep->counter.ops = &intel_qep_counter_ops;
428-
qep->counter.counts = intel_qep_counter_count;
429-
qep->counter.num_counts = ARRAY_SIZE(intel_qep_counter_count);
430-
qep->counter.signals = intel_qep_signals;
431-
qep->counter.num_signals = ARRAY_SIZE(intel_qep_signals);
432-
qep->counter.priv = qep;
426+
counter->name = pci_name(pci);
427+
counter->parent = dev;
428+
counter->ops = &intel_qep_counter_ops;
429+
counter->counts = intel_qep_counter_count;
430+
counter->num_counts = ARRAY_SIZE(intel_qep_counter_count);
431+
counter->signals = intel_qep_signals;
432+
counter->num_signals = ARRAY_SIZE(intel_qep_signals);
433433
qep->enabled = false;
434434

435435
pm_runtime_put(dev);
436436
pm_runtime_allow(dev);
437437

438-
return devm_counter_register(&pci->dev, &qep->counter);
438+
ret = devm_counter_add(&pci->dev, counter);
439+
if (ret < 0)
440+
return dev_err_probe(&pci->dev, ret, "Failed to add counter\n");
441+
442+
return 0;
439443
}
440444

441445
static void intel_qep_remove(struct pci_dev *pci)

0 commit comments

Comments
 (0)