Skip to content

Commit c67a290

Browse files
ian-abbottgregkh
authored andcommitted
staging: comedi: gsc_hpdi: check dma_alloc_coherent() return value
commit ab42b48f32d4c766420c3499ee9c0289b7028182 upstream. 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> OnePlusOSS#4.6+ Signed-off-by: Ian Abbott <abbotti@mev.co.uk> Link: https://lore.kernel.org/r/20191216110823.216237-1-abbotti@mev.co.uk Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 6cc3ecc commit c67a290

1 file changed

Lines changed: 10 additions & 0 deletions

File tree

drivers/staging/comedi/drivers/gsc_hpdi.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -632,13 +632,23 @@ static int gsc_hpdi_auto_attach(struct comedi_device *dev,
632632
dma_alloc_coherent(&pcidev->dev, DMA_BUFFER_SIZE,
633633
&devpriv->dio_buffer_phys_addr[i],
634634
GFP_KERNEL);
635+
if (!devpriv->dio_buffer[i]) {
636+
dev_warn(dev->class_dev,
637+
"failed to allocate DMA buffer\n");
638+
return -ENOMEM;
639+
}
635640
}
636641
/* allocate dma descriptors */
637642
devpriv->dma_desc = dma_alloc_coherent(&pcidev->dev,
638643
sizeof(struct plx_dma_desc) *
639644
NUM_DMA_DESCRIPTORS,
640645
&devpriv->dma_desc_phys_addr,
641646
GFP_KERNEL);
647+
if (!devpriv->dma_desc) {
648+
dev_warn(dev->class_dev,
649+
"failed to allocate DMA descriptors\n");
650+
return -ENOMEM;
651+
}
642652
if (devpriv->dma_desc_phys_addr & 0xf) {
643653
dev_warn(dev->class_dev,
644654
" dma descriptors not quad-word aligned (bug)\n");

0 commit comments

Comments
 (0)