lkml.org 
[lkml]   [2015]   [Jul]   [22]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
From
SubjectRE: [PATCH V3 3/7] Drivers: hv: vmbus: add APIs to send/recv hvsock packet and get the r/w-ability
Date
> From: Dan Carpenter
> Sent: Wednesday, July 22, 2015 18:36
> To: Dexuan Cui
> On Wed, Jul 22, 2015 at 10:09:10AM +0000, Dexuan Cui wrote:
> > > I'd suggest you do something like
> > >
> > > if (ret == -EAGIAIN)
> > > return 0;
> > > else if (ret)
> > > return ret;
> > >
> > > to make it future-proof (e.g. when a new error is returned by
> > > hv_ringbuffer_peek). And a comment would also be useful as it is unclear
> > > why we silence errors here.
> > Hi Vitaly,
> > Thanks!
> > I think I made a mistake here:
> > the "if (ret != 0) return 0;" should be changed
> > to "if (ret != 0) return ret;"
Usually 0 means success to me, so
to me, "ret != 0" reads like "ret is not successful" and seems natural.

The kind of usage is not rare in the kernel code:

decui@lin:~/linux-next$ grep 'if (ret != 0)' kernel/ include/ ipc/ -r | wc -l
28
decui@lin:~/linux-next$ grep 'if (ret != 0)' drivers/ -r | wc -l
1031

> The double negative really doesn't not make the code more complicated.
> I like using a quadruple negative instead.
>
> if (ret != 0 != 0)
> return ret;
> dan carpenter
Hi Dan, I read this as a humor. :-)

I'll take the suggestion and remember to use this in V4 and in future:

if (ret)
return ret;

Thanks!

-- Dexuan



\
 
 \ /
  Last update: 2015-07-23 05:41    [W:1.246 / U:0.528 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site