lkml.org 
[lkml]   [2010]   [Mar]   [12]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH] err.h: add __must_check to error pointer handlers
On 12/03/10 19:40 +0100, ext Alexey Dobriyan wrote:
> On Fri, Mar 12, 2010 at 03:45:40PM +0200, Jani Nikula wrote:
> > Add __must_check to error pointer handlers to have the compiler warn
> > about mistakes like:
> >
> > if (err)
> > ERR_PTR(err);
>
> > -static inline void *ERR_PTR(long error)
> > +static inline void * __must_check ERR_PTR(long error)
>
> We had bugs like that?

Two popped out immediately. Patches have been sent to appropriate
maintainers. Grepping my inbox:

Mar 12 Nikula Jani [PATCH] enclosure: fix error path - actually return ERR_PTR() on error
Mar 12 Nikula Jani [PATCH] sunrpc: fix error path - actually return ERR_PTR() on error

There's a slim chance that there may be others (grep doesn't find any
more obvious ones), but as allmodconfig seems broken currently, there
may be others which are as yet undiscovered.

> Pretty much every non-void function should be marked then.

All functions where it makes no sense ignore the return value. You
really wouldn't be doing an ERR_PTR unless you wanted to use the result.

Note that __must_check doesn't actually require 'checking', merely
'using' the return value, which includes just storing it in a variable,
and then later ignoring it.

An alternative static code analysis method could be used to detect such
things. Coverity Prevent uses a heuristic algorithm to detect missing
checks of return values using a popularity contest. Most people check
it - then everyone should probably check it.

Phil


\
 
 \ /
  Last update: 2010-03-12 20:47    [W:0.630 / U:0.992 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site