cluster-devel.redhat.com archive mirror
 help / color / mirror / Atom feed
From: Andrew Price <anprice@redhat.com>
To: cluster-devel.redhat.com
Subject: [Cluster-devel] [PATCH] libgfs2: Add __force tags to endianness conversion macros
Date: Fri, 23 Apr 2021 12:33:05 +0100	[thread overview]
Message-ID: <20210423113305.722908-1-anprice@redhat.com> (raw)

The __be* on-disk field types are annotated with __bitwise, which causes
sparse to recognise them as conflicting with non-__bitwise types, but
the endianness conversion macros don't have the required annotations to
tell sparse when to resolve the conflicts instead of flagging a warning.
Add __force annotations to the conversion macros.

This clears up a handful of sparse warnings but the anti-pattern of
storing cpu-endian values in the on-disk structs is still common (see
libgfs2/ondisk.c), so there are still some to be resolved.

Signed-off-by: Andrew Price <anprice@redhat.com>
---
 gfs2/convert/gfs2_convert.c |  2 +-
 gfs2/include/linux/types.h  |  3 +++
 gfs2/libgfs2/libgfs2.h      | 49 ++++++++++++++++++-------------------
 3 files changed, 28 insertions(+), 26 deletions(-)

diff --git a/gfs2/convert/gfs2_convert.c b/gfs2/convert/gfs2_convert.c
index 5656b39d..ded2589e 100644
--- a/gfs2/convert/gfs2_convert.c
+++ b/gfs2/convert/gfs2_convert.c
@@ -1201,7 +1201,7 @@ static int process_dirent_info(struct gfs2_inode *dip, struct gfs2_sbd *sbp,
 		/* Only do this if the dent was a true gfs1 dent, and not a   */
 		/* gfs2 dent converted from a previously aborted run.         */
 		if (dent_was_gfs1) {
-			switch be16_to_cpu(dent->de_type) {
+			switch (be16_to_cpu(dent->de_type)) {
 			case GFS_FILE_NON:
 				dent->de_type = cpu_to_be16(DT_UNKNOWN);
 				break;
diff --git a/gfs2/include/linux/types.h b/gfs2/include/linux/types.h
index 7f4d4b98..a092afc0 100644
--- a/gfs2/include/linux/types.h
+++ b/gfs2/include/linux/types.h
@@ -7,10 +7,13 @@
 
 #ifdef __CHECKER__
 #define __bitwise__ __attribute__((bitwise))
+#define __force__ __attribute__((force))
 #else
 #define __bitwise__
+#define __force__
 #endif
 #define __bitwise __bitwise__
+#define __force __force__
 
 typedef uint8_t __u8;
 typedef uint16_t __u16;
diff --git a/gfs2/libgfs2/libgfs2.h b/gfs2/libgfs2/libgfs2.h
index d8afc100..3f36ffb2 100644
--- a/gfs2/libgfs2/libgfs2.h
+++ b/gfs2/libgfs2/libgfs2.h
@@ -21,42 +21,41 @@ __BEGIN_DECLS
 
 #if __BYTE_ORDER == __BIG_ENDIAN
 
-#define be16_to_cpu(x) (x)
-#define be32_to_cpu(x) (x)
-#define be64_to_cpu(x) (x)
+#define be16_to_cpu(x) ((__force uint16_t)(__be16)(x))
+#define be32_to_cpu(x) ((__force uint32_t)(__be32)(x))
+#define be64_to_cpu(x) ((__force uint64_t)(__be64)(x))
 
-#define cpu_to_be16(x) (x)
-#define cpu_to_be32(x) (x)
-#define cpu_to_be64(x) (x)
+#define cpu_to_be16(x) ((__force __be16)(uint16_t)(x))
+#define cpu_to_be32(x) ((__force __be32)(uint32_t)(x))
+#define cpu_to_be64(x) ((__force __be64)(uint64_t)(x))
 
-#define le16_to_cpu(x) (bswap_16((x)))
-#define le32_to_cpu(x) (bswap_32((x)))
-#define le64_to_cpu(x) (bswap_64((x)))
+#define le16_to_cpu(x) bswap_16((__force uint16_t)(__le16)(x))
+#define le32_to_cpu(x) bswap_32((__force uint32_t)(__le32)(x))
+#define le64_to_cpu(x) bswap_64((__force uint64_t)(__le64)(x))
 
-#define cpu_to_le16(x) (bswap_16((x)))
-#define cpu_to_le32(x) (bswap_32((x)))
-#define cpu_to_le64(x) (bswap_64((x)))
+#define cpu_to_le16(x) ((__force __le16)bswap_16((x)))
+#define cpu_to_le32(x) ((__force __le32)bswap_32((x)))
+#define cpu_to_le64(x) ((__force __le64)bswap_64((x)))
 
 #endif  /*  __BYTE_ORDER == __BIG_ENDIAN  */
 
-
 #if __BYTE_ORDER == __LITTLE_ENDIAN
 
-#define be16_to_cpu(x) (bswap_16((x)))
-#define be32_to_cpu(x) (bswap_32((x)))
-#define be64_to_cpu(x) (bswap_64((x)))
+#define be16_to_cpu(x) bswap_16((__force uint16_t)(__be16)(x))
+#define be32_to_cpu(x) bswap_32((__force uint32_t)(__be32)(x))
+#define be64_to_cpu(x) bswap_64((__force uint64_t)(__be64)(x))
 
-#define cpu_to_be16(x) (bswap_16((x)))
-#define cpu_to_be32(x) (bswap_32((x)))
-#define cpu_to_be64(x) (bswap_64((x))) 
+#define cpu_to_be16(x) ((__force __be16)bswap_16((x)))
+#define cpu_to_be32(x) ((__force __be32)bswap_32((x)))
+#define cpu_to_be64(x) ((__force __be64)bswap_64((x)))
 
-#define le16_to_cpu(x) (x)
-#define le32_to_cpu(x) (x)
-#define le64_to_cpu(x) (x)
+#define le16_to_cpu(x) ((__force uint16_t)(__le16)(x))
+#define le32_to_cpu(x) ((__force uint32_t)(__le32)(x))
+#define le64_to_cpu(x) ((__force uint64_t)(__le64)(x))
 
-#define cpu_to_le16(x) (x)
-#define cpu_to_le32(x) (x)
-#define cpu_to_le64(x) (x)
+#define cpu_to_le16(x) ((__force __le16)(uint16_t)(x))
+#define cpu_to_le32(x) ((__force __le32)(uint32_t)(x))
+#define cpu_to_le64(x) ((__force __le64)(uint64_t)(x))
 
 #endif  /*  __BYTE_ORDER == __LITTLE_ENDIAN  */
 
-- 
2.30.2



                 reply	other threads:[~2021-04-23 11:33 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=20210423113305.722908-1-anprice@redhat.com \
    --to=anprice@redhat.com \
    /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;
as well as URLs for NNTP newsgroup(s).