Commit e86ba264 authored by Ian Abbott's avatar Ian Abbott Committed by Ben Hutchings

staging: comedi: jr3_pci: fix possible null pointer dereference

commit 45292be0 upstream.

For some reason, the driver does not consider allocation of the
subdevice private data to be a fatal error when attaching the COMEDI
device.  It tests the subdevice private data pointer for validity at
certain points, but omits some crucial tests.  In particular,
`jr3_pci_auto_attach()` calls `jr3_pci_alloc_spriv()` to allocate and
initialize the subdevice private data, but the same function
subsequently dereferences the pointer to access the `next_time_min` and
`next_time_max` members without checking it first.  The other missing
test is in the timer expiry routine `jr3_pci_poll_dev()`, but it will
crash before it gets that far.

Fix the bug by returning `-ENOMEM` from `jr3_pci_auto_attach()` as soon
as one of the calls to `jr3_pci_alloc_spriv()` returns `NULL`.  The
COMEDI core will subsequently call `jr3_pci_detach()` to clean up.
Signed-off-by: default avatarIan Abbott <abbotti@mev.co.uk>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: default avatarBen Hutchings <ben@decadent.org.uk>
parent a6334ec1
...@@ -726,11 +726,12 @@ static int jr3_pci_auto_attach(struct comedi_device *dev, ...@@ -726,11 +726,12 @@ static int jr3_pci_auto_attach(struct comedi_device *dev,
s->insn_read = jr3_pci_ai_insn_read; s->insn_read = jr3_pci_ai_insn_read;
spriv = jr3_pci_alloc_spriv(dev, s); spriv = jr3_pci_alloc_spriv(dev, s);
if (spriv) { if (!spriv)
/* Channel specific range and maxdata */ return -ENOMEM;
s->range_table_list = spriv->range_table_list;
s->maxdata_list = spriv->maxdata_list; /* Channel specific range and maxdata */
} s->range_table_list = spriv->range_table_list;
s->maxdata_list = spriv->maxdata_list;
} }
/* Reset DSP card */ /* Reset DSP card */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment