|
Message-ID: <CAGXu5j+eX4A5E5YQq3WmgWmW16nCUwswZsbwzVGdd1v8i72JLA@mail.gmail.com> Date: Thu, 1 Jun 2017 07:43:37 -0700 From: Kees Cook <keescook@...omium.org> To: Peter Zijlstra <peterz@...radead.org> Cc: "Reshetova, Elena" <elena.reshetova@...el.com>, "linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>, Christoph Hellwig <hch@...radead.org>, "Eric W. Biederman" <ebiederm@...ssion.com>, Andrew Morton <akpm@...ux-foundation.org>, Josh Poimboeuf <jpoimboe@...hat.com>, PaX Team <pageexec@...email.hu>, Jann Horn <jannh@...gle.com>, Eric Biggers <ebiggers3@...il.com>, Hans Liljestrand <ishkamiel@...il.com>, David Windsor <dwindsor@...il.com>, Greg KH <gregkh@...uxfoundation.org>, Ingo Molnar <mingo@...hat.com>, Alexey Dobriyan <adobriyan@...il.com>, "Serge E. Hallyn" <serge@...lyn.com>, "arozansk@...hat.com" <arozansk@...hat.com>, Davidlohr Bueso <dave@...olabs.net>, Manfred Spraul <manfred@...orfullife.com>, "axboe@...nel.dk" <axboe@...nel.dk>, James Bottomley <James.Bottomley@...senpartnership.com>, "x86@...nel.org" <x86@...nel.org>, Ingo Molnar <mingo@...nel.org>, Arnd Bergmann <arnd@...db.de>, "David S. Miller" <davem@...emloft.net>, Rik van Riel <riel@...hat.com>, linux-arch <linux-arch@...r.kernel.org>, "kernel-hardening@...ts.openwall.com" <kernel-hardening@...ts.openwall.com> Subject: Re: [PATCH v5 1/3] refcount: Create unchecked atomic_t implementation On Wed, May 31, 2017 at 4:09 AM, Peter Zijlstra <peterz@...radead.org> wrote: > On Wed, May 31, 2017 at 10:45:09AM +0000, Reshetova, Elena wrote: > >> > +static inline __must_check bool refcount_add_not_zero(unsigned int i, >> > + >> > refcount_t *r) >> > +{ >> > + return atomic_add_return(i, &r->refs) != 0; >> > +} >> >> Maybe atomic_add_unless(&r->refs, i, 0) in order to be consistent with the below inc_not_zero implementation? > > Yes, atomic_add_return() is strictly incorrect here since the add is > unconditional. > >> > +static inline __must_check bool refcount_sub_and_test(unsigned int i, >> > + >> > refcount_t *r) >> > +{ >> > + return atomic_sub_return(i, &r->refs) == 0; >> > +} >> >> Any reason for not using atomic_sub_and_test() here? > >> > +static inline __must_check bool refcount_dec_and_test(refcount_t *r) >> > +{ >> > + return atomic_dec_return(&r->refs) == 0; >> > +} >> >> Same here: atomic_dec_and_test()? > > Both those are better because they return condition codes generated from > the operand itself. Ah yes, thanks to both of you for the corrections. I'll send a new version... -Kees -- Kees Cook Pixel Security
Powered by blists - more mailing lists
Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.