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

counter: ftm-quaddec: Convert to new counter registration

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

Fixes: a3b9a99980d9 ("counter: add FlexTimer Module Quadrature decoder counter driver")
Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Acked-by: William Breathitt Gray <vilhelm.gray@gmail.com>
Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
Link: https://lore.kernel.org/r/20211230150300.72196-19-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
b5d6547c e99dec87

+13 -13
+13 -13
drivers/counter/ftm-quaddec.c
··· 26 26 }) 27 27 28 28 struct ftm_quaddec { 29 - struct counter_device counter; 30 29 struct platform_device *pdev; 31 30 void __iomem *ftm_base; 32 31 bool big_endian; ··· 258 259 259 260 static int ftm_quaddec_probe(struct platform_device *pdev) 260 261 { 262 + struct counter_device *counter; 261 263 struct ftm_quaddec *ftm; 262 264 263 265 struct device_node *node = pdev->dev.of_node; 264 266 struct resource *io; 265 267 int ret; 266 268 267 - ftm = devm_kzalloc(&pdev->dev, sizeof(*ftm), GFP_KERNEL); 268 - if (!ftm) 269 + counter = devm_counter_alloc(&pdev->dev, sizeof(*ftm)); 270 + if (!counter) 269 271 return -ENOMEM; 272 + ftm = counter_priv(counter); 270 273 271 274 io = platform_get_resource(pdev, IORESOURCE_MEM, 0); 272 275 if (!io) { ··· 284 283 dev_err(&pdev->dev, "Failed to map memory region\n"); 285 284 return -EINVAL; 286 285 } 287 - ftm->counter.name = dev_name(&pdev->dev); 288 - ftm->counter.parent = &pdev->dev; 289 - ftm->counter.ops = &ftm_quaddec_cnt_ops; 290 - ftm->counter.counts = &ftm_quaddec_counts; 291 - ftm->counter.num_counts = 1; 292 - ftm->counter.signals = ftm_quaddec_signals; 293 - ftm->counter.num_signals = ARRAY_SIZE(ftm_quaddec_signals); 294 - ftm->counter.priv = ftm; 286 + counter->name = dev_name(&pdev->dev); 287 + counter->parent = &pdev->dev; 288 + counter->ops = &ftm_quaddec_cnt_ops; 289 + counter->counts = &ftm_quaddec_counts; 290 + counter->num_counts = 1; 291 + counter->signals = ftm_quaddec_signals; 292 + counter->num_signals = ARRAY_SIZE(ftm_quaddec_signals); 295 293 296 294 mutex_init(&ftm->ftm_quaddec_mutex); 297 295 ··· 300 300 if (ret) 301 301 return ret; 302 302 303 - ret = devm_counter_register(&pdev->dev, &ftm->counter); 303 + ret = devm_counter_add(&pdev->dev, counter); 304 304 if (ret) 305 - return ret; 305 + return dev_err_probe(&pdev->dev, ret, "Failed to add counter\n"); 306 306 307 307 return 0; 308 308 }