Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1288710

Re: [PATCH 4/9v2] usb: host: ehci.h: fix single statement macros

From Sergei Shtylyov <sergei.shtylyov@cogentembedded.com>
Newsgroups linux.kernel
Subject Re: [PATCH 4/9v2] usb: host: ehci.h: fix single statement macros
Date 2015-12-10 18:30 +0100
Message-ID <qEdcw-Km-53@gated-at.bofh.it> (permalink)
References (2 earlier) <qE838-5I6-19@gated-at.bofh.it> <qE8wa-69e-13@gated-at.bofh.it> <qE98T-6EN-33@gated-at.bofh.it> <qEaHD-7v5-5@gated-at.bofh.it> <qEaRk-7yx-17@gated-at.bofh.it>
Organization Cogent Embedded

Show all headers | View raw


On 12/10/2015 05:56 PM, Geyslan G. Bem wrote:

>>>>>> Don't use the 'do {} while (0)' wrapper in a single statement macro.
>>>>>>
>>>>>> Caught by checkpatch: "WARNING: Single statement macros should not
>>>>>> use a do {} while (0) loop"
>>>>>>
>>>>>> Signed-off-by: Geyslan G. Bem <geyslan@gmail.com>
>>>>>> ---
>>>>>>     drivers/usb/host/ehci.h | 4 ++--
>>>>>>     1 file changed, 2 insertions(+), 2 deletions(-)
>>>>>>
>>>>>> diff --git a/drivers/usb/host/ehci.h b/drivers/usb/host/ehci.h
>>>>>> index cfeebd8..945000a 100644
>>>>>> --- a/drivers/usb/host/ehci.h
>>>>>> +++ b/drivers/usb/host/ehci.h
>>>>>> @@ -244,9 +244,9 @@ struct ehci_hcd {                   /* one per
>>>>>> controller */
>>>>>>           /* irq statistics */
>>>>>>     #ifdef EHCI_STATS
>>>>>>           struct ehci_stats       stats;
>>>>>> -#      define COUNT(x) do { (x)++; } while (0)
>>>>>> +#      define COUNT(x) ((x)++)
>>>>>>     #else
>>>>>> -#      define COUNT(x) do {} while (0)
>>>>>> +#      define COUNT(x) ((void) 0)
>>>>>
>>>>>
>>>>>
>>>>>      Why not just empty #define?
>>>>
>>>>
>>>> Indeed. I'll change it.
>>>> Tks Sergei.
>>>
>>>
>>> Since COUNT is not used to return the empty #define is ok. Another way
>>> is to use #define COUNT(x) (0) to get a 0 when necessary to read
>>> returns.

>>     Just 0, no parens please.

> Ok, no parens, since there's no evaluation.

    It's because the literals don't need parens at all.

> Then my change is:
>
> -#      define COUNT(x) do { (x)++; } while (0)
> +#      define COUNT(x) (++(x))
>   #else
> -#      define COUNT(x) do {} while (0)
> +#      define COUNT(x) 0
>
> Pre-increment allowing to return the updated x.

    Why if there was a post-increment before?

    Anyway, this talk is quite pointless since the macro didn't return any 
value anyway.

MBR, Sergei

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[PATCH 1/9v2] usb: host: ehci.h: remove space before comma "Geyslan G. Bem" <geyslan@gmail.com> - 2015-12-09 23:40 +0100
  [PATCH 3/9v2] usb: host: ehci.h: remove space before open square bracket "Geyslan G. Bem" <geyslan@gmail.com> - 2015-12-09 23:40 +0100
    Re: [PATCH 3/9v2] usb: host: ehci.h: remove space before open square  bracket Peter Senna Tschudin <peter.senna@gmail.com> - 2015-12-10 10:30 +0100
  [PATCH 4/9v2] usb: host: ehci.h: fix single statement macros "Geyslan G. Bem" <geyslan@gmail.com> - 2015-12-09 23:40 +0100
    Re: [PATCH 4/9v2] usb: host: ehci.h: fix single statement macros Peter Senna Tschudin <peter.senna@gmail.com> - 2015-12-10 11:00 +0100
    Re: [PATCH 4/9v2] usb: host: ehci.h: fix single statement macros Sergei Shtylyov <sergei.shtylyov@cogentembedded.com> - 2015-12-10 13:00 +0100
      Re: [PATCH 4/9v2] usb: host: ehci.h: fix single statement macros "Geyslan G. Bem" <geyslan@gmail.com> - 2015-12-10 13:30 +0100
        Re: [PATCH 4/9v2] usb: host: ehci.h: fix single statement macros "Geyslan G. Bem" <geyslan@gmail.com> - 2015-12-10 14:10 +0100
          Re: [PATCH 4/9v2] usb: host: ehci.h: fix single statement macros Sergei Shtylyov <sergei.shtylyov@cogentembedded.com> - 2015-12-10 15:50 +0100
            Re: [PATCH 4/9v2] usb: host: ehci.h: fix single statement macros "Geyslan G. Bem" <geyslan@gmail.com> - 2015-12-10 16:00 +0100
              Re: [PATCH 4/9v2] usb: host: ehci.h: fix single statement macros Sergei Shtylyov <sergei.shtylyov@cogentembedded.com> - 2015-12-10 18:30 +0100
                Re: [PATCH 4/9v2] usb: host: ehci.h: fix single statement macros Sergei Shtylyov <sergei.shtylyov@cogentembedded.com> - 2015-12-10 18:50 +0100
                Re: [PATCH 4/9v2] usb: host: ehci.h: fix single statement macros "Geyslan G. Bem" <geyslan@gmail.com> - 2015-12-10 19:10 +0100
                Re: [PATCH 4/9v2] usb: host: ehci.h: fix single statement macros "Geyslan G. Bem" <geyslan@gmail.com> - 2015-12-10 18:50 +0100
  [PATCH 5/9v2] usb: host: ehci.h: remove direct use of __attribute__ keyword "Geyslan G. Bem" <geyslan@gmail.com> - 2015-12-09 23:40 +0100
    Re: [PATCH 5/9v2] usb: host: ehci.h: remove direct use of  __attribute__ keyword Peter Senna Tschudin <peter.senna@gmail.com> - 2015-12-10 11:10 +0100
      Re: [PATCH 5/9v2] usb: host: ehci.h: remove direct use of  __attribute__ keyword "Geyslan G. Bem" <geyslan@gmail.com> - 2015-12-10 11:30 +0100
  [PATCH 7/9v2] usb: host: ehci.h: remove macros trailing semicolon "Geyslan G. Bem" <geyslan@gmail.com> - 2015-12-09 23:40 +0100
    Re: [PATCH 7/9v2] usb: host: ehci.h: remove macros trailing semicolon Peter Senna Tschudin <peter.senna@gmail.com> - 2015-12-10 11:30 +0100
  [PATCH 6/9v2] usb: host: ehci.h: use space after comma "Geyslan G. Bem" <geyslan@gmail.com> - 2015-12-09 23:40 +0100
    Re: [PATCH 6/9v2] usb: host: ehci.h: use space after comma Peter Senna Tschudin <peter.senna@gmail.com> - 2015-12-10 11:20 +0100
      Re: [PATCH 6/9v2] usb: host: ehci.h: use space after comma Alan Stern <stern@rowland.harvard.edu> - 2015-12-10 17:00 +0100
        Re: [PATCH 6/9v2] usb: host: ehci.h: use space after comma "Geyslan G. Bem" <geyslan@gmail.com> - 2015-12-10 17:10 +0100
  Re: [PATCH 1/9v2] usb: host: ehci.h: remove space before comma Peter Senna Tschudin <peter.senna@gmail.com> - 2015-12-10 10:20 +0100

csiph-web