linux-next.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Geert Uytterhoeven <geert@linux-m68k.org>
To: Joe Perches <joe@perches.com>
Cc: Kent Overstreet <kmo@daterainc.com>, Neil Brown <neilb@suse.de>,
	linux-bcache@vger.kernel.org,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	Linux-Next <linux-next@vger.kernel.org>
Subject: Re: [PATCH -next 2/2] bcache: Use max_t() when comparing different types
Date: Mon, 3 Feb 2014 14:47:20 +0100	[thread overview]
Message-ID: <CAMuHMdUv_xP-1A950i0U=Petaey-_VosSxh5sk44Gqti-ikY6w@mail.gmail.com> (raw)
In-Reply-To: <1389783998.14001.22.camel@joe-AO722>

On Wed, Jan 15, 2014 at 12:06 PM, Joe Perches <joe@perches.com> wrote:
> On Wed, 2014-01-15 at 10:06 +0100, Geert Uytterhoeven wrote:
>> drivers/md/bcache/btree.c: In function ‘insert_u64s_remaining’:
>> drivers/md/bcache/btree.c:1816: warning: comparison of distinct pointer types lacks a cast
> []
>> diff --git a/drivers/md/bcache/btree.c b/drivers/md/bcache/btree.c
> []
>> @@ -1813,7 +1813,7 @@ static size_t insert_u64s_remaining(struct btree *b)
>>       if (b->keys.ops->is_extents)
>>               ret -= KEY_MAX_U64S;
>>
>> -     return max(ret, 0L);
>> +     return max_t(ssize_t, ret, 0L);
>
> why not
>         return max(ret, 0);

Indeed, that also works, on both 32-bit and 64-bit.
Will resend, now all the issues moved from -next to Linus' tree.

> I think it odd that:
>
> drivers/md/bcache/bset.h:static inline size_t bch_btree_keys_u64s_remaining(struct btree_keys *b)
>
> and:
>
> static size_t insert_u64s_remaining(struct btree *b)
> {
>         ssize_t ret = bch_btree_keys_u64s_remaining(&b->keys);
>
>         /*
>          * Might land in the middle of an existing extent and have to split it
>          */
>         if (b->keys.ops->is_extents)
>                 ret -= KEY_MAX_U64S;
>
>         return max(ret, 0L);
> }
>
> so the only use of that size_t inline is cast to ssize_t

If the value returned by bch_btree_keys_u64s_remaining() is smaller
than KEY_MAX_U64S, it must stay negative after the subtraction,
instead of wrapping around to a big positive number. That's why ret is
ssize_t and not size_t.

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

  reply	other threads:[~2014-02-03 13:47 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-01-15  9:06 [PATCH -next 1/2] bcache: Use %zi to format size_t Geert Uytterhoeven
2014-01-15  9:06 ` [PATCH -next 2/2] bcache: Use max_t() when comparing different types Geert Uytterhoeven
2014-01-15 11:06   ` Joe Perches
2014-02-03 13:47     ` Geert Uytterhoeven [this message]
2014-02-06  9:00       ` Geert Uytterhoeven
2014-02-06  9:06         ` Joe Perches
2014-02-06 20:38           ` Andrew Morton
2014-02-06 20:45             ` Geert Uytterhoeven
2014-02-06 20:50               ` Andrew Morton
2014-02-06 20:53                 ` Geert Uytterhoeven

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='CAMuHMdUv_xP-1A950i0U=Petaey-_VosSxh5sk44Gqti-ikY6w@mail.gmail.com' \
    --to=geert@linux-m68k.org \
    --cc=joe@perches.com \
    --cc=kmo@daterainc.com \
    --cc=linux-bcache@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-next@vger.kernel.org \
    --cc=neilb@suse.de \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).