batman-adv: silence smatch errors in multicast compat code

Message ID 1384187589-23259-1-git-send-email-sw@simonwunderlich.de (mailing list archive)
State Superseded, archived
Headers

Commit Message

Simon Wunderlich Nov. 11, 2013, 4:33 p.m. UTC
  smatch is reporting problems of unreachable code parts:

multicast.c:170 batadv_mcast_get_bridge() info: ignoring unreachable
code.
tmp/multicast.c:172 batadv_mcast_get_bridge() info: ignoring
unreachable code.

These are caused by compat code which returns within a loop, never
giving the rest of the function a chance to be processed. This can be
changed by slightly adjusting the compat code, setting the iterator
variable to NULL and let the original function handle the rest. This
does not introduce any functional change.

Introduced by: a3f58139efedb96222dffdda89896c243fdff49e
("batman-adv: Multicast Listener Announcements via Translation Table")

Signed-off-by: Simon Wunderlich <sw@simonwunderlich.de>
---
 compat.h |   14 +++++---------
 1 file changed, 5 insertions(+), 9 deletions(-)
  

Comments

Linus Lüssing Feb. 16, 2014, 11:31 a.m. UTC | #1
On Mon, Nov 11, 2013 at 05:33:09PM +0100, Simon Wunderlich wrote:
> diff --git a/compat.h b/compat.h
> index 186547b..a99c9d5 100644
> --- a/compat.h
> +++ b/compat.h
> @@ -160,14 +160,12 @@ static inline int batadv_param_set_copystring(const char *val,
>  #define NET_ADDR_RANDOM 0
>  
>  #define netdev_master_upper_dev_get_rcu(dev) \
> -	upper; \
> -	rcu_read_unlock(); \
> +	NULL; \
>  	if (dev->br_port ? 1 : 0) { \
> +		rcu_read_unlock(); \
>  		dev_hold(dev); \
>  		return dev; \
>  	} \
> -\
> -	return NULL\
>

This approach unfortunately doesn't work and leads to crashes
because we assign NULL to upper and therefore dev, too, leading to
a null pointer exception when trying to access dev->br-port.

As the smatch warning is just a compat warning not leading to any
issues despite that, could we simply silence the build system to
ignore this instead?
  

Patch

diff --git a/compat.h b/compat.h
index 186547b..a99c9d5 100644
--- a/compat.h
+++ b/compat.h
@@ -160,14 +160,12 @@  static inline int batadv_param_set_copystring(const char *val,
 #define NET_ADDR_RANDOM 0
 
 #define netdev_master_upper_dev_get_rcu(dev) \
-	upper; \
-	rcu_read_unlock(); \
+	NULL; \
 	if (dev->br_port ? 1 : 0) { \
+		rcu_read_unlock(); \
 		dev_hold(dev); \
 		return dev; \
 	} \
-\
-	return NULL\
 
 #endif /* < KERNEL_VERSION(2, 6, 36) */
 
@@ -344,14 +342,12 @@  static int __batadv_interface_set_mac_addr(x, y)
 
 #ifndef netdev_master_upper_dev_get_rcu
 #define netdev_master_upper_dev_get_rcu(dev) \
-	upper; \
-	rcu_read_unlock(); \
+	NULL; \
 	if (dev->priv_flags & IFF_BRIDGE_PORT) { \
+		rcu_read_unlock(); \
 		dev_hold(dev); \
 		return dev; \
-	} \
-\
-	return NULL\
+	}
 
 #endif /* netdev_master_upper_dev_get_rcu */