Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

counter: intel-qep: Convert to new counter registration

This fixes device lifetime issues where it was possible to free a live
struct device.

Fixes: b711f687a1c1 ("counter: Add support for Intel Quadrature Encoder Peripheral")
Tested-by: Jarkko Nikula <jarkko.nikula@linux.intel.com>
Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Acked-by: William Breathitt Gray <vilhelm.gray@gmail.com>
Acked-by: Jarkko Nikula <jarkko.nikula@linux.intel.com>
Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
Link: https://lore.kernel.org/r/20211230150300.72196-18-u.kleine-koenig@pengutronix.de
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Uwe Kleine-König and committed by
Greg Kroah-Hartman
e99dec87 aefc7e17

+16 -12
+16 -12
drivers/counter/intel-qep.c
··· 63 63 #define INTEL_QEP_CLK_PERIOD_NS 10 64 64 65 65 struct intel_qep { 66 - struct counter_device counter; 67 66 struct mutex lock; 68 67 struct device *dev; 69 68 void __iomem *regs; ··· 391 392 392 393 static int intel_qep_probe(struct pci_dev *pci, const struct pci_device_id *id) 393 394 { 395 + struct counter_device *counter; 394 396 struct intel_qep *qep; 395 397 struct device *dev = &pci->dev; 396 398 void __iomem *regs; 397 399 int ret; 398 400 399 - qep = devm_kzalloc(dev, sizeof(*qep), GFP_KERNEL); 400 - if (!qep) 401 + counter = devm_counter_alloc(dev, sizeof(*qep)); 402 + if (!counter) 401 403 return -ENOMEM; 404 + qep = counter_priv(counter); 402 405 403 406 ret = pcim_enable_device(pci); 404 407 if (ret) ··· 423 422 intel_qep_init(qep); 424 423 pci_set_drvdata(pci, qep); 425 424 426 - qep->counter.name = pci_name(pci); 427 - qep->counter.parent = dev; 428 - qep->counter.ops = &intel_qep_counter_ops; 429 - qep->counter.counts = intel_qep_counter_count; 430 - qep->counter.num_counts = ARRAY_SIZE(intel_qep_counter_count); 431 - qep->counter.signals = intel_qep_signals; 432 - qep->counter.num_signals = ARRAY_SIZE(intel_qep_signals); 433 - qep->counter.priv = qep; 425 + counter->name = pci_name(pci); 426 + counter->parent = dev; 427 + counter->ops = &intel_qep_counter_ops; 428 + counter->counts = intel_qep_counter_count; 429 + counter->num_counts = ARRAY_SIZE(intel_qep_counter_count); 430 + counter->signals = intel_qep_signals; 431 + counter->num_signals = ARRAY_SIZE(intel_qep_signals); 434 432 qep->enabled = false; 435 433 436 434 pm_runtime_put(dev); 437 435 pm_runtime_allow(dev); 438 436 439 - return devm_counter_register(&pci->dev, &qep->counter); 437 + ret = devm_counter_add(&pci->dev, counter); 438 + if (ret < 0) 439 + return dev_err_probe(&pci->dev, ret, "Failed to add counter\n"); 440 + 441 + return 0; 440 442 } 441 443 442 444 static void intel_qep_remove(struct pci_dev *pci)