Repository : ssh://git@diktynna/batman-adv On branches: ecsv/pu,main,main
commit ee4dcf70d3612b416f25f4a5034c2f9d83d8c210 Author: Sven Eckelmann sven@narfation.org Date: Sun Oct 6 19:39:31 2024 +0200
batman-adv: Use string choice helper to print booleans
The commit ea4692c75e1c ("lib/string_helpers: Consolidate string helpers implementation") introduced common helpers to print string representations of boolean helpers. These are supposed to be used instead of open coded versions.
Signed-off-by: Sven Eckelmann sven@narfation.org
ee4dcf70d3612b416f25f4a5034c2f9d83d8c210 compat-include/linux/string_choices.h | 32 ++++++++++++++++++++++++++++++++ net/batman-adv/bat_iv_ogm.c | 4 ++-- net/batman-adv/bridge_loop_avoidance.c | 8 ++++---- 3 files changed, 38 insertions(+), 6 deletions(-)
diff --git a/compat-include/linux/string_choices.h b/compat-include/linux/string_choices.h new file mode 100644 index 00000000..9a6aba7f --- /dev/null +++ b/compat-include/linux/string_choices.h @@ -0,0 +1,32 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* Copyright (C) B.A.T.M.A.N. contributors: + * + * Marek Lindner, Simon Wunderlich + * + * This file contains macros for maintaining compatibility with older versions + * of the Linux kernel. + */ + +#ifndef _NET_BATMAN_ADV_COMPAT_LINUX_STRING_CHOICES_H_ +#define _NET_BATMAN_ADV_COMPAT_LINUX_STRING_CHOICES_H_ + +#include <linux/version.h> +#if LINUX_VERSION_IS_GEQ(6, 5, 0) +#include_next <linux/string_choices.h> +#elif LINUX_VERSION_IS_GEQ(5, 18, 0) +#include <linux/string_helpers.h> +#else + +static inline const char *str_yes_no(bool v) +{ + return v ? "yes" : "no"; +} + +static inline const char *str_on_off(bool v) +{ + return v ? "on" : "off"; +} + +#endif + +#endif /* _NET_BATMAN_ADV_COMPAT_LINUX_STRING_CHOICES_H_ */ diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c index 74b49c35..07ae5dd1 100644 --- a/net/batman-adv/bat_iv_ogm.c +++ b/net/batman-adv/bat_iv_ogm.c @@ -36,6 +36,7 @@ #include <linux/spinlock.h> #include <linux/stddef.h> #include <linux/string.h> +#include <linux/string_choices.h> #include <linux/types.h> #include <linux/workqueue.h> #include <net/genetlink.h> @@ -371,8 +372,7 @@ static void batadv_iv_ogm_send_to_if(struct batadv_forw_packet *forw_packet, batadv_ogm_packet->orig, ntohl(batadv_ogm_packet->seqno), batadv_ogm_packet->tq, batadv_ogm_packet->ttl, - ((batadv_ogm_packet->flags & BATADV_DIRECTLINK) ? - "on" : "off"), + str_on_off(batadv_ogm_packet->flags & BATADV_DIRECTLINK), hard_iface->net_dev->name, hard_iface->net_dev->dev_addr);
diff --git a/net/batman-adv/bridge_loop_avoidance.c b/net/batman-adv/bridge_loop_avoidance.c index 5f46ca3d..449faf5a 100644 --- a/net/batman-adv/bridge_loop_avoidance.c +++ b/net/batman-adv/bridge_loop_avoidance.c @@ -33,6 +33,7 @@ #include <linux/sprintf.h> #include <linux/stddef.h> #include <linux/string.h> +#include <linux/string_choices.h> #include <linux/workqueue.h> #include <net/arp.h> #include <net/genetlink.h> @@ -1946,16 +1947,15 @@ bool batadv_bla_rx(struct batadv_priv *bat_priv, struct sk_buff *skb, claim = batadv_claim_hash_find(bat_priv, &search_claim);
if (!claim) { + bool local = batadv_is_my_client(bat_priv, ethhdr->h_source, vid); + /* possible optimization: race for a claim */ /* No claim exists yet, claim it for us! */
batadv_dbg(BATADV_DBG_BLA, bat_priv, "%s(): Unclaimed MAC %pM found. Claim it. Local: %s\n", - __func__, ethhdr->h_source, - batadv_is_my_client(bat_priv, - ethhdr->h_source, vid) ? - "yes" : "no"); + __func__, ethhdr->h_source, str_yes_no(local)); batadv_handle_claim(bat_priv, primary_if, primary_if->net_dev->dev_addr, ethhdr->h_source, vid);