# Re: \[PATCH v3 net-next 1/9\] af\_unix: Factorise test\_bit() for SOCK\_PASSCRED and SOCK\_PASSPIDFD.

- From: Willem de Bruijn \<willemdebruijn.kernel@gmail.com\>
- Date: 2025-05-15 18:07:07 
- List: netdev
- Page: https://ratatoskr.run/netdev/2025/05/11327366
- Thread: https://ratatoskr.run/netdev/2025/05/11327261/t.md

```text
Kuniyuki Iwashima wrote:
> Currently, the same checks for SOCK_PASSCRED and SOCK_PASSPIDFD
> are scattered across many places.
> 
> Let's centralise the bit tests to make the following changes cleaner.
> 
> Signed-off-by: Kuniyuki Iwashima <redacted>
> ---
>  net/unix/af_unix.c | 37 +++++++++++++++----------------------
>  1 file changed, 15 insertions(+), 22 deletions(-)
> 
> diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c
> index 2ab20821d6bb..464e183ffdb8 100644
> --- a/net/unix/af_unix.c
> +++ b/net/unix/af_unix.c
> @@ -765,6 +765,14 @@ static void copy_peercred(struct sock *sk, struct sock *peersk)
>  	spin_unlock(&sk->sk_peer_lock);
>  }
>  
> +static bool unix_may_passcred(const struct sock *sk)
> +{
> +	struct socket *sock = sk->sk_socket;

Also const?

> +
> +	return test_bit(SOCK_PASSCRED, &sock->flags) ||
> +		test_bit(SOCK_PASSPIDFD, &sock->flags);
> +}
```
