[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <cbe1fd40-2d9f-4396-84a0-741db2c5c586@gmail.com>
Date: Tue, 22 Oct 2024 10:07:25 -0500
From: Denis Kenzior <denkenz@...il.com>
To: Kuniyuki Iwashima <kuniyu@...zon.com>
Cc: agross@...nel.org, almasrymina@...gle.com, asml.silence@...il.com,
axboe@...nel.dk, davem@...emloft.net, edumazet@...gle.com, krisman@...e.de,
kuba@...nel.org, linux-arm-msm@...r.kernel.org,
linux-kernel@...r.kernel.org, manivannan.sadhasivam@...aro.org,
marcel@...tmann.org, netdev@...r.kernel.org, pabeni@...hat.com
Subject: Re: [RFC PATCH v1 04/10] net: qrtr: Report sender endpoint in aux
data
On 10/18/24 7:22 PM, Kuniyuki Iwashima wrote:
> From: Denis Kenzior <denkenz@...il.com>
> Date: Fri, 18 Oct 2024 13:18:22 -0500
>> @@ -1234,6 +1247,78 @@ static int qrtr_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
>> return rc;
>> }
>>
>> +static int qrtr_setsockopt(struct socket *sock, int level, int optname,
>> + sockptr_t optval, unsigned int optlen)
>> +{
>> + struct qrtr_sock *ipc = qrtr_sk(sock->sk);
>> + struct sock *sk = sock->sk;
>> + unsigned int val = 0;
>> + int rc = 0;
>> +
>> + if (level != SOL_QRTR)
>> + return -ENOPROTOOPT;
>> +
>> + if (optlen >= sizeof(val) &&
>> + copy_from_sockptr(&val, optval, sizeof(val)))
>> + return -EFAULT;
>> +
>> + lock_sock(sk);
>
> This seems unnecessary to me.
>
> sk_setsockopt(), do_ip_setsockopt(), and do_ipv6_setsockopt() do not
> hold lock_sock() for assign_bit().
Indeed, thanks for spotting that. I'll fix this in the next version. I'll also
drop lock_sock/release_sock in qrtr_sock_set_report_endpoint (patch 9).
>
> Also, QRTR_BIND_ENDPOINT in a later patch will not need lock_sock()
> neither. The value is u32, so you can use WRITE_ONCE() here and
> READ_ONCE() in getsockopt().
>
Makes sense, I'll fix this as well.
>
>> +
>> + switch (optname) {
>> + case QRTR_REPORT_ENDPOINT:
>> + assign_bit(QRTR_F_REPORT_ENDPOINT, &ipc->flags, val);
>> + break;
>> + default:
>> + rc = -ENOPROTOOPT;
>> + }
>> +
>> + release_sock(sk);
>> +
>> + return rc;
>> +}
>> +
>> +static int qrtr_getsockopt(struct socket *sock, int level, int optname,
>> + char __user *optval, int __user *optlen)
>> +{
>> + struct qrtr_sock *ipc = qrtr_sk(sock->sk);
>> + struct sock *sk = sock->sk;
>> + unsigned int val;
>> + int len;
>> + int rc = 0;
>> +
>> + if (level != SOL_QRTR)
>> + return -ENOPROTOOPT;
>> +
>> + if (get_user(len, optlen))
>> + return -EFAULT;
>> +
>> + if (len < sizeof(val))
>> + return -EINVAL;
>> +
>> + lock_sock(sk);
>
> Same remark.
>
>
>> +
>> + switch (optname) {
>> + case QRTR_REPORT_ENDPOINT:
>> + val = test_bit(QRTR_F_REPORT_ENDPOINT, &ipc->flags);
>> + break;
>> + default:
>> + rc = -ENOPROTOOPT;
>> + }
>> +
>> + release_sock(sk);
>> +
>> + if (rc)
>> + return rc;
>> +
>> + len = sizeof(int);
>> +
>> + if (put_user(len, optlen) ||
>> + copy_to_user(optval, &val, len))
>> + rc = -EFAULT;
>> +
>> + return rc;
>> +}
>> +
>> static int qrtr_release(struct socket *sock)
>> {
>> struct sock *sk = sock->sk;
Powered by blists - more mailing lists