diff mbox

[libdrm] atomic: fix atomic_add_unless() fallback's return value

Message ID 20170316000859.25038-1-eric@engestrom.ch (mailing list archive)
State New, archived
Headers show

Commit Message

Eric Engestrom March 16, 2017, 12:08 a.m. UTC
According to the kernel documentation:
  Returns non-zero if @v was not @u, and zero otherwise.

Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=100077
Fixes: 63fc571863aa64683400 ("atomic: add atomic_add_unless()")
Signed-off-by: David Shao <davshao@gmail.com>
Reviewed-by: Eric Engestrom <eric@engestrom.ch>
Signed-off-by: Eric Engestrom <eric@engestrom.ch>
---
 xf86atomic.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Eric Engestrom March 16, 2017, 4:46 p.m. UTC | #1
On Thursday, 2017-03-16 00:08:59 +0000, Eric Engestrom wrote:
> According to the kernel documentation:
>   Returns non-zero if @v was not @u, and zero otherwise.
> 
> Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=100077
> Fixes: 63fc571863aa64683400 ("atomic: add atomic_add_unless()")
> Signed-off-by: David Shao <davshao@gmail.com>
> Reviewed-by: Eric Engestrom <eric@engestrom.ch>
> Signed-off-by: Eric Engestrom <eric@engestrom.ch>

That last s-o-b was added automatically, by mistake. I'll remove it when
pushing this.

This patch seems trivial to verify, can someone confirm this is right?

/me is about ~94% sure, but doesn't know much about atomic ops and their
return value convention.

I checked the kernel and it does what libdrm does after this patch, so
either one should be fixed; I'm assuming kernel is right and libdrm
needs fixing, hence this patch.

Cheers,
  Eric

> ---
>  xf86atomic.h | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/xf86atomic.h b/xf86atomic.h
> index 922b37da..ecb1ba86 100644
> --- a/xf86atomic.h
> +++ b/xf86atomic.h
> @@ -111,7 +111,7 @@ static inline int atomic_add_unless(atomic_t *v, int add, int unless)
>  	c = atomic_read(v);
>  	while (c != unless && (old = atomic_cmpxchg(v, c, c + add)) != c)
>  		c = old;
> -	return c == unless;
> +	return c != unless;
>  }
>  
>  #endif
> -- 
> Cheers,
>   Eric
>
Emil Velikov March 17, 2017, 7:08 p.m. UTC | #2
[+ Lionel]

On 16 March 2017 at 16:46, Eric Engestrom <eric.engestrom@imgtec.com> wrote:
> On Thursday, 2017-03-16 00:08:59 +0000, Eric Engestrom wrote:
>> According to the kernel documentation:
>>   Returns non-zero if @v was not @u, and zero otherwise.
>>
>> Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=100077
>> Fixes: 63fc571863aa64683400 ("atomic: add atomic_add_unless()")
>> Signed-off-by: David Shao <davshao@gmail.com>
>> Reviewed-by: Eric Engestrom <eric@engestrom.ch>
>> Signed-off-by: Eric Engestrom <eric@engestrom.ch>
>
> That last s-o-b was added automatically, by mistake. I'll remove it when
> pushing this.
>
> This patch seems trivial to verify, can someone confirm this is right?
>
> /me is about ~94% sure, but doesn't know much about atomic ops and their
> return value convention.
>
> I checked the kernel and it does what libdrm does after this patch, so
> either one should be fixed; I'm assuming kernel is right and libdrm
> needs fixing, hence this patch.
>
Changing the function matches the documentation, yet it doesn't [seem
to] align with how it's used.
I'm fairly sure that this will break libdrm_intel.

Lionel, can you take a look at this patch please ?
https://patchwork.freedesktop.org/patch/144252/

Emil
diff mbox

Patch

diff --git a/xf86atomic.h b/xf86atomic.h
index 922b37da..ecb1ba86 100644
--- a/xf86atomic.h
+++ b/xf86atomic.h
@@ -111,7 +111,7 @@  static inline int atomic_add_unless(atomic_t *v, int add, int unless)
 	c = atomic_read(v);
 	while (c != unless && (old = atomic_cmpxchg(v, c, c + add)) != c)
 		c = old;
-	return c == unless;
+	return c != unless;
 }
 
 #endif