diff mbox

[RFC] Btrfs-progs: Fix compiler warnings on PPC64.

Message ID 1347492116-16317-1-git-send-email-clinew@linux.vnet.ibm.com (mailing list archive)
State Accepted, archived
Headers show

Commit Message

clinew@linux.vnet.ibm.com Sept. 12, 2012, 11:21 p.m. UTC
From: Wade Cline <clinew@linux.vnet.ibm.com>

The kernel uses unsigned long long for u64, but PPC64 uses unsigned
long by default. This results in print warnings such as:

print-tree.c:333: warning: format ‘%llu’ expects type ‘long long
unsigned int’, but argument 4 has type ‘u64’

Defining __KERNEL__ before the file <asm/types.h>, or any file that
includes this file, will let PPC64 know to use unsigned long long
for u64 instead. This patch adds the defines and fixes the print
warnings on PPC64.

Signed-off-by: Wade Cline <clinew@linux.vnet.ibm.com>
---
 cmds-receive.c |    1 +
 cmds-scrub.c   |    2 ++
 convert.c      |    1 +
 kerncompat.h   |    6 ++++++
 mkfs.c         |    1 +
 5 files changed, 11 insertions(+), 0 deletions(-)

Comments

David Sterba Sept. 14, 2012, 1:59 p.m. UTC | #1
On Wed, Sep 12, 2012 at 04:21:56PM -0700, clinew@linux.vnet.ibm.com wrote:
> Defining __KERNEL__ before the file <asm/types.h>, or any file that
> includes this file, will let PPC64 know to use unsigned long long
> for u64 instead. This patch adds the defines and fixes the print
> warnings on PPC64.

Defining __KERNEL__ in random places does not seem clean, I understand
it in kerncompat.h which should transparently fix any compatibility
issues, and the files like cmd-receive.c should include this instead of
the explicit defines.


david
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
clinew@linux.vnet.ibm.com Sept. 14, 2012, 5:13 p.m. UTC | #2
On 09/14/2012 06:59 AM, David Sterba wrote:
> On Wed, Sep 12, 2012 at 04:21:56PM -0700, clinew@linux.vnet.ibm.com wrote:
>> Defining __KERNEL__ before the file<asm/types.h>, or any file that
>> includes this file, will let PPC64 know to use unsigned long long
>> for u64 instead. This patch adds the defines and fixes the print
>> warnings on PPC64.
> Defining __KERNEL__ in random places does not seem clean, I understand
> it in kerncompat.h which should transparently fix any compatibility
> issues, and the files like cmd-receive.c should include this instead of
> the explicit defines.
>
>
> david
>

I agree that defining __KERNEL__ does not seem clean, but the problem is 
that
the various include files sort of "race" to include the type definition. 
For example,
in cmds-scrub.c:

#include <sys/ioctl.h>
#include <sys/wait.h>
#define __KERNEL__
#include <sys/stat.h>

will generate compiler warnings while:

#include <sys/ioctl.h>
#define __KERNEL__
#include <sys/wait.h>
#include <sys/stat.h>

will not. By the time kerncompat.h is included, u64 is almost always 
defined to
the non-compatible value. So either kerncompat.h needs to be defined as 
the -first-
included header file, or __KERNEL__ needs to be defined.

...it would also be possible to do something like:

#define __KERNEL__
#include <sys/wait.h>
#undef __KERNEL__

but that seems a bit too hacky.

I'm open to any other ideas, though.

Thank you,
Wade

--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
David Sterba Sept. 20, 2012, 2:15 p.m. UTC | #3
On Fri, Sep 14, 2012 at 10:13:13AM -0700, Wade Cline wrote:
> By the time kerncompat.h is included, u64 is almost always defined to
> the non-compatible value. So either kerncompat.h needs to be defined as the
> -first-

This makes most sense to me.

Although the include files should go in the order 1. system 2. local,
and kernecompat.h is local, it's special in it's own way and i don't see
any problem with that.

david
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/cmds-receive.c b/cmds-receive.c
index a8be6fa..6cb51fe 100644
--- a/cmds-receive.c
+++ b/cmds-receive.c
@@ -20,6 +20,7 @@ 
 #define _POSIX_C_SOURCE 200809
 #define _XOPEN_SOURCE 700
 #define _BSD_SOURCE
+#define __KERNEL__
 
 #include <unistd.h>
 #include <stdint.h>
diff --git a/cmds-scrub.c b/cmds-scrub.c
index 24be20f..7f6aa68 100644
--- a/cmds-scrub.c
+++ b/cmds-scrub.c
@@ -16,6 +16,8 @@ 
  * Boston, MA 021110-1307, USA.
  */
 
+#define __KERNEL__
+
 #include <sys/ioctl.h>
 #include <sys/wait.h>
 #include <sys/stat.h>
diff --git a/convert.c b/convert.c
index fa7bf8c..74ffceb 100644
--- a/convert.c
+++ b/convert.c
@@ -18,6 +18,7 @@ 
 
 #define _XOPEN_SOURCE 600
 #define _GNU_SOURCE 1
+#define __KERNEL__
 #ifndef __CHECKER__
 #include <sys/ioctl.h>
 #include <sys/mount.h>
diff --git a/kerncompat.h b/kerncompat.h
index 46236cd..2e571b8 100644
--- a/kerncompat.h
+++ b/kerncompat.h
@@ -57,11 +57,17 @@ 
 #endif
 
 #ifndef __CHECKER__
+/*
+ * PPC64 uses unsigned long for u64 while the kernel uses unsigned long long;
+ * Specifying this will let PPC64 know to use unsigned long long instead.
+ */
+#define __KERNEL__
 #include <asm/types.h>
 typedef __u32 u32;
 typedef __u64 u64;
 typedef __u16 u16;
 typedef __u8 u8;
+#undef __KERNEL__
 #else
 typedef unsigned int u32;
 typedef unsigned int __u32;
diff --git a/mkfs.c b/mkfs.c
index dff5eb8..1c88804 100644
--- a/mkfs.c
+++ b/mkfs.c
@@ -18,6 +18,7 @@ 
 
 #define _XOPEN_SOURCE 500
 #define _GNU_SOURCE
+#define __KERNEL__
 
 #ifndef __CHECKER__
 #include <sys/ioctl.h>