lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:	Mon, 3 Feb 2014 14:47:20 +0100
From:	Geert Uytterhoeven <geert@...ux-m68k.org>
To:	Joe Perches <joe@...ches.com>
Cc:	Kent Overstreet <kmo@...erainc.com>, Neil Brown <neilb@...e.de>,
	linux-bcache@...r.kernel.org,
	"linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>,
	Linux-Next <linux-next@...r.kernel.org>
Subject: Re: [PATCH -next 2/2] bcache: Use max_t() when comparing different types

On Wed, Jan 15, 2014 at 12:06 PM, Joe Perches <joe@...ches.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@...ux-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
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ