[patch] of: check for IS_ERR()

Grant Likely grant.likely at secretlab.ca
Sat Feb 27 03:11:46 EST 2010


On Fri, Feb 26, 2010 at 2:54 AM, David Miller <davem at davemloft.net> wrote:
> From: Dan Carpenter <error27 at gmail.com>
> Date: Fri, 26 Feb 2010 12:49:41 +0300
>
>> get_phy_device() can return an ERR_PTR()
>>
>> Signed-off-by: Dan Carpenter <error27 at gmail.com>
>> ---
>> I don't have a cross compile environment set up so I can't even compile
>> test this.  :/  But err.h is included so it should be OK.
>
> It should return ERR_PTR() consistently.  Checking for both
> NULL and ERR_PTR() is undesirable.

Ugh.  This is why I dislike the ERR_PTR() pattern so much.  The
compiler cannot do any type checking and it is implemented
inconsistently.  You have to go look at the calling function to find
out what you're allowed to do with the return value.  ie. which test
do I use? (!ptr) or IS_ERR(ptr)?

It would be better if ERR_PTR() returned a structure or a union.  At
least that way the compiler would yell at you if the an ERR_PTR was
being returned.

g.

-- 
Grant Likely, B.Sc., P.Eng.
Secret Lab Technologies Ltd.


More information about the devicetree-discuss mailing list