]> git.hungrycats.org Git - linux/commitdiff
batman-adv: Make TT capability changes atomic
authorLinus Lüssing <linus.luessing@c0d3.blue>
Tue, 16 Jun 2015 15:10:24 +0000 (17:10 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 22 Oct 2015 21:43:23 +0000 (14:43 -0700)
commit ac4eebd48461ec993e7cb614d5afe7df8c72e6b7 upstream.

Bitwise OR/AND assignments in C aren't guaranteed to be atomic. One
OGM handler might undo the set/clear of a specific bit from another
handler run in between.

Fix this by using the atomic set_bit()/clear_bit()/test_bit() functions.

Fixes: e17931d1a61d ("batman-adv: introduce capability initialization bitfield")
Signed-off-by: Linus Lüssing <linus.luessing@c0d3.blue>
Signed-off-by: Marek Lindner <mareklindner@neomailbox.ch>
Signed-off-by: Antonio Quartulli <antonio@meshcoding.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
net/batman-adv/translation-table.c
net/batman-adv/types.h

index deb87c6870aaa10a56f56bfb2a43dc96fea1c64f..4f2a9d2c56dbba0f7845ef747e94c7c53576d5c8 100644 (file)
@@ -15,6 +15,7 @@
  * along with this program; if not, see <http://www.gnu.org/licenses/>.
  */
 
+#include <linux/bitops.h>
 #include "main.h"
 #include "translation-table.h"
 #include "soft-interface.h"
@@ -1860,7 +1861,7 @@ void batadv_tt_global_del_orig(struct batadv_priv *bat_priv,
                }
                spin_unlock_bh(list_lock);
        }
-       orig_node->capa_initialized &= ~BATADV_ORIG_CAPA_HAS_TT;
+       clear_bit(BATADV_ORIG_CAPA_HAS_TT, &orig_node->capa_initialized);
 }
 
 static bool batadv_tt_global_to_purge(struct batadv_tt_global_entry *tt_global,
@@ -2819,7 +2820,7 @@ static void _batadv_tt_update_changes(struct batadv_priv *bat_priv,
                                return;
                }
        }
-       orig_node->capa_initialized |= BATADV_ORIG_CAPA_HAS_TT;
+       set_bit(BATADV_ORIG_CAPA_HAS_TT, &orig_node->capa_initialized);
 }
 
 static void batadv_tt_fill_gtable(struct batadv_priv *bat_priv,
@@ -3321,7 +3322,8 @@ static void batadv_tt_update_orig(struct batadv_priv *bat_priv,
        bool has_tt_init;
 
        tt_vlan = (struct batadv_tvlv_tt_vlan_data *)tt_buff;
-       has_tt_init = orig_node->capa_initialized & BATADV_ORIG_CAPA_HAS_TT;
+       has_tt_init = test_bit(BATADV_ORIG_CAPA_HAS_TT,
+                              &orig_node->capa_initialized);
 
        /* orig table not initialised AND first diff is in the OGM OR the ttvn
         * increased by one -> we can apply the attached changes
index 767390318c86a7b17da5e23097d7edf974d01095..4d3de8d8f331e01c2ff7787eab4745690ab18022 100644 (file)
@@ -257,7 +257,7 @@ struct batadv_orig_node {
        struct hlist_node mcast_want_all_ipv6_node;
 #endif
        unsigned long capabilities;
-       uint8_t capa_initialized;
+       unsigned long capa_initialized;
        atomic_t last_ttvn;
        unsigned char *tt_buff;
        int16_t tt_buff_len;
@@ -298,7 +298,7 @@ struct batadv_orig_node {
 enum batadv_orig_capabilities {
        BATADV_ORIG_CAPA_HAS_DAT,
        BATADV_ORIG_CAPA_HAS_NC,
-       BATADV_ORIG_CAPA_HAS_TT = BIT(2),
+       BATADV_ORIG_CAPA_HAS_TT,
        BATADV_ORIG_CAPA_HAS_MCAST = BIT(3),
 };