]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
batman-adv: replace non-atomic packet_size_max with (READ|WRITE)_ONCE
authorSven Eckelmann <sven@narfation.org>
Tue, 12 May 2026 17:37:05 +0000 (19:37 +0200)
committerSven Eckelmann <sven@narfation.org>
Mon, 1 Jun 2026 12:22:02 +0000 (14:22 +0200)
The maximum packet size of an meshif is only accessed as plain loads/stores
and does not require full atomic_t semantics. Convert to a native integer
and replace its users with READ_ONCE()/WRITE_ONCE() to avoid load/store
tearing.

Signed-off-by: Sven Eckelmann <sven@narfation.org>
net/batman-adv/hard-interface.c
net/batman-adv/mesh-interface.c
net/batman-adv/translation-table.c
net/batman-adv/types.h

index 86e7d10864e2f96cb77cc2be006d296fb9072d67..bb3c31b5f259d620c7175800863367a7bc4cf25a 100644 (file)
@@ -7,7 +7,6 @@
 #include "hard-interface.h"
 #include "main.h"
 
-#include <linux/atomic.h>
 #include <linux/bug.h>
 #include <linux/byteorder/generic.h>
 #include <linux/compiler.h>
@@ -629,7 +628,7 @@ out:
         * overhead). For example, this value is used by TT to compute the
         * maximum local table size
         */
-       atomic_set(&bat_priv->packet_size_max, min_mtu);
+       WRITE_ONCE(bat_priv->packet_size_max, min_mtu);
 
        /* the real mesh-interface MTU is computed by removing the payload
         * overhead from the maximum amount of bytes that was just computed.
index 7497f307c10db807753381f40a8d0f366df22d22..b6797654b18ab64ce59bc53e22768ed4d55fe496 100644 (file)
@@ -779,7 +779,7 @@ static int batadv_meshif_init_late(struct net_device *dev)
        WRITE_ONCE(bat_priv->log_level, 0);
 #endif
        WRITE_ONCE(bat_priv->fragmentation, 1);
-       atomic_set(&bat_priv->packet_size_max, BATADV_MAX_MTU);
+       WRITE_ONCE(bat_priv->packet_size_max, BATADV_MAX_MTU);
        atomic_set(&bat_priv->bcast_queue_left, BATADV_BCAST_QUEUE_LEN);
        atomic_set(&bat_priv->batman_queue_left, BATADV_BATMAN_QUEUE_LEN);
 
index 515f26ff8c269a7019e9f506f4d2e502c597a7df..e319b0796f7c89ba33afa09f6cdf0399e3e9c0bc 100644 (file)
@@ -649,7 +649,7 @@ bool batadv_tt_local_add(struct net_device *mesh_iface, const u8 *addr,
        /* Ignore the client if we cannot send it in a full table response. */
        table_size = batadv_tt_local_table_transmit_size(bat_priv);
        table_size += batadv_tt_len(1);
-       packet_size_max = atomic_read(&bat_priv->packet_size_max);
+       packet_size_max = READ_ONCE(bat_priv->packet_size_max);
        if (table_size > packet_size_max) {
                net_ratelimited_function(batadv_info, mesh_iface,
                                         "Local translation table size (%i) exceeds maximum packet size (%i); Ignoring new local tt entry: %pM\n",
@@ -3069,7 +3069,7 @@ static bool batadv_send_other_tt_response(struct batadv_priv *bat_priv,
 
        /* Don't send the response, if larger than fragmented packet. */
        tt_len = sizeof(struct batadv_unicast_tvlv_packet) + tvlv_len;
-       if (tt_len > atomic_read(&bat_priv->packet_size_max)) {
+       if (tt_len > READ_ONCE(bat_priv->packet_size_max)) {
                net_ratelimited_function(batadv_info, bat_priv->mesh_iface,
                                         "Ignoring TT_REQUEST from %pM; Response size exceeds max packet size.\n",
                                         res_dst_orig_node->orig);
@@ -3932,7 +3932,7 @@ bool batadv_tt_add_temporary_global_entry(struct batadv_priv *bat_priv,
 void batadv_tt_local_resize_to_mtu(struct net_device *mesh_iface)
 {
        struct batadv_priv *bat_priv = netdev_priv(mesh_iface);
-       int packet_size_max = atomic_read(&bat_priv->packet_size_max);
+       int packet_size_max = READ_ONCE(bat_priv->packet_size_max);
        int table_size, timeout = BATADV_TT_LOCAL_TIMEOUT / 2;
        bool reduced = false;
 
index 58375c0a643b86534f0bcec4d2dbb1bad93dc22c..7533d71b737257c1df81f46234a7feeacce79d01 100644 (file)
@@ -1570,7 +1570,7 @@ struct batadv_priv {
         *  multiple fragmented skbs or a single frame if fragmentation is
         *  disabled
         */
-       atomic_t packet_size_max;
+       int packet_size_max;
 
        /**
         * @frag_seqno: incremental counter to identify chains of egress