All of lore.kernel.org
 help / color / mirror / Atom feed
From: Daniel Dressler <danieru.dressler@gmail.com>
To: danieru.dressler@gmail.com
Cc: Chris Mason <clm@fb.com>, Josef Bacik <jbacik@fb.com>,
	linux-btrfs@vger.kernel.org (open list:BTRFS FILE SYSTEM),
	linux-kernel@vger.kernel.org (open list)
Subject: [PATCH v2] Btrfs: qgroup: add BUILD_BUG to report pointer cast breakage
Date: Thu, 13 Nov 2014 00:54:39 +0900	[thread overview]
Message-ID: <1415807679-3824-1-git-send-email-danieru.dressler@gmail.com> (raw)
In-Reply-To: <danieru.dressler@gmail.com>

Our ulist data structure stores at max 64bit
values. qgroup has used this structure to store
pointers. In the future when we upgrade to 128bit
this casting of pointers to uint64_t will break.

This patch adds a BUILD_BUG ensuring that this
code will not be left untouched in the upgrade.

It also marks this issue on the TODO list so it
may be addressed before such an upgrade.

Signed-off-by: Daniel Dressler <danieru.dressler@gmail.com>
---
 fs/btrfs/qgroup.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/fs/btrfs/qgroup.c b/fs/btrfs/qgroup.c
index 48b60db..a9a4cab 100644
--- a/fs/btrfs/qgroup.c
+++ b/fs/btrfs/qgroup.c
@@ -44,6 +44,7 @@
  *  - caches fuer ulists
  *  - performance benchmarks
  *  - check all ioctl parameters
+ *  - do not cast uintptr_t to uint64_t in ulist usage
  */
 
 /*
@@ -99,8 +100,12 @@ struct btrfs_qgroup_list {
 	struct btrfs_qgroup *member;
 };
 
-#define ptr_to_u64(x) ((u64)(uintptr_t)x)
-#define u64_to_ptr(x) ((struct btrfs_qgroup *)(uintptr_t)x)
+#define ptr_to_u64(x) \
+	(BUILD_BUG_ON_ZERO(sizeof(uintptr_t) > sizeof(u64)) + \
+	((u64)(uintptr_t)x))
+#define u64_to_ptr(x) \
+	(BUILD_BUG_ON_ZERO(sizeof(uintptr_t) > sizeof(u64)) + \
+	((struct btrfs_qgroup *)(uintptr_t)x))
 
 static int
 qgroup_rescan_init(struct btrfs_fs_info *fs_info, u64 progress_objectid,
-- 
2.1.0


             reply	other threads:[~2014-11-12 15:54 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-11-12 15:54 Daniel Dressler [this message]
2014-11-21 15:46 ` [PATCH v2] Btrfs: qgroup: add BUILD_BUG to report pointer cast breakage David Sterba

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=1415807679-3824-1-git-send-email-danieru.dressler@gmail.com \
    --to=danieru.dressler@gmail.com \
    --cc=clm@fb.com \
    --cc=jbacik@fb.com \
    --cc=linux-btrfs@vger.kernel.org \
    --cc=linux-kernel@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.