staging: comedi: gsc_hpdi: check dma_alloc_coherent() return value
authorIan Abbott <abbotti@mev.co.uk>
Mon, 16 Dec 2019 11:08:23 +0000 (11:08 +0000)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 31 Dec 2019 11:37:58 +0000 (12:37 +0100)
commitc67a2906487c75e9415d9ea1c6ca622a9e63a769
treedcd6bd0629fe26bed58410adb92285ad591a3184
parent6cc3ecc1ac2364cddd8bf44dcfdd6123dd63d14c
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> #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>
drivers/staging/comedi/drivers/gsc_hpdi.c