From 63e0f3b39c4c36fa94d5d2ab3942f7984a115bc3 Mon Sep 17 00:00:00 2001 From: David Sterba Date: Mon, 30 May 2022 15:47:06 +0200 Subject: [PATCH] btrfs-progs: kernel-lib: make headers C++ compatible The snapper build fails due to updates to kernel-lib files, the type casts do not work the same way in C++. Simplify READ_ONCE/WRITE_ONCE even more, drop use of 'new' as identifier. Issue: https://github.com/openSUSE/snapper/issues/725 Signed-off-by: David Sterba --- kerncompat.h | 21 +++------------------ kernel-lib/list.h | 24 ++++++++++++++++-------- 2 files changed, 19 insertions(+), 26 deletions(-) diff --git a/kerncompat.h b/kerncompat.h index 64c2c0c3..f6477990 100644 --- a/kerncompat.h +++ b/kerncompat.h @@ -538,29 +538,14 @@ struct __una_u64 { __le64 x; } __attribute__((__packed__)); * Changed: * - __unqual_scalar_typeof: volatile cast to typeof() * - compiletime_assert_rwonce_type: no word size compatibility checks + * - no const volatile cast */ -/* - * Use __READ_ONCE() instead of READ_ONCE() if you do not require any - * atomicity. Note that this may result in tears! - */ -#ifndef __READ_ONCE -#define __READ_ONCE(x) (*(const volatile typeof(x) *)&(x)) -#endif - -#define READ_ONCE(x) \ -({ \ - __READ_ONCE(x); \ -}) - -#define __WRITE_ONCE(x, val) \ -do { \ - *(volatile typeof(x) *)&(x) = (val); \ -} while (0) +#define READ_ONCE(x) (x) #define WRITE_ONCE(x, val) \ do { \ - __WRITE_ONCE(x, val); \ + (x) = (val); \ } while (0) #endif diff --git a/kernel-lib/list.h b/kernel-lib/list.h index 11adb03a..0fe78971 100644 --- a/kernel-lib/list.h +++ b/kernel-lib/list.h @@ -28,6 +28,10 @@ #include #include +#ifdef __cplusplus +extern "C" { +#endif + #define LIST_POISON1 ((void *) 0x00100100) #define LIST_POISON2 ((void *) 0x00200200) @@ -187,8 +191,8 @@ static inline void __list_del_entry(struct list_head *entry) static inline void list_del(struct list_head *entry) { __list_del_entry(entry); - entry->next = LIST_POISON1; - entry->prev = LIST_POISON2; + entry->next = (struct list_head *)LIST_POISON1; + entry->prev = (struct list_head *)LIST_POISON2; } /** @@ -901,8 +905,8 @@ static inline void __hlist_del(struct hlist_node *n) static inline void hlist_del(struct hlist_node *n) { __hlist_del(n); - n->next = LIST_POISON1; - n->pprev = LIST_POISON2; + n->next = (struct hlist_node *)LIST_POISON1; + n->pprev = (struct hlist_node **)LIST_POISON2; } /** @@ -1012,11 +1016,11 @@ hlist_is_singular_node(struct hlist_node *n, struct hlist_head *h) * reference of the first entry if it exists. */ static inline void hlist_move_list(struct hlist_head *old, - struct hlist_head *new) + struct hlist_head *xnew) { - new->first = old->first; - if (new->first) - new->first->pprev = &new->first; + xnew->first = old->first; + if (xnew->first) + xnew->first->pprev = &xnew->first; old->first = NULL; } @@ -1076,4 +1080,8 @@ static inline void hlist_move_list(struct hlist_head *old, pos && ({ n = pos->member.next; 1; }); \ pos = hlist_entry_safe(n, typeof(*pos), member)) +#ifdef __cplusplus +} +#endif + #endif