mirror of
https://github.com/torvalds/linux.git
synced 2026-07-27 09:36:22 +02:00
Bluetooth: hci_sock: convert to getsockopt_iter
Convert HCI socket's getsockopt implementation to use the new getsockopt_iter callback with sockopt_t. Key changes: - Replace (char __user *optval, int __user *optlen) with sockopt_t *sopt - Use sopt->optlen for buffer length (input) - Use copy_to_iter() instead of put_user()/copy_to_user() - Add linux/uio.h for copy_to_iter() The sockopt_t parameter is named sopt rather than opt to avoid collision with the existing local int opt used by HCI_DATA_DIR and HCI_TIME_STAMP. Signed-off-by: Breno Leitao <leitao@debian.org> Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
This commit is contained in:
parent
79cf74d870
commit
ad6cde3066
|
|
@ -27,6 +27,7 @@
|
|||
#include <linux/export.h>
|
||||
#include <linux/utsname.h>
|
||||
#include <linux/sched.h>
|
||||
#include <linux/uio.h>
|
||||
#include <linux/unaligned.h>
|
||||
|
||||
#include <net/bluetooth/bluetooth.h>
|
||||
|
|
@ -2063,7 +2064,7 @@ static int hci_sock_setsockopt(struct socket *sock, int level, int optname,
|
|||
}
|
||||
|
||||
static int hci_sock_getsockopt_old(struct socket *sock, int level, int optname,
|
||||
char __user *optval, int __user *optlen)
|
||||
sockopt_t *sopt)
|
||||
{
|
||||
struct hci_ufilter uf;
|
||||
struct sock *sk = sock->sk;
|
||||
|
|
@ -2071,8 +2072,7 @@ static int hci_sock_getsockopt_old(struct socket *sock, int level, int optname,
|
|||
|
||||
BT_DBG("sk %p, opt %d", sk, optname);
|
||||
|
||||
if (get_user(len, optlen))
|
||||
return -EFAULT;
|
||||
len = sopt->optlen;
|
||||
|
||||
lock_sock(sk);
|
||||
|
||||
|
|
@ -2088,7 +2088,8 @@ static int hci_sock_getsockopt_old(struct socket *sock, int level, int optname,
|
|||
else
|
||||
opt = 0;
|
||||
|
||||
if (put_user(opt, (int __user *)optval))
|
||||
if (copy_to_iter(&opt, sizeof(opt), &sopt->iter_out) !=
|
||||
sizeof(opt))
|
||||
err = -EFAULT;
|
||||
break;
|
||||
|
||||
|
|
@ -2098,7 +2099,8 @@ static int hci_sock_getsockopt_old(struct socket *sock, int level, int optname,
|
|||
else
|
||||
opt = 0;
|
||||
|
||||
if (put_user(opt, (int __user *)optval))
|
||||
if (copy_to_iter(&opt, sizeof(opt), &sopt->iter_out) !=
|
||||
sizeof(opt))
|
||||
err = -EFAULT;
|
||||
break;
|
||||
|
||||
|
|
@ -2114,7 +2116,7 @@ static int hci_sock_getsockopt_old(struct socket *sock, int level, int optname,
|
|||
}
|
||||
|
||||
len = min_t(unsigned int, len, sizeof(uf));
|
||||
if (copy_to_user(optval, &uf, len))
|
||||
if (copy_to_iter(&uf, len, &sopt->iter_out) != len)
|
||||
err = -EFAULT;
|
||||
break;
|
||||
|
||||
|
|
@ -2129,16 +2131,16 @@ static int hci_sock_getsockopt_old(struct socket *sock, int level, int optname,
|
|||
}
|
||||
|
||||
static int hci_sock_getsockopt(struct socket *sock, int level, int optname,
|
||||
char __user *optval, int __user *optlen)
|
||||
sockopt_t *sopt)
|
||||
{
|
||||
struct sock *sk = sock->sk;
|
||||
int err = 0;
|
||||
u16 mtu;
|
||||
|
||||
BT_DBG("sk %p, opt %d", sk, optname);
|
||||
|
||||
if (level == SOL_HCI)
|
||||
return hci_sock_getsockopt_old(sock, level, optname, optval,
|
||||
optlen);
|
||||
return hci_sock_getsockopt_old(sock, level, optname, sopt);
|
||||
|
||||
if (level != SOL_BLUETOOTH)
|
||||
return -ENOPROTOOPT;
|
||||
|
|
@ -2148,7 +2150,9 @@ static int hci_sock_getsockopt(struct socket *sock, int level, int optname,
|
|||
switch (optname) {
|
||||
case BT_SNDMTU:
|
||||
case BT_RCVMTU:
|
||||
if (put_user(hci_pi(sk)->mtu, (u16 __user *)optval))
|
||||
mtu = hci_pi(sk)->mtu;
|
||||
if (copy_to_iter(&mtu, sizeof(mtu), &sopt->iter_out) !=
|
||||
sizeof(mtu))
|
||||
err = -EFAULT;
|
||||
break;
|
||||
|
||||
|
|
@ -2185,7 +2189,7 @@ static const struct proto_ops hci_sock_ops = {
|
|||
.listen = sock_no_listen,
|
||||
.shutdown = sock_no_shutdown,
|
||||
.setsockopt = hci_sock_setsockopt,
|
||||
.getsockopt = hci_sock_getsockopt,
|
||||
.getsockopt_iter = hci_sock_getsockopt,
|
||||
.connect = sock_no_connect,
|
||||
.socketpair = sock_no_socketpair,
|
||||
.accept = sock_no_accept,
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user