]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
comedi: comedi_test: Fix possible deletion of uninitialized timers
authorIan Abbott <abbotti@mev.co.uk>
Tue, 8 Jul 2025 13:06:27 +0000 (14:06 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 16 Jul 2025 13:02:44 +0000 (15:02 +0200)
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: 73e0e4dfed4c ("staging: comedi: comedi_test: fix timer lock-up")
Cc: stable@vger.kernel.org # 6.15+
Signed-off-by: Ian Abbott <abbotti@mev.co.uk>
Link: https://lore.kernel.org/r/20250708130627.21743-1-abbotti@mev.co.uk
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/comedi/drivers/comedi_test.c

index 9747e6d1f6eb80d5bf8dfde412e9f7bfbf2ade6f..7984950f0f992cdc64b841dd8ed55b9f2ab93845 100644 (file)
@@ -792,7 +792,7 @@ static void waveform_detach(struct comedi_device *dev)
 {
        struct waveform_private *devpriv = dev->private;
 
-       if (devpriv) {
+       if (devpriv && dev->n_subdevices) {
                timer_delete_sync(&devpriv->ai_timer);
                timer_delete_sync(&devpriv->ao_timer);
        }