All of lore.kernel.org
 help / color / mirror / Atom feed
* New bcache compiler warning (was: Re: bcache: Minor fixes from kbuild robot)
@ 2014-02-17 21:00 Geert Uytterhoeven
  2014-02-17 21:06 ` Randy Dunlap
  0 siblings, 1 reply; 7+ messages in thread
From: Geert Uytterhoeven @ 2014-02-17 21:00 UTC (permalink / raw)
  To: Kent Overstreet; +Cc: Linux Kernel Mailing List, linux-bcache

On Fri, Feb 14, 2014 at 8:04 PM, Linux Kernel Mailing List
<linux-kernel@vger.kernel.org> wrote:
>    bcache: Minor fixes from kbuild robot

> diff --git a/drivers/md/bcache/bset.c b/drivers/md/bcache/bset.c
> index 4f6b594..3f74b4b 100644
> --- a/drivers/md/bcache/bset.c
> +++ b/drivers/md/bcache/bset.c
> @@ -23,7 +23,7 @@ void bch_dump_bset(struct btree_keys *b, struct bset *i, unsigned set)
>         for (k = i->start; k < bset_bkey_last(i); k = next) {
>                 next = bkey_next(k);
>
> -               printk(KERN_ERR "block %u key %zi/%u: ", set,
> +               printk(KERN_ERR "block %u key %li/%u: ", set,
>                        (uint64_t *) k - i->d, i->keys);
>
>                 if (b->ops->key_dump)

On 32-bit (m68k):
drivers/md/bcache/bset.c: In function ‘bch_dump_bset’:
drivers/md/bcache/bset.c:27: warning: format ‘%li’ expects type ‘long
int’, but argument 3 has type ‘int’

What are you trying to print here? It looks a bit strange to me.
Technically, the difference between two pointers is of type ptrdiff_.
The kernel had

typedef __kernel_ptrdiff_t      ptrdiff_t;

and

#if __BITS_PER_LONG != 64
typedef unsigned int    __kernel_size_t;
typedef int             __kernel_ssize_t;
typedef int             __kernel_ptrdiff_t;
#else
typedef __kernel_ulong_t __kernel_size_t;
typedef __kernel_long_t __kernel_ssize_t;
typedef __kernel_long_t __kernel_ptrdiff_t;
#endif

So I'd expect "%zi" to be the right way, and a quick test compile on
32-bit (m68k)
and 64-bit (amd64) comfirms that. What was wrong with it?

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

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: New bcache compiler warning (was: Re: bcache: Minor fixes from kbuild robot)
  2014-02-17 21:00 New bcache compiler warning (was: Re: bcache: Minor fixes from kbuild robot) Geert Uytterhoeven
@ 2014-02-17 21:06 ` Randy Dunlap
  2014-02-17 21:11   ` Geert Uytterhoeven
  0 siblings, 1 reply; 7+ messages in thread
From: Randy Dunlap @ 2014-02-17 21:06 UTC (permalink / raw)
  To: Geert Uytterhoeven, Kent Overstreet
  Cc: Linux Kernel Mailing List, linux-bcache

On 02/17/2014 01:00 PM, Geert Uytterhoeven wrote:
> On Fri, Feb 14, 2014 at 8:04 PM, Linux Kernel Mailing List
> <linux-kernel@vger.kernel.org> wrote:
>>    bcache: Minor fixes from kbuild robot
> 
>> diff --git a/drivers/md/bcache/bset.c b/drivers/md/bcache/bset.c
>> index 4f6b594..3f74b4b 100644
>> --- a/drivers/md/bcache/bset.c
>> +++ b/drivers/md/bcache/bset.c
>> @@ -23,7 +23,7 @@ void bch_dump_bset(struct btree_keys *b, struct bset *i, unsigned set)
>>         for (k = i->start; k < bset_bkey_last(i); k = next) {
>>                 next = bkey_next(k);
>>
>> -               printk(KERN_ERR "block %u key %zi/%u: ", set,
>> +               printk(KERN_ERR "block %u key %li/%u: ", set,
>>                        (uint64_t *) k - i->d, i->keys);
>>
>>                 if (b->ops->key_dump)
> 
> On 32-bit (m68k):
> drivers/md/bcache/bset.c: In function ‘bch_dump_bset’:
> drivers/md/bcache/bset.c:27: warning: format ‘%li’ expects type ‘long
> int’, but argument 3 has type ‘int’
> 
> What are you trying to print here? It looks a bit strange to me.
> Technically, the difference between two pointers is of type ptrdiff_.
> The kernel had
> 
> typedef __kernel_ptrdiff_t      ptrdiff_t;
> 
> and
> 
> #if __BITS_PER_LONG != 64
> typedef unsigned int    __kernel_size_t;
> typedef int             __kernel_ssize_t;
> typedef int             __kernel_ptrdiff_t;
> #else
> typedef __kernel_ulong_t __kernel_size_t;
> typedef __kernel_long_t __kernel_ssize_t;
> typedef __kernel_long_t __kernel_ptrdiff_t;
> #endif
> 
> So I'd expect "%zi" to be the right way, and a quick test compile on
> 32-bit (m68k)
> and 64-bit (amd64) comfirms that. What was wrong with it?

The kernel supports 't' (%t) for ptrdiff_t (same as glibc),
so %ti should work (or %tu).

-- 
~Randy

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: New bcache compiler warning (was: Re: bcache: Minor fixes from kbuild robot)
  2014-02-17 21:06 ` Randy Dunlap
@ 2014-02-17 21:11   ` Geert Uytterhoeven
  2014-02-17 21:45     ` Kent Overstreet
  0 siblings, 1 reply; 7+ messages in thread
From: Geert Uytterhoeven @ 2014-02-17 21:11 UTC (permalink / raw)
  To: Randy Dunlap; +Cc: Kent Overstreet, Linux Kernel Mailing List, linux-bcache

On Mon, Feb 17, 2014 at 10:06 PM, Randy Dunlap <rdunlap@infradead.org> wrote:
> On 02/17/2014 01:00 PM, Geert Uytterhoeven wrote:
>> On Fri, Feb 14, 2014 at 8:04 PM, Linux Kernel Mailing List
>> <linux-kernel@vger.kernel.org> wrote:
>>>    bcache: Minor fixes from kbuild robot
>>
>>> diff --git a/drivers/md/bcache/bset.c b/drivers/md/bcache/bset.c
>>> index 4f6b594..3f74b4b 100644
>>> --- a/drivers/md/bcache/bset.c
>>> +++ b/drivers/md/bcache/bset.c
>>> @@ -23,7 +23,7 @@ void bch_dump_bset(struct btree_keys *b, struct bset *i, unsigned set)
>>>         for (k = i->start; k < bset_bkey_last(i); k = next) {
>>>                 next = bkey_next(k);
>>>
>>> -               printk(KERN_ERR "block %u key %zi/%u: ", set,
>>> +               printk(KERN_ERR "block %u key %li/%u: ", set,
>>>                        (uint64_t *) k - i->d, i->keys);
>>>
>>>                 if (b->ops->key_dump)
>>
>> On 32-bit (m68k):
>> drivers/md/bcache/bset.c: In function ‘bch_dump_bset’:
>> drivers/md/bcache/bset.c:27: warning: format ‘%li’ expects type ‘long
>> int’, but argument 3 has type ‘int’
>>
>> What are you trying to print here? It looks a bit strange to me.
>> Technically, the difference between two pointers is of type ptrdiff_.
>> The kernel had
>>
>> typedef __kernel_ptrdiff_t      ptrdiff_t;
>>
>> and
>>
>> #if __BITS_PER_LONG != 64
>> typedef unsigned int    __kernel_size_t;
>> typedef int             __kernel_ssize_t;
>> typedef int             __kernel_ptrdiff_t;
>> #else
>> typedef __kernel_ulong_t __kernel_size_t;
>> typedef __kernel_long_t __kernel_ssize_t;
>> typedef __kernel_long_t __kernel_ptrdiff_t;
>> #endif
>>
>> So I'd expect "%zi" to be the right way, and a quick test compile on
>> 32-bit (m68k)
>> and 64-bit (amd64) comfirms that. What was wrong with it?
>
> The kernel supports 't' (%t) for ptrdiff_t (same as glibc),
> so %ti should work (or %tu).

Yes, that compiles without warnings, too.

And after more decyphering, "(uint64_t *) k - i->d" seems to be positive,
so "%tu" should be OK.

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

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: New bcache compiler warning (was: Re: bcache: Minor fixes from kbuild robot)
  2014-02-17 21:11   ` Geert Uytterhoeven
@ 2014-02-17 21:45     ` Kent Overstreet
  2014-02-17 22:44       ` Randy Dunlap
  2014-02-18  9:01       ` Geert Uytterhoeven
  0 siblings, 2 replies; 7+ messages in thread
From: Kent Overstreet @ 2014-02-17 21:45 UTC (permalink / raw)
  To: Geert Uytterhoeven; +Cc: Randy Dunlap, Linux Kernel Mailing List, linux-bcache

On Mon, Feb 17, 2014 at 10:11:51PM +0100, Geert Uytterhoeven wrote:
> On Mon, Feb 17, 2014 at 10:06 PM, Randy Dunlap <rdunlap@infradead.org> wrote:
> > On 02/17/2014 01:00 PM, Geert Uytterhoeven wrote:
> >> On Fri, Feb 14, 2014 at 8:04 PM, Linux Kernel Mailing List
> >> <linux-kernel@vger.kernel.org> wrote:
> >>>    bcache: Minor fixes from kbuild robot
> >>
> >>> diff --git a/drivers/md/bcache/bset.c b/drivers/md/bcache/bset.c
> >>> index 4f6b594..3f74b4b 100644
> >>> --- a/drivers/md/bcache/bset.c
> >>> +++ b/drivers/md/bcache/bset.c
> >>> @@ -23,7 +23,7 @@ void bch_dump_bset(struct btree_keys *b, struct bset *i, unsigned set)
> >>>         for (k = i->start; k < bset_bkey_last(i); k = next) {
> >>>                 next = bkey_next(k);
> >>>
> >>> -               printk(KERN_ERR "block %u key %zi/%u: ", set,
> >>> +               printk(KERN_ERR "block %u key %li/%u: ", set,
> >>>                        (uint64_t *) k - i->d, i->keys);
> >>>
> >>>                 if (b->ops->key_dump)
> >>
> >> On 32-bit (m68k):
> >> drivers/md/bcache/bset.c: In function ‘bch_dump_bset’:
> >> drivers/md/bcache/bset.c:27: warning: format ‘%li’ expects type ‘long
> >> int’, but argument 3 has type ‘int’
> >>
> >> What are you trying to print here? It looks a bit strange to me.
> >> Technically, the difference between two pointers is of type ptrdiff_.
> >> The kernel had
> >>
> >> typedef __kernel_ptrdiff_t      ptrdiff_t;
> >>
> >> and
> >>
> >> #if __BITS_PER_LONG != 64
> >> typedef unsigned int    __kernel_size_t;
> >> typedef int             __kernel_ssize_t;
> >> typedef int             __kernel_ptrdiff_t;
> >> #else
> >> typedef __kernel_ulong_t __kernel_size_t;
> >> typedef __kernel_long_t __kernel_ssize_t;
> >> typedef __kernel_long_t __kernel_ptrdiff_t;
> >> #endif
> >>
> >> So I'd expect "%zi" to be the right way, and a quick test compile on
> >> 32-bit (m68k)
> >> and 64-bit (amd64) comfirms that. What was wrong with it?
> >
> > The kernel supports 't' (%t) for ptrdiff_t (same as glibc),
> > so %ti should work (or %tu).
> 
> Yes, that compiles without warnings, too.
> 
> And after more decyphering, "(uint64_t *) k - i->d" seems to be positive,
> so "%tu" should be OK.

*swears* Actually, I'm just going to cast this to unsigned (that's definitely
safe here):


commit 70bc49d421c793f73a772ae1f50622a39c6136d9
Author: Kent Overstreet <kmo@daterainc.com>
Date:   Mon Feb 17 13:44:06 2014 -0800

    bcache: Fix another compiler warning on m68k
    
    Use a bigger hammer this time
    
    Signed-off-by: Kent Overstreet <kmo@daterainc.com>

diff --git a/drivers/md/bcache/bset.c b/drivers/md/bcache/bset.c
index 3f74b4b074..5454164153 100644
--- a/drivers/md/bcache/bset.c
+++ b/drivers/md/bcache/bset.c
@@ -23,8 +23,8 @@ void bch_dump_bset(struct btree_keys *b, struct bset *i, unsigned set)
 	for (k = i->start; k < bset_bkey_last(i); k = next) {
 		next = bkey_next(k);
 
-		printk(KERN_ERR "block %u key %li/%u: ", set,
-		       (uint64_t *) k - i->d, i->keys);
+		printk(KERN_ERR "block %u key %u/%u: ", set,
+		       (unsigned) ((u64 *) k - i->d), i->keys);
 
 		if (b->ops->key_dump)
 			b->ops->key_dump(b, k);


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: New bcache compiler warning (was: Re: bcache: Minor fixes from kbuild robot)
  2014-02-17 21:45     ` Kent Overstreet
@ 2014-02-17 22:44       ` Randy Dunlap
  2014-02-17 22:46         ` Kent Overstreet
  2014-02-18  9:01       ` Geert Uytterhoeven
  1 sibling, 1 reply; 7+ messages in thread
From: Randy Dunlap @ 2014-02-17 22:44 UTC (permalink / raw)
  To: Kent Overstreet, Geert Uytterhoeven
  Cc: Linux Kernel Mailing List, linux-bcache

On 02/17/2014 01:45 PM, Kent Overstreet wrote:
> On Mon, Feb 17, 2014 at 10:11:51PM +0100, Geert Uytterhoeven wrote:
>> On Mon, Feb 17, 2014 at 10:06 PM, Randy Dunlap <rdunlap@infradead.org> wrote:
>>> On 02/17/2014 01:00 PM, Geert Uytterhoeven wrote:
>>>> On Fri, Feb 14, 2014 at 8:04 PM, Linux Kernel Mailing List
>>>> <linux-kernel@vger.kernel.org> wrote:
>>>>>    bcache: Minor fixes from kbuild robot
>>>>
>>>>> diff --git a/drivers/md/bcache/bset.c b/drivers/md/bcache/bset.c
>>>>> index 4f6b594..3f74b4b 100644
>>>>> --- a/drivers/md/bcache/bset.c
>>>>> +++ b/drivers/md/bcache/bset.c
>>>>> @@ -23,7 +23,7 @@ void bch_dump_bset(struct btree_keys *b, struct bset *i, unsigned set)
>>>>>         for (k = i->start; k < bset_bkey_last(i); k = next) {
>>>>>                 next = bkey_next(k);
>>>>>
>>>>> -               printk(KERN_ERR "block %u key %zi/%u: ", set,
>>>>> +               printk(KERN_ERR "block %u key %li/%u: ", set,
>>>>>                        (uint64_t *) k - i->d, i->keys);
>>>>>
>>>>>                 if (b->ops->key_dump)
>>>>
>>>> On 32-bit (m68k):
>>>> drivers/md/bcache/bset.c: In function ‘bch_dump_bset’:
>>>> drivers/md/bcache/bset.c:27: warning: format ‘%li’ expects type ‘long
>>>> int’, but argument 3 has type ‘int’
>>>>
>>>> What are you trying to print here? It looks a bit strange to me.
>>>> Technically, the difference between two pointers is of type ptrdiff_.
>>>> The kernel had
>>>>
>>>> typedef __kernel_ptrdiff_t      ptrdiff_t;
>>>>
>>>> and
>>>>
>>>> #if __BITS_PER_LONG != 64
>>>> typedef unsigned int    __kernel_size_t;
>>>> typedef int             __kernel_ssize_t;
>>>> typedef int             __kernel_ptrdiff_t;
>>>> #else
>>>> typedef __kernel_ulong_t __kernel_size_t;
>>>> typedef __kernel_long_t __kernel_ssize_t;
>>>> typedef __kernel_long_t __kernel_ptrdiff_t;
>>>> #endif
>>>>
>>>> So I'd expect "%zi" to be the right way, and a quick test compile on
>>>> 32-bit (m68k)
>>>> and 64-bit (amd64) comfirms that. What was wrong with it?
>>>
>>> The kernel supports 't' (%t) for ptrdiff_t (same as glibc),
>>> so %ti should work (or %tu).
>>
>> Yes, that compiles without warnings, too.
>>
>> And after more decyphering, "(uint64_t *) k - i->d" seems to be positive,
>> so "%tu" should be OK.
> 
> *swears* Actually, I'm just going to cast this to unsigned (that's definitely
> safe here):
> 
> 
> commit 70bc49d421c793f73a772ae1f50622a39c6136d9
> Author: Kent Overstreet <kmo@daterainc.com>
> Date:   Mon Feb 17 13:44:06 2014 -0800
> 
>     bcache: Fix another compiler warning on m68k
>     
>     Use a bigger hammer this time
>     
>     Signed-off-by: Kent Overstreet <kmo@daterainc.com>
> 
> diff --git a/drivers/md/bcache/bset.c b/drivers/md/bcache/bset.c
> index 3f74b4b074..5454164153 100644
> --- a/drivers/md/bcache/bset.c
> +++ b/drivers/md/bcache/bset.c
> @@ -23,8 +23,8 @@ void bch_dump_bset(struct btree_keys *b, struct bset *i, unsigned set)
>  	for (k = i->start; k < bset_bkey_last(i); k = next) {
>  		next = bkey_next(k);
>  
> -		printk(KERN_ERR "block %u key %li/%u: ", set,
> -		       (uint64_t *) k - i->d, i->keys);
> +		printk(KERN_ERR "block %u key %u/%u: ", set,
> +		       (unsigned) ((u64 *) k - i->d), i->keys);
>  
>  		if (b->ops->key_dump)
>  			b->ops->key_dump(b, k);
> 

Could that cause a truncation?  unsigned means unsigned int.
Can unsigned int be smaller (fewer bits) than the k pointer?
If so, is that OK or a problem?

-- 
~Randy

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: New bcache compiler warning (was: Re: bcache: Minor fixes from kbuild robot)
  2014-02-17 22:44       ` Randy Dunlap
@ 2014-02-17 22:46         ` Kent Overstreet
  0 siblings, 0 replies; 7+ messages in thread
From: Kent Overstreet @ 2014-02-17 22:46 UTC (permalink / raw)
  To: Randy Dunlap; +Cc: Geert Uytterhoeven, Linux Kernel Mailing List, linux-bcache

On Mon, Feb 17, 2014 at 02:44:47PM -0800, Randy Dunlap wrote:
> Could that cause a truncation?  unsigned means unsigned int.
> Can unsigned int be smaller (fewer bits) than the k pointer?
> If so, is that OK or a problem?

It's just truncating the offset of the pointer within the struct bset, which is
part of a btree node - the thing that's being cast is restricted to be no bigger
than a btree node, which is at most a few mb.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: New bcache compiler warning (was: Re: bcache: Minor fixes from kbuild robot)
  2014-02-17 21:45     ` Kent Overstreet
  2014-02-17 22:44       ` Randy Dunlap
@ 2014-02-18  9:01       ` Geert Uytterhoeven
  1 sibling, 0 replies; 7+ messages in thread
From: Geert Uytterhoeven @ 2014-02-18  9:01 UTC (permalink / raw)
  To: Kent Overstreet; +Cc: Randy Dunlap, Linux Kernel Mailing List, linux-bcache

On Mon, Feb 17, 2014 at 10:45 PM, Kent Overstreet <kmo@daterainc.com> wrote:
> *swears* Actually, I'm just going to cast this to unsigned (that's definitely
> safe here):
>
>
> commit 70bc49d421c793f73a772ae1f50622a39c6136d9
> Author: Kent Overstreet <kmo@daterainc.com>
> Date:   Mon Feb 17 13:44:06 2014 -0800
>
>     bcache: Fix another compiler warning on m68k

JFYI, you also get this warning on other 32-bit platforms (e.g. ARM).

>     Use a bigger hammer this time

Looks like it's big enough, now ;-)

>     Signed-off-by: Kent Overstreet <kmo@daterainc.com>
>
> diff --git a/drivers/md/bcache/bset.c b/drivers/md/bcache/bset.c
> index 3f74b4b074..5454164153 100644
> --- a/drivers/md/bcache/bset.c
> +++ b/drivers/md/bcache/bset.c
> @@ -23,8 +23,8 @@ void bch_dump_bset(struct btree_keys *b, struct bset *i, unsigned set)
>         for (k = i->start; k < bset_bkey_last(i); k = next) {
>                 next = bkey_next(k);
>
> -               printk(KERN_ERR "block %u key %li/%u: ", set,
> -                      (uint64_t *) k - i->d, i->keys);
> +               printk(KERN_ERR "block %u key %u/%u: ", set,
> +                      (unsigned) ((u64 *) k - i->d), i->keys);
>
>                 if (b->ops->key_dump)
>                         b->ops->key_dump(b, k);

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

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2014-02-18  9:01 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-02-17 21:00 New bcache compiler warning (was: Re: bcache: Minor fixes from kbuild robot) Geert Uytterhoeven
2014-02-17 21:06 ` Randy Dunlap
2014-02-17 21:11   ` Geert Uytterhoeven
2014-02-17 21:45     ` Kent Overstreet
2014-02-17 22:44       ` Randy Dunlap
2014-02-17 22:46         ` Kent Overstreet
2014-02-18  9:01       ` Geert Uytterhoeven

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.