mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Phil Carmody <ext-phil.2.carmody@nokia.com>
To: ext Alexey Dobriyan <adobriyan@gmail.com>
Cc: "Nikula Jani.1 (EXT-Nixu/Helsinki)" <ext-jani.1.nikula@nokia.com>,
	"akpm@linux-foundation.org" <akpm@linux-foundation.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] err.h: add __must_check to error pointer handlers
Date: Fri, 12 Mar 2010 21:45:17 +0200	[thread overview]
Message-ID: <20100312194517.GU5610@pcarmody-desktop> (raw)
In-Reply-To: <20100312184056.GA4107@x200>

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

      reply	other threads:[~2010-03-12 19:45 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-03-12 13:45 Jani Nikula
2010-03-12 18:40 ` Alexey Dobriyan
2010-03-12 19:45   ` Phil Carmody [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20100312194517.GU5610@pcarmody-desktop \
    --to=ext-phil.2.carmody@nokia.com \
    --cc=adobriyan@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=ext-jani.1.nikula@nokia.com \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome