Subject: Re: [PATCH -net] netpoll: fix NULL pointer dereference in netpoll_cleanup

From: Nikolay Aleksandrov <[email-masked]>
Date: Wed, 18 Sep 2013 23:09:11 +0200

On 09/18/2013 06:25 PM, Joe Perches wrote:
> On Wed, 2013-09-18 at 12:15 -0400, David Miller wrote:
>> From: Nikolay Aleksandrov <[email-masked]>
>> Date: Tue, 17 Sep 2013 16:12:35 +0200
>>
>>> @@ -1284,15 +1284,15 @@ EXPORT_SYMBOL_GPL(__netpoll_free_async);
>>>  
>>>  void netpoll_cleanup(struct netpoll *np)
>>>  {
>>> -     if (!np->dev)
>>> -             return;
>>> -
>>>       rtnl_lock();
>>> +     if (!np->dev) {
>>> +             rtnl_unlock();
>>> +             return;
>>> +     }
>>>       __netpoll_cleanup(np);
>>> -     rtnl_unlock();
>>> -
>>>       dev_put(np->dev);
>>>       np->dev = NULL;
>>> +     rtnl_unlock();
>>>  }
>>>  EXPORT_SYMBOL(netpoll_cleanup);
>>
>> I know it seems arbitrary, but please do this like:
>>
>>         lock();
>>         if (condition) {
>>                 ...
>>         }
>>         unlock();
>>
>> rather than having multiple return/unlock code paths.
>>
>> This style I am suggesting is easier to audit for locking problems.
> 
> Another alternative is:
> 
> 	lock();
> 
> 	if (!condition)
> 		goto out;
> 
> 	...
> 
> out:
> 	unlock();
> 	return ...;
> }
> 
Yup, this is the alternative I plan to use :-)

Thanks Joe