This wasn't an issue before the latest checkpatch update. So, we have a code 
base that is already doing both  (ptr == NULL) and !ptr. We are not jumping 
around, checkpatch was changed.

To me both ways are OK:

if (ptr == NULL)
if (ptr != NULL)
if (ptr)
if (!ptr)

It depends on the context and e.g. pointer variable or function naming, which 
one: direct or inverted logic results more readable code.


What's not OK is that style checker prevents user to compare against a @retval 
(NULL) defined in the API. With pointers, NULL results a cleaner API definition 
than 0.

/**
 * Shared memory block address
 *
 * @param[in] shm   Block handle
 *
 * @return Memory block address
 * @retval NULL on failure
 */
void *odp_shm_addr(odp_shm_t shm);



-Petri




> -----Original Message-----
> From: lng-odp [mailto:[email protected]] On Behalf Of
> EXT Maxim Uvarov
> Sent: Monday, September 14, 2015 12:24 PM
> To: [email protected]
> Subject: Re: [lng-odp] new checkpatch CHECK level warning
> 
> The bad thing is that we are going to jump back and forth with style
> define. That
> does not look good. Allowing bunch of different styles is also bad. We
> should allow only
> one style of coding for that thing. I like kernels short checks i.e. if
> (!x).
> 
> Sorry, -1.
> 
> Maxim.
> 
> On 09/12/15 00:29, Bill Fischofer wrote:
> > +1 for deleting this particular warning.
> >
> > On Fri, Sep 11, 2015 at 12:18 PM, Mike Holmes <[email protected]
> > <mailto:[email protected]>> wrote:
> >
> >
> >
> >     On 11 September 2015 at 13:02, Stuart Haslam
> >     <[email protected] <mailto:[email protected]>>
> wrote:
> >
> >         On Fri, Sep 11, 2015 at 12:37:16PM -0400, Mike Holmes wrote:
> >         > Checkpatch is being fixed for that flaw, it was raised but
> >         Nicholas, Viresh
> >         > and myself upstream.
> >         >
> >
> >         Which flaw, the fact that it does complain about x == NULL or
> >         that it
> >         doesn't complain about NULL == x?
> >
> >
> >     https://lkml.org/lkml/2015/8/27/469
> >
> >
> >         Anyway, personally I don't have a problem with any of these;
> >
> >         if (x == NULL)
> >         if (NULL == x)
> >         if (!x)
> >
> >         As long as they're appropriate in the context, so +1 from me
> >         for just
> >         removing the check in the hope we can stop talking about it.
> >
> >
> >     I also have no objection to these three, depending on context
> >     each can be the most readable
> >
> >
> >         --
> >         Stuart.
> >
> >
> >
> >
> >     --
> >     Mike Holmes
> >     Technical Manager - Linaro Networking Group
> >     Linaro.org <http://www.linaro.org/>***│ *Open source software for
> >     ARM SoCs
> >
> >
> >
> >
> > _______________________________________________
> > lng-odp mailing list
> > [email protected]
> > https://lists.linaro.org/mailman/listinfo/lng-odp
> 
> _______________________________________________
> lng-odp mailing list
> [email protected]
> https://lists.linaro.org/mailman/listinfo/lng-odp
_______________________________________________
lng-odp mailing list
[email protected]
https://lists.linaro.org/mailman/listinfo/lng-odp

Reply via email to