On 2013-05-10 17:27, H Hartley Sweeten wrote:
On Friday, May 10, 2013 6:07 AM, Ian Abbott wrote:
When allocating a buffer to support asynchronous comedi commands, if a
DMA coherent buffer was requested but `CONFIG_HAS_DMA` is undefined,
bail out of local helper function `__comedi_buf_alloc()` with an error
message.

Signed-off-by: Ian Abbott <abbo...@mev.co.uk>
---
  drivers/staging/comedi/comedi_buf.c | 6 ++++++
  1 file changed, 6 insertions(+)

diff --git a/drivers/staging/comedi/comedi_buf.c 
b/drivers/staging/comedi/comedi_buf.c
index b6cd67a..d4be0e6 100644
--- a/drivers/staging/comedi/comedi_buf.c
+++ b/drivers/staging/comedi/comedi_buf.c
@@ -76,6 +76,12 @@ static void __comedi_buf_alloc(struct comedi_device *dev,
        struct comedi_buf_page *buf;
        unsigned i;

+       if (!IS_ENABLED(CONFIG_HAS_DMA) && s->async_dma_dir != DMA_NONE) {
+               dev_err(dev->class_dev,
+                       "dma buffer allocation not supported\n");
+               return;
+       }
+
        async->buf_page_list = vzalloc(sizeof(*buf) * n_pages);
        if (async->buf_page_list)
                pages = vmalloc(sizeof(struct page *) * n_pages);

Would it be better to put this test in comedi_buf_alloc() and return a different
errno?

With the check in __comedi_buf_alloc(), comedi_buf_alloc() needlessly calls
__comedi_buf_free() and __comedi_buf_alloc() before returning an errno of
-ENOMEM. I think an errno of -ENOSYS, or even -EINVAL, would be more
appropriate.

What would a fake dma_alloc_coherent() inline stub function return if it existed? I think it might return -ENOMEM. Since __comedi_buf_alloc() is only called from comedi_buf_alloc() and could easily be changed to return an errno, I don't think it matters where the test is done.

--
-=( Ian Abbott @ MEV Ltd.    E-mail: <abbo...@mev.co.uk>        )=-
-=( Tel: +44 (0)161 477 1898   FAX: +44 (0)161 718 3587         )=-
_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/devel

Reply via email to