1313#include <linux/bug.h>
1414#include <linux/byteorder/generic.h>
1515#include <linux/cache.h>
16+ #include <linux/compiler.h>
1617#include <linux/container_of.h>
1718#include <linux/errno.h>
1819#include <linux/etherdevice.h>
@@ -274,7 +275,7 @@ batadv_iv_ogm_emit_send_time(const struct batadv_priv *bat_priv)
274275{
275276 unsigned int msecs ;
276277
277- msecs = atomic_read ( & bat_priv -> orig_interval ) - BATADV_JITTER ;
278+ msecs = READ_ONCE ( bat_priv -> orig_interval ) - BATADV_JITTER ;
278279 msecs += get_random_u32_below (2 * BATADV_JITTER );
279280
280281 return jiffies + msecs_to_jiffies (msecs );
@@ -289,7 +290,7 @@ static unsigned long batadv_iv_ogm_fwd_send_time(void)
289290/* apply hop penalty for a normal link */
290291static u8 batadv_hop_penalty (u8 tq , const struct batadv_priv * bat_priv )
291292{
292- int hop_penalty = atomic_read ( & bat_priv -> hop_penalty );
293+ int hop_penalty = READ_ONCE ( bat_priv -> hop_penalty );
293294 int new_tq ;
294295
295296 new_tq = tq * (BATADV_TQ_MAX_VALUE - hop_penalty );
@@ -555,7 +556,7 @@ static bool batadv_iv_ogm_aggregate_new(const unsigned char *packet_buff,
555556 unsigned int skb_size ;
556557 atomic_t * queue_left = own_packet ? NULL : & bat_priv -> batman_queue_left ;
557558
558- if (atomic_read ( & bat_priv -> aggregated_ogms ))
559+ if (READ_ONCE ( bat_priv -> aggregated_ogms ))
559560 skb_size = max_t (unsigned int , BATADV_MAX_AGGREGATION_BYTES ,
560561 packet_len );
561562 else
@@ -641,15 +642,18 @@ static bool batadv_iv_ogm_queue_add(struct batadv_priv *bat_priv,
641642 struct batadv_ogm_packet * batadv_ogm_packet ;
642643 bool direct_link ;
643644 unsigned long max_aggregation_jiffies ;
645+ bool aggregated_ogms ;
644646
645647 batadv_ogm_packet = (struct batadv_ogm_packet * )packet_buff ;
646648 direct_link = !!(batadv_ogm_packet -> flags & BATADV_DIRECTLINK );
647649 max_aggregation_jiffies = msecs_to_jiffies (BATADV_MAX_AGGREGATION_MS );
648650
649651 /* find position for the packet in the forward queue */
650652 spin_lock_bh (& bat_priv -> forw_bat_list_lock );
653+ aggregated_ogms = READ_ONCE (bat_priv -> aggregated_ogms );
654+
651655 /* own packets are not to be aggregated */
652- if (atomic_read ( & bat_priv -> aggregated_ogms ) && !own_packet ) {
656+ if (aggregated_ogms && !own_packet ) {
653657 hlist_for_each_entry (forw_packet_pos ,
654658 & bat_priv -> forw_bat_list , list ) {
655659 if (batadv_iv_ogm_can_aggregate (batadv_ogm_packet ,
@@ -675,7 +679,7 @@ static bool batadv_iv_ogm_queue_add(struct batadv_priv *bat_priv,
675679 * we hold it back for a while, so that it might be aggregated
676680 * later on
677681 */
678- if (!own_packet && atomic_read ( & bat_priv -> aggregated_ogms ) )
682+ if (!own_packet && aggregated_ogms )
679683 send_time += max_aggregation_jiffies ;
680684
681685 return batadv_iv_ogm_aggregate_new (packet_buff , packet_len ,
@@ -888,7 +892,7 @@ static void batadv_iv_ogm_schedule_buff(struct batadv_hard_iface *hard_iface)
888892 */
889893 queue_delayed_work (batadv_event_workqueue ,
890894 & hard_iface -> bat_iv .reschedule_work ,
891- msecs_to_jiffies (atomic_read ( & bat_priv -> orig_interval )));
895+ msecs_to_jiffies (READ_ONCE ( bat_priv -> orig_interval )));
892896 }
893897
894898 batadv_hardif_put (primary_if );
@@ -2321,7 +2325,7 @@ static void batadv_iv_iface_enabled(struct batadv_hard_iface *hard_iface)
23212325static void batadv_iv_init_sel_class (struct batadv_priv * bat_priv )
23222326{
23232327 /* set default TQ difference threshold to 20 */
2324- atomic_set ( & bat_priv -> gw .sel_class , 20 );
2328+ WRITE_ONCE ( bat_priv -> gw .sel_class , 20 );
23252329}
23262330
23272331static struct batadv_gw_node *
@@ -2353,7 +2357,7 @@ batadv_iv_gw_get_best_gw_node(struct batadv_priv *bat_priv)
23532357
23542358 tq_avg = router_ifinfo -> bat_iv .tq_avg ;
23552359
2356- switch (atomic_read ( & bat_priv -> gw .sel_class )) {
2360+ switch (READ_ONCE ( bat_priv -> gw .sel_class )) {
23572361 case 1 : /* fast connection */
23582362 tmp_gw_factor = tq_avg * tq_avg ;
23592363 tmp_gw_factor *= gw_node -> bandwidth_down ;
@@ -2407,13 +2411,14 @@ static bool batadv_iv_gw_is_eligible(struct batadv_priv *bat_priv,
24072411{
24082412 struct batadv_neigh_ifinfo * router_orig_ifinfo = NULL ;
24092413 struct batadv_neigh_ifinfo * router_gw_ifinfo = NULL ;
2414+ u32 sel_class = READ_ONCE (bat_priv -> gw .sel_class );
24102415 struct batadv_neigh_node * router_gw = NULL ;
24112416 struct batadv_neigh_node * router_orig = NULL ;
24122417 u8 gw_tq_avg , orig_tq_avg ;
24132418 bool ret = false;
24142419
24152420 /* dynamic re-election is performed only on fast or late switch */
2416- if (atomic_read ( & bat_priv -> gw . sel_class ) <= 2 )
2421+ if (sel_class <= 2 )
24172422 return false;
24182423
24192424 router_gw = batadv_orig_router_get (curr_gw_orig , BATADV_IF_DEFAULT );
@@ -2448,8 +2453,7 @@ static bool batadv_iv_gw_is_eligible(struct batadv_priv *bat_priv,
24482453 /* if the routing class is greater than 3 the value tells us how much
24492454 * greater the TQ value of the new gateway must be
24502455 */
2451- if ((atomic_read (& bat_priv -> gw .sel_class ) > 3 ) &&
2452- (orig_tq_avg - gw_tq_avg < atomic_read (& bat_priv -> gw .sel_class )))
2456+ if (sel_class > 3 && orig_tq_avg - gw_tq_avg < sel_class )
24532457 goto out ;
24542458
24552459 batadv_dbg (BATADV_DBG_BATMAN , bat_priv ,
0 commit comments