[i2c] [patch 2.6.26-rc1] i2c_use_client() defends against NULL

David Brownell david-b at pacbell.net
Sat May 17 20:53:04 CEST 2008


On Saturday 17 May 2008, Trent Piepho wrote:
> > > Passing NULL to the current functions would just crash, it wouldn't
> > > morph anything.
> >
> > That's only if you assume an MMU set up to cause oopsing on reference
> > to the first and last pages of memory.  Not the best of assumptions...
> 
> Maybe BUG_ON(!client) would be better?  It seems more likely to catch
> a programming error.

BUG_ON() is almost always the wrong answer though ... it's only
appropriate when there's no way for the system to continue.

And in fact, here it's *not* a bug...

Passing NULL around is more often OK than not.  Example, it's
expected that passing it to a "free this object" routine will
work, saving callers a NULL check.  Similarly, refcount calls.




More information about the i2c mailing list