All of lore.kernel.org
 help / color / mirror / Atom feed
From: Christoph Hellwig <hch@lst.de>
To: "Darrick J. Wong" <djwong@kernel.org>
Cc: Christoph Hellwig <hch@lst.de>, linux-xfs@vger.kernel.org
Subject: Re: [PATCH, RFC] libxfs: check the size of on-disk data structures
Date: Mon, 4 Dec 2023 05:37:18 +0100	[thread overview]
Message-ID: <20231204043718.GA25793@lst.de> (raw)
In-Reply-To: <20231201020658.GU361584@frogsfrogsfrogs>

On Thu, Nov 30, 2023 at 06:06:58PM -0800, Darrick J. Wong wrote:
> I copy-pasta'd the whole mess from compiler_types.h and build_bug.h into
> include/xfs.h.  It works, but it might be kinda egregious though.

Oh.  I actually have a local patch to simply switch to static_assert
as that completly relies on the compiler and gives better output.  I
haven't even written a proper commit log, but this is it:

diff --git a/fs/xfs/xfs_ondisk.h b/fs/xfs/xfs_ondisk.h
index 2f24bd42ac1dd7..3a5581ecb36d4c 100644
--- a/fs/xfs/xfs_ondisk.h
+++ b/fs/xfs/xfs_ondisk.h
@@ -7,16 +7,16 @@
 #define __XFS_ONDISK_H
 
 #define XFS_CHECK_STRUCT_SIZE(structname, size) \
-	BUILD_BUG_ON_MSG(sizeof(structname) != (size), "XFS: sizeof(" \
-		#structname ") is wrong, expected " #size)
+	static_assert(sizeof(structname) == (size), \
+		"XFS: sizeof(" #structname ") is wrong, expected " #size)
 
 #define XFS_CHECK_OFFSET(structname, member, off) \
-	BUILD_BUG_ON_MSG(offsetof(structname, member) != (off), \
+	static_assert(offsetof(structname, member) == (off), \
 		"XFS: offsetof(" #structname ", " #member ") is wrong, " \
 		"expected " #off)
 
 #define XFS_CHECK_VALUE(value, expected) \
-	BUILD_BUG_ON_MSG((value) != (expected), \
+	static_assert((value) == (expected), \
 		"XFS: value of " #value " is wrong, expected " #expected)
 
 static inline void __init

  reply	other threads:[~2023-12-04  4:37 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-08 16:33 [PATCH, RFC] libxfs: check the size of on-disk data structures Christoph Hellwig
2023-11-09 19:52 ` Darrick J. Wong
2023-11-10  5:08   ` Christoph Hellwig
2023-12-01  2:06     ` Darrick J. Wong
2023-12-04  4:37       ` Christoph Hellwig [this message]
2023-12-04 19:53         ` Darrick J. Wong
2023-12-04 20:04           ` Christoph Hellwig

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=20231204043718.GA25793@lst.de \
    --to=hch@lst.de \
    --cc=djwong@kernel.org \
    --cc=linux-xfs@vger.kernel.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.