batman-adv: Avoid precedence issues in macros
authorSven Eckelmann <sven@narfation.org>
Wed, 21 Sep 2016 07:23:50 +0000 (09:23 +0200)
committerSimon Wunderlich <sw@simonwunderlich.de>
Wed, 19 Oct 2016 06:37:54 +0000 (08:37 +0200)
It must be avoided that arguments to a macro are evaluated ungrouped (which
enforces normal operator precendence). Otherwise the result of the macro
is not well defined.

Signed-off-by: Sven Eckelmann <sven@narfation.org>
Signed-off-by: Simon Wunderlich <sw@simonwunderlich.de>
net/batman-adv/log.h
net/batman-adv/main.h
net/batman-adv/packet.h

index e0e1a88c3e5807dfefea4dc0f255b69087c1f15b..ab47acf2eb01e206b656ecc7f39e51dbbc2a1589 100644 (file)
@@ -71,12 +71,12 @@ int batadv_debug_log(struct batadv_priv *bat_priv, const char *fmt, ...)
 __printf(2, 3);
 
 /* possibly ratelimited debug output */
-#define _batadv_dbg(type, bat_priv, ratelimited, fmt, arg...)  \
-       do {                                                    \
-               if (atomic_read(&bat_priv->log_level) & type && \
-                   (!ratelimited || net_ratelimit()))          \
-                       batadv_debug_log(bat_priv, fmt, ## arg);\
-       }                                                       \
+#define _batadv_dbg(type, bat_priv, ratelimited, fmt, arg...)          \
+       do {                                                            \
+               if (atomic_read(&(bat_priv)->log_level) & (type) &&     \
+                   (!(ratelimited) || net_ratelimit()))                \
+                       batadv_debug_log(bat_priv, fmt, ## arg);        \
+       }                                                               \
        while (0)
 #else /* !CONFIG_BATMAN_ADV_DEBUG */
 __printf(4, 5)
index 6a2328d177097e7e0dc1ab5330c1e7a9c1cd43f3..daddca94feb89f8c53248998dbc4379a01ef6891 100644 (file)
@@ -199,8 +199,8 @@ struct packet_type;
 struct seq_file;
 struct sk_buff;
 
-#define BATADV_PRINT_VID(vid) ((vid & BATADV_VLAN_HAS_TAG) ? \
-                              (int)(vid & VLAN_VID_MASK) : -1)
+#define BATADV_PRINT_VID(vid) (((vid) & BATADV_VLAN_HAS_TAG) ? \
+                              (int)((vid) & VLAN_VID_MASK) : -1)
 
 extern struct list_head batadv_hardif_list;
 
index d2e9bbd5f46d8bc6861af981b1b8623dcfa3ad19..7a36bcfa0ba01993080b2ad1ddca94ca0d50adc9 100644 (file)
@@ -21,7 +21,7 @@
 #include <asm/byteorder.h>
 #include <linux/types.h>
 
-#define batadv_tp_is_error(n) ((u8)n > 127 ? 1 : 0)
+#define batadv_tp_is_error(n) ((u8)(n) > 127 ? 1 : 0)
 
 /**
  * enum batadv_packettype - types for batman-adv encapsulated packets