From: Sven Eckelmann batadv_v_neigh_cmp() returns the difference of two u32 throughput values as int. A difference of more than INT_MAX changes the sign of the result: throughput1 = 3000000000, throughput2 = 0 3000000000 - 0 = 3000000000 -> (int)-1294967296 The neighbor with the lower throughput is then seen as the better one by batadv_find_best_neighbor() and batadv_transtable_best_orig(). Compare the two values instead of subtracting them. The callers only check the sign of the result. Fixes: 9786906022eb ("batman-adv: B.A.T.M.A.N. V - implement neighbor comparison API calls") Reported-by: Sashiko Closes: https://sashiko.dev/#/patchset/20260831135117.574836-1-sw%40simonwunderlich.de?part=3 Signed-off-by: Sven Eckelmann Signed-off-by: Simon Wunderlich --- net/batman-adv/bat_v.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/net/batman-adv/bat_v.c b/net/batman-adv/bat_v.c index 8de71a2c220c..c3e4b7468bec 100644 --- a/net/batman-adv/bat_v.c +++ b/net/batman-adv/bat_v.c @@ -499,6 +499,8 @@ static int batadv_v_neigh_cmp(struct batadv_neigh_node *neigh1, { struct batadv_neigh_ifinfo *ifinfo1; struct batadv_neigh_ifinfo *ifinfo2; + u32 throughput1; + u32 throughput2; int ret = 0; ifinfo1 = batadv_neigh_ifinfo_get(neigh1, if_outgoing1); @@ -509,7 +511,13 @@ static int batadv_v_neigh_cmp(struct batadv_neigh_node *neigh1, if (!ifinfo2) goto err_ifinfo2; - ret = ifinfo1->bat_v.throughput - ifinfo2->bat_v.throughput; + throughput1 = ifinfo1->bat_v.throughput; + throughput2 = ifinfo2->bat_v.throughput; + + if (throughput1 > throughput2) + ret = 1; + else if (throughput1 < throughput2) + ret = -1; batadv_neigh_ifinfo_put(ifinfo2); err_ifinfo2: -- 2.47.3