Repository : ssh://git@open-mesh.org/batman-adv
On branch : master
commit 8a54d0aaf9d3c674516eeb03e2768c5cc12c84e1 Author: Pankaj Bharadiya pankaj.laxminarayan.bharadiya@intel.com Date: Tue Sep 24 16:28:36 2019 +0530
batman-adv: Use sizeof_member() macro
Replace all the occurrences of FIELD_SIZEOF() and sizeof_field() with sizeof_member() except at places where these are defined. Later patches will remove the unused definitions.
This patch is generated using following script:
EXCLUDE_FILES="include/linux/stddef.h|include/linux/kernel.h"
git grep -l -e "\bFIELD_SIZEOF\b" -e "\bsizeof_field\b" | while read file; do
if [[ "$file" =~ $EXCLUDE_FILES ]]; then continue fi sed -i -e 's/\bFIELD_SIZEOF\b/sizeof_member/g' \ -e 's/\bsizeof_field\b/sizeof_member/g' \ $file; done
Signed-off-by: Pankaj Bharadiya pankaj.laxminarayan.bharadiya@intel.com Link: https://lore.kernel.org/r/20190924105839.110713-3-pankaj.laxminarayan.bharad... Co-developed-by: Kees Cook keescook@chromium.org Signed-off-by: Kees Cook keescook@chromium.org Acked-by: David Miller davem@davemloft.net # for net/ [sven@narfation.org: add compat code] Signed-off-by: Sven Eckelmann sven@narfation.org
8a54d0aaf9d3c674516eeb03e2768c5cc12c84e1 compat-include/linux/stddef.h | 24 ++++++++++++++++++++++++ net/batman-adv/main.c | 2 +- 2 files changed, 25 insertions(+), 1 deletion(-)
diff --git a/compat-include/linux/stddef.h b/compat-include/linux/stddef.h new file mode 100644 index 00000000..a09b4201 --- /dev/null +++ b/compat-include/linux/stddef.h @@ -0,0 +1,24 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* Copyright (C) 2007-2019 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_STDDEF_H_ +#define _NET_BATMAN_ADV_COMPAT_LINUX_STDDEF_H_ + +#include <linux/version.h> +#include_next <linux/stddef.h> + +#if LINUX_VERSION_CODE < KERNEL_VERSION(5, 5, 0) + +#ifndef sizeof_member +#define sizeof_member(TYPE, MEMBER) (sizeof(((TYPE *)0)->MEMBER)) +#endif + +#endif /* < KERNEL_VERSION(5, 5, 0) */ + +#endif /* _NET_BATMAN_ADV_COMPAT_LINUX_STDDEF_H_ */ diff --git a/net/batman-adv/main.c b/net/batman-adv/main.c index 4a89177d..49cce458 100644 --- a/net/batman-adv/main.c +++ b/net/batman-adv/main.c @@ -548,7 +548,7 @@ static void batadv_recv_handler_init(void) BUILD_BUG_ON(sizeof(struct batadv_tvlv_tt_change) != 12); BUILD_BUG_ON(sizeof(struct batadv_tvlv_roam_adv) != 8);
- i = FIELD_SIZEOF(struct sk_buff, cb); + i = sizeof_member(struct sk_buff, cb); BUILD_BUG_ON(sizeof(struct batadv_skb_cb) > i);
/* broadcast packet */