Re: [PATCH v4 04/10] net/socket: Break down __sys_getsockopt

From: Andy Shevchenko
Date: Tue Sep 05 2023 - 12:03:34 EST


On Mon, Sep 04, 2023 at 09:24:57AM -0700, Breno Leitao wrote:
> Split __sys_getsockopt() into two functions by removing the core
> logic into a sub-function (do_sock_getsockopt()). This will avoid
> code duplication when doing the same operation in other callers, for
> instance.
>
> do_sock_getsockopt() will be called by io_uring getsockopt() command
> operation in the following patch.
>
> The same was done for the setsockopt pair.

...

> + ops = READ_ONCE(sock->ops);
> + if (level == SOL_SOCKET) {
> + err = sk_getsockopt(sock->sk, level, optname, optval, optlen);
> + } else if (unlikely(!ops->getsockopt)) {
> + err = -EOPNOTSUPP;
> + } else {
> + if (WARN_ONCE(optval.is_kernel || optlen.is_kernel,
> + "Invalid argument type"))
> + return -EOPNOTSUPP;
> +
> + err = ops->getsockopt(sock, level, optname, optval.user,
> + optlen.user);
> + }

Can be written as

} else if (WARN_ONCE(optval.is_kernel || optlen.is_kernel,
"Invalid argument type"))
return -EOPNOTSUPP;
} else {
err = ops->getsockopt(sock, level, optname, optval.user,
optlen.user);
}

With that done, the {} are not needed anymore.

> + if (!compat) {

if (compat)
return err;

> + max_optlen = BPF_CGROUP_GETSOCKOPT_MAX_OPTLEN(optlen);

> + err = BPF_CGROUP_RUN_PROG_GETSOCKOPT(sock->sk, level, optname,
> + optval, optlen, max_optlen,
> + err);

return ... ?

> + }
> +
> + return err;
> +}

--
With Best Regards,
Andy Shevchenko