99f90386d8b3d5e3317ac3e11b47db18abbfe380
[feed/routing.git] / batman-adv / patches / 0006-batman-adv-Make-MCAST-capability-changes-atomic.patch
1 From 201a54ba710ab7f40b82ad3c109f702c47d0761f Mon Sep 17 00:00:00 2001
2 From: =?UTF-8?q?Linus=20L=C3=BCssing?= <linus.luessing@c0d3.blue>
3 Date: Tue, 16 Jun 2015 17:10:25 +0200
4 Subject: [PATCH 06/13] batman-adv: Make MCAST capability changes atomic
5 MIME-Version: 1.0
6 Content-Type: text/plain; charset=UTF-8
7 Content-Transfer-Encoding: 8bit
8
9 Bitwise OR/AND assignments in C aren't guaranteed to be atomic. One
10 OGM handler might undo the set/clear of a specific bit from another
11 handler run in between.
12
13 Fix this by using the atomic set_bit()/clear_bit() functions.
14
15 Fixes: 77ec494490d6 ("batman-adv: Announce new capability via multicast TVLV")
16 Signed-off-by: Linus Lüssing <linus.luessing@c0d3.blue>
17 Signed-off-by: Marek Lindner <mareklindner@neomailbox.ch>
18 ---
19 multicast.c | 6 +++---
20 1 file changed, 3 insertions(+), 3 deletions(-)
21
22 diff --git a/multicast.c b/multicast.c
23 index 09f2838..00612bf 100644
24 --- a/multicast.c
25 +++ b/multicast.c
26 @@ -684,7 +684,7 @@ static void batadv_mcast_tvlv_ogm_handler_v1(struct batadv_priv *bat_priv,
27 !(orig->capabilities & BATADV_ORIG_CAPA_HAS_MCAST)) {
28 if (orig_initialized)
29 atomic_dec(&bat_priv->mcast.num_disabled);
30 - orig->capabilities |= BATADV_ORIG_CAPA_HAS_MCAST;
31 + set_bit(BATADV_ORIG_CAPA_HAS_MCAST, &orig->capabilities);
32 /* If mcast support is being switched off or if this is an initial
33 * OGM without mcast support then increase the disabled mcast
34 * node counter.
35 @@ -693,10 +693,10 @@ static void batadv_mcast_tvlv_ogm_handler_v1(struct batadv_priv *bat_priv,
36 (orig->capabilities & BATADV_ORIG_CAPA_HAS_MCAST ||
37 !orig_initialized)) {
38 atomic_inc(&bat_priv->mcast.num_disabled);
39 - orig->capabilities &= ~BATADV_ORIG_CAPA_HAS_MCAST;
40 + clear_bit(BATADV_ORIG_CAPA_HAS_MCAST, &orig->capabilities);
41 }
42
43 - orig->capa_initialized |= BATADV_ORIG_CAPA_HAS_MCAST;
44 + set_bit(BATADV_ORIG_CAPA_HAS_MCAST, &orig->capa_initialized);
45
46 if (orig_mcast_enabled && tvlv_value &&
47 (tvlv_value_len >= sizeof(mcast_flags)))
48 --
49 2.1.4
50