Commit ab42b48f authored by Ian Abbott's avatar Ian Abbott Committed by Greg Kroah-Hartman

staging: comedi: gsc_hpdi: check dma_alloc_coherent() return value

The "auto-attach" handler function `gsc_hpdi_auto_attach()` calls
`dma_alloc_coherent()` in a loop to allocate some DMA data buffers, and
also calls it to allocate a buffer for a DMA descriptor chain.  However,
it does not check the return value of any of these calls.  Change
`gsc_hpdi_auto_attach()` to return `-ENOMEM` if any of these
`dma_alloc_coherent()` calls fail.  This will result in the comedi core
calling the "detach" handler `gsc_hpdi_detach()` as part of the
clean-up, which will call `gsc_hpdi_free_dma()` to free any allocated
DMA coherent memory buffers.

Cc: <stable@vger.kernel.org> #4.6+
Signed-off-by: default avatarIan Abbott <abbotti@mev.co.uk>
Link: https://lore.kernel.org/r/20191216110823.216237-1-abbotti@mev.co.ukSigned-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent d1eef1c6
...@@ -623,6 +623,11 @@ static int gsc_hpdi_auto_attach(struct comedi_device *dev, ...@@ -623,6 +623,11 @@ static int gsc_hpdi_auto_attach(struct comedi_device *dev,
dma_alloc_coherent(&pcidev->dev, DMA_BUFFER_SIZE, dma_alloc_coherent(&pcidev->dev, DMA_BUFFER_SIZE,
&devpriv->dio_buffer_phys_addr[i], &devpriv->dio_buffer_phys_addr[i],
GFP_KERNEL); GFP_KERNEL);
if (!devpriv->dio_buffer[i]) {
dev_warn(dev->class_dev,
"failed to allocate DMA buffer\n");
return -ENOMEM;
}
} }
/* allocate dma descriptors */ /* allocate dma descriptors */
devpriv->dma_desc = dma_alloc_coherent(&pcidev->dev, devpriv->dma_desc = dma_alloc_coherent(&pcidev->dev,
...@@ -630,6 +635,11 @@ static int gsc_hpdi_auto_attach(struct comedi_device *dev, ...@@ -630,6 +635,11 @@ static int gsc_hpdi_auto_attach(struct comedi_device *dev,
NUM_DMA_DESCRIPTORS, NUM_DMA_DESCRIPTORS,
&devpriv->dma_desc_phys_addr, &devpriv->dma_desc_phys_addr,
GFP_KERNEL); GFP_KERNEL);
if (!devpriv->dma_desc) {
dev_warn(dev->class_dev,
"failed to allocate DMA descriptors\n");
return -ENOMEM;
}
if (devpriv->dma_desc_phys_addr & 0xf) { if (devpriv->dma_desc_phys_addr & 0xf) {
dev_warn(dev->class_dev, dev_warn(dev->class_dev,
" dma descriptors not quad-word aligned (bug)\n"); " dma descriptors not quad-word aligned (bug)\n");
......
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