fs/hfsplus/xattr.c: comparison of distinct pointer types lacks a cast

4 messages, 3 authors, 2014-05-25 · open the first message on its own page

fs/hfsplus/xattr.c: comparison of distinct pointer types lacks a cast

From: Christian Kujau <hidden>
Date: 2014-05-25 01:42:05

Hi,

while compiling 3.15-rc6 for powerpc (gcc-4.8.1 crosscompiling on x86_64), 
this happens:

---------------------------------------------------------------
  CC [M]  fs/hfsplus/xattr_user.o
  CC [M]  fs/hfsplus/xattr_security.o
  CC [M]  fs/hfsplus/xattr.o
  CC [M]  fs/hfsplus/xattr_trusted.o
In file included from 
/usr/local/src/linux-git/arch/powerpc/include/asm/div64.h:1:0,
                 from /usr/local/src/linux-git/include/linux/kernel.h:124,
                 from /usr/local/src/linux-git/include/asm-generic/bug.h:13,
                 from /usr/local/src/linux-git/arch/powerpc/include/asm/bug.h:127,
                 from /usr/local/src/linux-git/include/linux/bug.h:4,
                 from /usr/local/src/linux-git/include/linux/thread_info.h:11,
                 from /usr/local/src/linux-git/include/asm-generic/preempt.h:4,
                 from arch/powerpc/include/generated/asm/preempt.h:1,
                 from /usr/local/src/linux-git/include/linux/preempt.h:18,
                 from /usr/local/src/linux-git/include/linux/spinlock.h:50,
                 from /usr/local/src/linux-git/include/linux/wait.h:8,
                 from /usr/local/src/linux-git/include/linux/fs.h:6,
                 from /usr/local/src/linux-git/fs/hfsplus/hfsplus_fs.h:19,
                 from /usr/local/src/linux-git/fs/hfsplus/xattr.c:9:
/usr/local/src/linux-git/fs/hfsplus/xattr.c: In function 
'hfsplus_init_header_node':
/usr/local/src/linux-git/include/asm-generic/div64.h:43:28: warning: 
comparison of distinct pointer types lacks a cast [enabled by default]
  (void)(((typeof((n)) *)0) == ((uint64_t *)0)); \
                            ^
/usr/local/src/linux-git/fs/hfsplus/xattr.c:86:2: note: in expansion of 
macro 'do_div'
  do_div(tmp, node_size);
  ^
  LD [M]  fs/hfsplus/hfsplus.o
---------------------------------------------------------------

I don't fully understand the issue here, but xattr.c:86 reads:

           do_div(tmp, node_size);

Now, "git log -S do_div --source fs/hfsplus/xattr.c" brought up the 
following commit from Geert, introducing do_div() to xattr.c

  commit a99b7069aab8fc3fb4f26d15795dc280b52e38b1 HEAD
  Author: Geert Uytterhoeven [off-list ref]
  Date:   Thu Nov 14 14:32:18 2013 -0800
  hfsplus: Fix undefined __divdi3 in hfsplus_init_header_node()

Reverting this commit makes the warning above go away, but I doubt this 
would be the correct solution here :-)

Note: the warning has been reported[0] by Geert for v3.13-rc7 back in 
January 2014 already.

Thanks,
Christian.

[0] https://lkml.org/lkml/2014/1/6/107
-- 
BOFH excuse #133:

It's not plugged in.

Re: fs/hfsplus/xattr.c: comparison of distinct pointer types lacks a cast

From: Geert Uytterhoeven <geert@linux-m68k.org>
Date: 2014-05-25 08:48:54

Hi Christian,

On Sun, May 25, 2014 at 3:42 AM, Christian Kujau [off-list ref] wrote:
/usr/local/src/linux-git/include/asm-generic/div64.h:43:28: warning:
comparison of distinct pointer types lacks a cast [enabled by default]
  (void)(((typeof((n)) *)0) == ((uint64_t *)0)); \
                            ^
/usr/local/src/linux-git/fs/hfsplus/xattr.c:86:2: note: in expansion of
macro 'do_div'
  do_div(tmp, node_size);
  ^
  LD [M]  fs/hfsplus/hfsplus.o

---------------------------------------------------------------

I don't fully understand the issue here, but xattr.c:86 reads:

           do_div(tmp, node_size);
"tmp" is "loff_t" which is "__kernel_loff_t", which is "long long", i.e. signed,
while include/asm-generic/div64.h compares its type with "uint64_t".

As inode sizes are positive, it should be safe to change the type of "tmp"
to "u64". Does that make the warning go away?
Now, "git log -S do_div --source fs/hfsplus/xattr.c" brought up the
following commit from Geert, introducing do_div() to xattr.c

  commit a99b7069aab8fc3fb4f26d15795dc280b52e38b1 HEAD
  Author: Geert Uytterhoeven [off-list ref]
  Date:   Thu Nov 14 14:32:18 2013 -0800
  hfsplus: Fix undefined __divdi3 in hfsplus_init_header_node()

Reverting this commit makes the warning above go away, but I doubt this
would be the correct solution here :-)
Indeed ;-)

Gr{oetje,eeting}s,

                        Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds

Re: fs/hfsplus/xattr.c: comparison of distinct pointer types lacks a cast

From: Christian Kujau <hidden>
Date: 2014-05-25 19:07:48

On Sun, 25 May 2014 at 10:48, Geert Uytterhoeven wrote:
"tmp" is "loff_t" which is "__kernel_loff_t", which is "long long", i.e. signed,
while include/asm-generic/div64.h compares its type with "uint64_t".
Thanks for the explanation!
As inode sizes are positive, it should be safe to change the type of "tmp"
to "u64". Does that make the warning go away?
Yes, this helped! Compile-tested only:

 Signed-off-by: Christian Kujau [off-list ref]
      Fixed-by: Geert Uytterhoeven [off-list ref]

Commit a99b7069aab8fc3fb4f26d15795dc280b52e38b1 introduced do_div() to 
xattr.c and the warning below too.

As Geert remarked: "tmp" is "loff_t" which is "__kernel_loff_t", which
is "long long", i.e. signed, while include/asm-generic/div64.h compares
its type with "uint64_t". As inode sizes are positive, it should be safe 
to change the type of "tmp" to "u64". 

==============================
  CC [M]  fs/hfsplus/xattr_user.o
  CC [M]  fs/hfsplus/xattr_security.o
  CC [M]  fs/hfsplus/xattr.o
  CC [M]  fs/hfsplus/xattr_trusted.o
In file included from 
arch/powerpc/include/asm/div64.h:1:0,
                 from include/linux/kernel.h:124,
                 from include/asm-generic/bug.h:13,
                 from arch/powerpc/include/asm/bug.h:127,
                 from include/linux/bug.h:4,
                 from include/linux/thread_info.h:11,
                 from include/asm-generic/preempt.h:4,
                 from arch/powerpc/include/generated/asm/preempt.h:1,
                 from include/linux/preempt.h:18,
                 from include/linux/spinlock.h:50,
                 from include/linux/wait.h:8,
                 from include/linux/fs.h:6,
                 from fs/hfsplus/hfsplus_fs.h:19,
                 from fs/hfsplus/xattr.c:9:
fs/hfsplus/xattr.c: In function 
'hfsplus_init_header_node':
include/asm-generic/div64.h:43:28: warning: 
comparison of distinct pointer types lacks a cast [enabled by default]
  (void)(((typeof((n)) *)0) == ((uint64_t *)0)); \
                            ^
fs/hfsplus/xattr.c:86:2: note: in expansion of 
macro 'do_div'
  do_div(tmp, node_size);
  ^
  LD [M]  fs/hfsplus/hfsplus.o
==============================

diff --git a/fs/hfsplus/xattr.c b/fs/hfsplus/xattr.c
index 4e27edc..cd9ed4c 100644
--- a/fs/hfsplus/xattr.c
+++ b/fs/hfsplus/xattr.c
@@ -66,7 +66,7 @@ static void hfsplus_init_header_node(struct inode *attr_file,
 	char *bmp;
 	u32 used_nodes;
 	u32 used_bmp_bytes;
-	loff_t tmp;
+	u64 tmp;
 
 	hfs_dbg(ATTR_MOD, "init_hdr_attr_file: clump %u, node_size %u\n",
 				clump_size, node_size);


Thanks,
Christian.
-- 
BOFH excuse #388:

Bad user karma.

Re: fs/hfsplus/xattr.c: comparison of distinct pointer types lacks a cast

From: Sergei Antonov <hidden>
Date: 2014-05-25 21:19:43

On 25 May 2014 21:07, Christian Kujau [off-list ref] wrote:
quoted hunk
On Sun, 25 May 2014 at 10:48, Geert Uytterhoeven wrote:
quoted
"tmp" is "loff_t" which is "__kernel_loff_t", which is "long long", i.e. signed,
while include/asm-generic/div64.h compares its type with "uint64_t".
Thanks for the explanation!
quoted
As inode sizes are positive, it should be safe to change the type of "tmp"
to "u64". Does that make the warning go away?
Yes, this helped! Compile-tested only:

 Signed-off-by: Christian Kujau [off-list ref]
      Fixed-by: Geert Uytterhoeven [off-list ref]

Commit a99b7069aab8fc3fb4f26d15795dc280b52e38b1 introduced do_div() to
xattr.c and the warning below too.

As Geert remarked: "tmp" is "loff_t" which is "__kernel_loff_t", which
is "long long", i.e. signed, while include/asm-generic/div64.h compares
its type with "uint64_t". As inode sizes are positive, it should be safe
to change the type of "tmp" to "u64".

==============================
  CC [M]  fs/hfsplus/xattr_user.o
  CC [M]  fs/hfsplus/xattr_security.o
  CC [M]  fs/hfsplus/xattr.o
  CC [M]  fs/hfsplus/xattr_trusted.o
In file included from
arch/powerpc/include/asm/div64.h:1:0,
                 from include/linux/kernel.h:124,
                 from include/asm-generic/bug.h:13,
                 from arch/powerpc/include/asm/bug.h:127,
                 from include/linux/bug.h:4,
                 from include/linux/thread_info.h:11,
                 from include/asm-generic/preempt.h:4,
                 from arch/powerpc/include/generated/asm/preempt.h:1,
                 from include/linux/preempt.h:18,
                 from include/linux/spinlock.h:50,
                 from include/linux/wait.h:8,
                 from include/linux/fs.h:6,
                 from fs/hfsplus/hfsplus_fs.h:19,
                 from fs/hfsplus/xattr.c:9:
fs/hfsplus/xattr.c: In function
'hfsplus_init_header_node':
include/asm-generic/div64.h:43:28: warning:
comparison of distinct pointer types lacks a cast [enabled by default]
  (void)(((typeof((n)) *)0) == ((uint64_t *)0)); \
                            ^
fs/hfsplus/xattr.c:86:2: note: in expansion of
macro 'do_div'
  do_div(tmp, node_size);
  ^
  LD [M]  fs/hfsplus/hfsplus.o
==============================

diff --git a/fs/hfsplus/xattr.c b/fs/hfsplus/xattr.c
index 4e27edc..cd9ed4c 100644
--- a/fs/hfsplus/xattr.c
+++ b/fs/hfsplus/xattr.c
@@ -66,7 +66,7 @@ static void hfsplus_init_header_node(struct inode *attr_file,
        char *bmp;
        u32 used_nodes;
        u32 used_bmp_bytes;
-       loff_t tmp;
+       u64 tmp;

        hfs_dbg(ATTR_MOD, "init_hdr_attr_file: clump %u, node_size %u\n",
                                clump_size, node_size);
Acked-by: Sergei Antonov <redacted>
This patch also needs a name, for example "hfsplus: remove compiler
warning on PowerPC".
You may need to send it to Andrew Morton [off-list ref]
to include in linux-next.
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help