public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Al Viro <viro@ftp.linux.org.uk>
To: Linus Torvalds <torvalds@linux-foundation.org>
Cc: rmk@arm.linux.org.uk, linux-kernel@vger.kernel.org
Subject: [PATCH] arm unaligned.h annotations
Date: Thu, 26 Jul 2007 17:46:19 +0100	[thread overview]
Message-ID: <20070726164619.GO27237@ftp.linux.org.uk> (raw)

	Have put_unaligned() warn if types would be wrong
for assignment, slap force-casts where needed.  Cast the
result of get_unaligned to typeof(*ptr).  With that in
place we get proper typechecking, both from gcc and from sparse,
including that for bitwise types.

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
---
diff --git a/include/asm-arm/unaligned.h b/include/asm-arm/unaligned.h
index 795b9e5..8431f6e 100644
--- a/include/asm-arm/unaligned.h
+++ b/include/asm-arm/unaligned.h
@@ -60,24 +60,24 @@ extern int __bug_unaligned_x(const void *ptr);
 		__get_unaligned_4_be((__p+4)))
 
 #define __get_unaligned_le(ptr)						\
-	({								\
+	((__force typeof(*(ptr)))({					\
 		const __u8 *__p = (const __u8 *)(ptr);			\
 		__builtin_choose_expr(sizeof(*(ptr)) == 1, *__p,	\
 		  __builtin_choose_expr(sizeof(*(ptr)) == 2, __get_unaligned_2_le(__p),	\
 		  __builtin_choose_expr(sizeof(*(ptr)) == 4, __get_unaligned_4_le(__p),	\
 		  __builtin_choose_expr(sizeof(*(ptr)) == 8, __get_unaligned_8_le(__p),	\
 		    (void)__bug_unaligned_x(__p)))));			\
-	})
+	}))
 
 #define __get_unaligned_be(ptr)						\
-	({								\
+	((__force typeof(*(ptr)))({					\
 		const __u8 *__p = (const __u8 *)(ptr);			\
 		__builtin_choose_expr(sizeof(*(ptr)) == 1, *__p,	\
 		  __builtin_choose_expr(sizeof(*(ptr)) == 2, __get_unaligned_2_be(__p),	\
 		  __builtin_choose_expr(sizeof(*(ptr)) == 4, __get_unaligned_4_be(__p),	\
 		  __builtin_choose_expr(sizeof(*(ptr)) == 8, __get_unaligned_8_be(__p),	\
 		    (void)__bug_unaligned_x(__p)))));			\
-	})
+	}))
 
 
 static inline void __put_unaligned_2_le(__u32 __v, register __u8 *__p)
@@ -131,15 +131,16 @@ static inline void __put_unaligned_8_be(const unsigned long long __v, register _
  */
 #define __put_unaligned_le(val,ptr)					\
 	({							\
+		(void)sizeof(*(ptr) = (val));			\
 		switch (sizeof(*(ptr))) {			\
 		case 1:						\
 			*(ptr) = (val);				\
 			break;					\
-		case 2: __put_unaligned_2_le((val),(__u8 *)(ptr));	\
+		case 2: __put_unaligned_2_le((__force u16)(val),(__u8 *)(ptr));	\
 			break;					\
-		case 4:	__put_unaligned_4_le((val),(__u8 *)(ptr));	\
+		case 4:	__put_unaligned_4_le((__force u32)(val),(__u8 *)(ptr));	\
 			break;					\
-		case 8:	__put_unaligned_8_le((val),(__u8 *)(ptr)); \
+		case 8:	__put_unaligned_8_le((__force u64)(val),(__u8 *)(ptr)); \
 			break;					\
 		default: __bug_unaligned_x(ptr);		\
 			break;					\
@@ -149,15 +150,16 @@ static inline void __put_unaligned_8_be(const unsigned long long __v, register _
 
 #define __put_unaligned_be(val,ptr)					\
 	({							\
+		(void)sizeof(*(ptr) = (val));			\
 		switch (sizeof(*(ptr))) {			\
 		case 1:						\
 			*(ptr) = (val);				\
 			break;					\
-		case 2: __put_unaligned_2_be((val),(__u8 *)(ptr));	\
+		case 2: __put_unaligned_2_be((__force u16)(val),(__u8 *)(ptr));	\
 			break;					\
-		case 4:	__put_unaligned_4_be((val),(__u8 *)(ptr));	\
+		case 4:	__put_unaligned_4_be((__force u32)(val),(__u8 *)(ptr));	\
 			break;					\
-		case 8:	__put_unaligned_8_be((val),(__u8 *)(ptr)); \
+		case 8:	__put_unaligned_8_be((__force u64)(val),(__u8 *)(ptr)); \
 			break;					\
 		default: __bug_unaligned_x(ptr);		\
 			break;					\

                 reply	other threads:[~2007-07-26 16:46 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20070726164619.GO27237@ftp.linux.org.uk \
    --to=viro@ftp.linux.org.uk \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rmk@arm.linux.org.uk \
    --cc=torvalds@linux-foundation.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox