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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 12/10/2015 08:40 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@xxxxxxxxx>
---
     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?

There's nothing wrong with post-increment. The pre one would be
necessary if using return.

   Maybe it was intended to return the old value? :-)


    Anyway, this talk is quite pointless since the macro didn't return any
value anyway.
You're sure, there's no use anywhere of the return of that macro indeed.

*do* {} *while* (0) just couldn't return any value, it's not just a compound statement which gcc indeed allows to be evaluated.

Sending v2 soon.

MBR, Sergei

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Linux Media]     [Linux Input]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Old Linux USB Devel Archive]

  Powered by Linux