diff mbox series

hurd fcntl: remove duplicate do...while in LOCKED macro

Message ID tencent_6AE67FD99D9CE0D5E6F93FFF6CE49CED1E09@qq.com
State New
Headers show
Series hurd fcntl: remove duplicate do...while in LOCKED macro | expand

Commit Message

develop--- via Libc-alpha Jan. 4, 2023, 10:30 a.m. UTC
From: abushwang <wangshuo_1994@foxmail.com>

commit e1a467d introduces do...while for LOCKED macro. However, there is
already while(0) in LOCKED macro according to HURD_CRITICAL_END in hurd/hurd/signal.h:

    #define HURD_CRITICAL_BEGIN \
      { void *__hurd_critical__ = _hurd_critical_section_lock ()
    #define HURD_CRITICAL_END \
          _hurd_critical_section_unlock (__hurd_critical__); } while (0)

It is robust enough.

Signed-off-by: abushwang <wangshuo_1994@foxmail.com>
---
 sysdeps/mach/hurd/fcntl.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

Comments

Samuel Thibault Jan. 4, 2023, 11:56 a.m. UTC | #1
wangshuo_1994@foxmail.com, le mer. 04 janv. 2023 18:30:57 +0800, a ecrit:
> From: abushwang <wangshuo_1994@foxmail.com>
> 
> commit e1a467d introduces do...while for LOCKED macro. However, there is
> already while(0) in LOCKED macro according to HURD_CRITICAL_END in hurd/hurd/signal.h:
> 
>     #define HURD_CRITICAL_BEGIN \
>       { void *__hurd_critical__ = _hurd_critical_section_lock ()
>     #define HURD_CRITICAL_END \
>           _hurd_critical_section_unlock (__hurd_critical__); } while (0)
> 
> It is robust enough.

That's true, but that's a bit hidden, and might someday go away.

The original purpose of my change was to avoid exposing a double ';' to
static analyzers who then frown upon it.

The do { } while(0) shouldn't be harmful anyway, so I prefer to keep it.

Samuel

> Signed-off-by: abushwang <wangshuo_1994@foxmail.com>
> ---
>  sysdeps/mach/hurd/fcntl.c | 5 ++---
>  1 file changed, 2 insertions(+), 3 deletions(-)
> 
> diff --git a/sysdeps/mach/hurd/fcntl.c b/sysdeps/mach/hurd/fcntl.c
> index 48608493a1..ea35e9b977 100644
> --- a/sysdeps/mach/hurd/fcntl.c
> +++ b/sysdeps/mach/hurd/fcntl.c
> @@ -109,7 +109,7 @@ __libc_fcntl (int fd, int cmd, ...)
>  
>        /* Set RESULT by evaluating EXPR with the descriptor locked.
>  	 Check for an empty descriptor and return EBADF.  */
> -#define LOCKED(expr) do {						      \
> +#define LOCKED(expr)							      \
>        HURD_CRITICAL_BEGIN;						      \
>        __spin_lock (&d->port.lock);					      \
>        if (d->port.port == MACH_PORT_NULL)				      \
> @@ -117,8 +117,7 @@ __libc_fcntl (int fd, int cmd, ...)
>        else								      \
>  	result = (expr);						      \
>        __spin_unlock (&d->port.lock);					      \
> -      HURD_CRITICAL_END;						      \
> -} while(0)
> +      HURD_CRITICAL_END;
>  
>      case F_GETFD:		/* Get descriptor flags.  */
>        LOCKED (d->flags);
> -- 
> 2.37.3
diff mbox series

Patch

diff --git a/sysdeps/mach/hurd/fcntl.c b/sysdeps/mach/hurd/fcntl.c
index 48608493a1..ea35e9b977 100644
--- a/sysdeps/mach/hurd/fcntl.c
+++ b/sysdeps/mach/hurd/fcntl.c
@@ -109,7 +109,7 @@  __libc_fcntl (int fd, int cmd, ...)
 
       /* Set RESULT by evaluating EXPR with the descriptor locked.
 	 Check for an empty descriptor and return EBADF.  */
-#define LOCKED(expr) do {						      \
+#define LOCKED(expr)							      \
       HURD_CRITICAL_BEGIN;						      \
       __spin_lock (&d->port.lock);					      \
       if (d->port.port == MACH_PORT_NULL)				      \
@@ -117,8 +117,7 @@  __libc_fcntl (int fd, int cmd, ...)
       else								      \
 	result = (expr);						      \
       __spin_unlock (&d->port.lock);					      \
-      HURD_CRITICAL_END;						      \
-} while(0)
+      HURD_CRITICAL_END;
 
     case F_GETFD:		/* Get descriptor flags.  */
       LOCKED (d->flags);