[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <20210724162429.394792-1-sven@narfation.org>
Date: Sat, 24 Jul 2021 18:24:29 +0200
From: Sven Eckelmann <sven@...fation.org>
To: Arnd Bergmann <arnd@...db.de>
Cc: b.a.t.m.a.n@...ts.open-mesh.org, linux-arch@...r.kernel.org,
linux-kernel@...r.kernel.org, Sven Eckelmann <sven@...fation.org>
Subject: [PATCH] asm-generic: avoid sparse {get,put}_unaligned warning
Sparse will try to check casting of simple integer types which are marked
as __bitwise. This for example "disallows" simple casting of __be{16,32,64}
or __le{16,32,64} to other types. This is also true for pointers to
variables with this type.
But the new generic {get,put}_unaligned is doing that by (reinterpret)
casting the original pointer to a new (anonymous) struct pointer. This will
then create warnings like:
net/batman-adv/distributed-arp-table.c:1461:19: warning: cast from restricted __be32 *
net/batman-adv/distributed-arp-table.c:1510:23: warning: cast from restricted __be32 [usertype] *[assigned] magic
net/batman-adv/distributed-arp-table.c:1588:24: warning: cast from restricted __be32 [usertype] *[assigned] yiaddr
The special attribute force must be used in such statements when the cast
is known to be safe to avoid these warnings.
Fixes: 803f4e1eab7a ("asm-generic: simplify asm/unaligned.h")
Signed-off-by: Sven Eckelmann <sven@...fation.org>
---
include/asm-generic/unaligned.h | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/include/asm-generic/unaligned.h b/include/asm-generic/unaligned.h
index 1c4242416c9f..e2b23e5bf945 100644
--- a/include/asm-generic/unaligned.h
+++ b/include/asm-generic/unaligned.h
@@ -10,12 +10,13 @@
#include <asm/byteorder.h>
#define __get_unaligned_t(type, ptr) ({ \
- const struct { type x; } __packed *__pptr = (typeof(__pptr))(ptr); \
+ const struct { type x; } __packed *__pptr; \
+ __pptr = (__force typeof(__pptr))(ptr); \
__pptr->x; \
})
#define __put_unaligned_t(type, val, ptr) do { \
- struct { type x; } __packed *__pptr = (typeof(__pptr))(ptr); \
+ struct { type x; } __packed *__pptr = (__force typeof(__pptr))(ptr); \
__pptr->x = (val); \
} while (0)
--
2.30.2
Powered by blists - more mailing lists