lkml.org 
[lkml]   [2014]   [Feb]   [27]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    Patch in this message
    /
    SubjectRe: [PATCH 1/2] asm-generic: rwsem: ensure sem->cnt is only accessed via atomic_long_*
    From
    Date
    On Fri, 2014-02-21 at 17:22 +0000, Will Deacon wrote:
    > The asm-generic rwsem implementation directly acceses sem->cnt when
    > performing a __down_read_trylock operation. Whilst this is probably safe
    > on all architectures, we should stick to the atomic_long_* API and use
    > atomic_long_read instead.
    >
    > Signed-off-by: Will Deacon <will.deacon@arm.com>
    > ---
    > include/asm-generic/rwsem.h | 2 +-
    > 1 file changed, 1 insertion(+), 1 deletion(-)
    >
    > diff --git a/include/asm-generic/rwsem.h b/include/asm-generic/rwsem.h
    > index bb1e2cdeb9bf..75af612f54f8 100644
    > --- a/include/asm-generic/rwsem.h
    > +++ b/include/asm-generic/rwsem.h
    > @@ -41,7 +41,7 @@ static inline int __down_read_trylock(struct rw_semaphore *sem)
    > {
    > long tmp;
    >
    > - while ((tmp = sem->count) >= 0) {
    > + while ((tmp = atomic_long_read((atomic_long_t *)&sem->count)) >= 0) {

    That's pretty ugly, how about having infinite look and just do the tmp
    assign separately from the conditional?

    It also looks like a cpu_relax() could help here between iterations.
    Other than that:

    Reviewed-by: Davidlohr Bueso <davidlohr@hp.com>



    \
     
     \ /
      Last update: 2014-02-27 07:21    [W:3.029 / U:0.036 seconds]
    ©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site