[1/2] zdtm/lib: Check EWOULDBLOCK in errno instead of -EWOULDBLOCK

Submitted by Adrian Reber on June 13, 2018, 12:12 p.m.

Details

Message ID 1528891950-25141-1-git-send-email-adrian@lisas.de
State Accepted
Series "Series without cover letter"
Headers show

Commit Message

Adrian Reber June 13, 2018, 12:12 p.m.
From: Dmitry Safonov <dima@arista.com>

Syscalls do return negative value in case of an error.
But errno contains the error code itself.

Add uint32_t to sys_futex() definition.
sizeof(unsigned int) might be not 4 bytes.

Signed-off-by: Dmitry Safonov <dima@arista.com>
Signed-off-by: Adrian Reber <areber@redhat.com>
---
 test/zdtm/lib/lock.h | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

Patch hide | download patch | download mbox

diff --git a/test/zdtm/lib/lock.h b/test/zdtm/lib/lock.h
index 972ed57..9c0831d 100644
--- a/test/zdtm/lib/lock.h
+++ b/test/zdtm/lib/lock.h
@@ -23,8 +23,8 @@  typedef struct {
 #define FUTEX_ABORT_FLAG	(0x80000000)
 #define FUTEX_ABORT_RAW		(-1U)
 
-static inline int sys_futex(unsigned int *uaddr, int op, unsigned int val, const struct timespec *timeout,
-                 int *uaddr2, unsigned int val3)
+static inline int sys_futex(uint32_t *uaddr, int op, uint32_t val, const struct timespec *timeout,
+                 uint32_t *uaddr2, uint32_t val3)
 {
 	return syscall(__NR_futex, uaddr, op, val, timeout, uaddr2, val3);
 }
@@ -142,11 +142,11 @@  static void inline mutex_lock(mutex_t *m)
 	uint32_t c;
 	int ret;
 
-	while ((c = atomic_inc(&m->raw))) {
+	while ((c = atomic_inc(&m->raw)) != 0) {
 		ret = sys_futex(&m->raw, FUTEX_WAIT, c + 1, NULL, NULL, 0);
 		if (ret < 0)
 			pr_perror("futex");
-		BUG_ON(ret < 0 && errno != -EWOULDBLOCK);
+		BUG_ON(ret < 0 && errno != EWOULDBLOCK);
 	}
 }
 

Comments

Andrey Vagin June 14, 2018, 5:23 p.m.
Applied, thanks!

On Wed, Jun 13, 2018 at 12:12:29PM +0000, Adrian Reber wrote:
> From: Dmitry Safonov <dima@arista.com>
> 
> Syscalls do return negative value in case of an error.
> But errno contains the error code itself.
> 
> Add uint32_t to sys_futex() definition.
> sizeof(unsigned int) might be not 4 bytes.
> 
> Signed-off-by: Dmitry Safonov <dima@arista.com>
> Signed-off-by: Adrian Reber <areber@redhat.com>
> ---
>  test/zdtm/lib/lock.h | 8 ++++----
>  1 file changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/test/zdtm/lib/lock.h b/test/zdtm/lib/lock.h
> index 972ed57..9c0831d 100644
> --- a/test/zdtm/lib/lock.h
> +++ b/test/zdtm/lib/lock.h
> @@ -23,8 +23,8 @@ typedef struct {
>  #define FUTEX_ABORT_FLAG	(0x80000000)
>  #define FUTEX_ABORT_RAW		(-1U)
>  
> -static inline int sys_futex(unsigned int *uaddr, int op, unsigned int val, const struct timespec *timeout,
> -                 int *uaddr2, unsigned int val3)
> +static inline int sys_futex(uint32_t *uaddr, int op, uint32_t val, const struct timespec *timeout,
> +                 uint32_t *uaddr2, uint32_t val3)
>  {
>  	return syscall(__NR_futex, uaddr, op, val, timeout, uaddr2, val3);
>  }
> @@ -142,11 +142,11 @@ static void inline mutex_lock(mutex_t *m)
>  	uint32_t c;
>  	int ret;
>  
> -	while ((c = atomic_inc(&m->raw))) {
> +	while ((c = atomic_inc(&m->raw)) != 0) {
>  		ret = sys_futex(&m->raw, FUTEX_WAIT, c + 1, NULL, NULL, 0);
>  		if (ret < 0)
>  			pr_perror("futex");
> -		BUG_ON(ret < 0 && errno != -EWOULDBLOCK);
> +		BUG_ON(ret < 0 && errno != EWOULDBLOCK);
>  	}
>  }
>  
> -- 
> 1.8.3.1
>