Skip to content

Commit 1b98304

Browse files
ian-abbottgregkh
authored andcommitted
comedi: comedi_test: Fix possible deletion of uninitialized timers
In `waveform_common_attach()`, the two timers `&devpriv->ai_timer` and `&devpriv->ao_timer` are initialized after the allocation of the device private data by `comedi_alloc_devpriv()` and the subdevices by `comedi_alloc_subdevices()`. The function may return with an error between those function calls. In that case, `waveform_detach()` will be called by the Comedi core to clean up. The check that `waveform_detach()` uses to decide whether to delete the timers is incorrect. It only checks that the device private data was allocated, but that does not guarantee that the timers were initialized. It also needs to check that the subdevices were allocated. Fix it. Fixes: 73e0e4d ("staging: comedi: comedi_test: fix timer lock-up") Cc: [email protected] # 6.15+ Signed-off-by: Ian Abbott <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 46d8c74 commit 1b98304

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

drivers/comedi/drivers/comedi_test.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -792,7 +792,7 @@ static void waveform_detach(struct comedi_device *dev)
792792
{
793793
struct waveform_private *devpriv = dev->private;
794794

795-
if (devpriv) {
795+
if (devpriv && dev->n_subdevices) {
796796
timer_delete_sync(&devpriv->ai_timer);
797797
timer_delete_sync(&devpriv->ao_timer);
798798
}

0 commit comments

Comments
 (0)