Skip to contentSkip to conversation

staging: comedi: add error handling for vmap

PATCH In review Zhouyang Jia 3 participants 3 messages Jun 12, 2018 – Jun 14, 2018 1 message not in the archive Staging

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 staging: comedi: add error handling for vmap

When vmap fails, the lack of error-handling code may cause unexpected results.

This patch adds error-handling code after calling vmap.

---
 drivers/staging/comedi/comedi_buf.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/staging/comedi/comedi_buf.c +4 -1
index f693c2c..5e48693 100644
@@ -132,9 +132,12 @@ static void __comedi_buf_alloc(struct comedi_device *dev,
 	spin_unlock_irqrestore(&s->spin_lock, flags);
 
 	/* vmap the prealloc_buf if all the pages were allocated */
-	if (i == n_pages)
+	if (i == n_pages) {
 		async->prealloc_buf = vmap(pages, n_pages, VM_MAP,
 					   COMEDI_PAGE_PROTECTION);
+		if (!async->prealloc_buf)
+			dev_err(dev->class_dev, "failed to vmap pages\n");
+	}
 
 	vfree(pages);
 }
Signature · 1 line
2.7.4
#1 lore raw
Quoted 5 lines · Zhouyang Jia

When vmap fails, the lack of error-handling code may cause unexpected results.

This patch adds error-handling code after calling vmap.

Again, this is not error handling, this is just an error message. This error condition is handled in the caller.

regards,
dan carpenter

A message that is not in the archive (sent off-list or not yet received): CABb2TxKVnC3KkCAs501ffzomOF8GLfLqDvWW=z7mHRf8UKc9YQ@mail.gmail.com

#3 lore raw
Quoted 7 lines · Zhouyang Jia

Hi,

I reported this bug since more than 90% callsites of vmap are well handled in kernel. The caller function __comedi_buf_alloc has no return value, so I don't know how the error is handled in its caller.

Quoted 7 lines

I believe there would be a better error handling method, but I have limited domain knowledge, so I'm sorry I can't help here.

Thanks for your kind reply.

Best,
Zhouyang

__comedi_buf_alloc is just a helper function factored out of, and called by comedi_buf_alloc. __comedi_buf_alloc does not clean up after itself on error because it expects comedi_buf_alloc to detect the error and call __comedi_buf_free to clean up any partially allocated mess:

    __comedi_buf_alloc(dev, s, n_pages);
    if (!async->prealloc_buf) {
        /*
         * [This is not the actual comment in the code!]
         *
         * Error occured in __comedi_buf_alloc().
         * Buffer may be partially allocated.
         * Call __comedi_buf_free() to clean it up.
         */
        __comedi_buf_free(dev, s);
        return -ENOMEM;
    }
Quoted 20 lines

2018-06-12 19:50 GMT+08:00 Dan Carpenter <[email protected] <mailto:[email protected]>>:

On Tue, Jun 12, 2018 at 11:25:35AM +0800, Zhouyang Jia wrote:
> When vmap fails, the lack of error-handling code may > cause unexpected results.
>
> This patch adds error-handling code after calling vmap. >

Again, this is not error handling, this is just an error message.  This error condition is handled in the caller.

regards,
dan carpenter

Signature · 4 lines
-=( Ian Abbott <[email protected]> || Web: www.mev.co.uk )=-
-=( MEV Ltd. is a company registered in England & Wales. )=-
-=( Registered number: 02862268.  Registered address:    )=-
-=( 15 West Park Road, Bramhall, STOCKPORT, SK7 3JZ, UK. )=-