Commit 0771cbb3 authored by Luiz Augusto von Dentz's avatar Luiz Augusto von Dentz Committed by Marcel Holtmann

Bluetooth: SCO: Replace use of memcpy_from_msg with bt_skb_sendmsg

This makes use of bt_skb_sendmsg instead of allocating a different
buffer to be used with memcpy_from_msg which cause one extra copy.
Signed-off-by: default avatarLuiz Augusto von Dentz <luiz.von.dentz@intel.com>
Signed-off-by: default avatarMarcel Holtmann <marcel@holtmann.org>
parent 97e4e802
...@@ -281,27 +281,19 @@ static int sco_connect(struct hci_dev *hdev, struct sock *sk) ...@@ -281,27 +281,19 @@ static int sco_connect(struct hci_dev *hdev, struct sock *sk)
return err; return err;
} }
static int sco_send_frame(struct sock *sk, void *buf, int len, static int sco_send_frame(struct sock *sk, struct sk_buff *skb)
unsigned int msg_flags)
{ {
struct sco_conn *conn = sco_pi(sk)->conn; struct sco_conn *conn = sco_pi(sk)->conn;
struct sk_buff *skb;
int err;
/* Check outgoing MTU */ /* Check outgoing MTU */
if (len > conn->mtu) if (skb->len > conn->mtu)
return -EINVAL; return -EINVAL;
BT_DBG("sk %p len %d", sk, len); BT_DBG("sk %p len %d", sk, skb->len);
skb = bt_skb_send_alloc(sk, len, msg_flags & MSG_DONTWAIT, &err);
if (!skb)
return err;
memcpy(skb_put(skb, len), buf, len);
hci_send_sco(conn->hcon, skb); hci_send_sco(conn->hcon, skb);
return len; return skb->len;
} }
static void sco_recv_frame(struct sco_conn *conn, struct sk_buff *skb) static void sco_recv_frame(struct sco_conn *conn, struct sk_buff *skb)
...@@ -728,7 +720,7 @@ static int sco_sock_sendmsg(struct socket *sock, struct msghdr *msg, ...@@ -728,7 +720,7 @@ static int sco_sock_sendmsg(struct socket *sock, struct msghdr *msg,
size_t len) size_t len)
{ {
struct sock *sk = sock->sk; struct sock *sk = sock->sk;
void *buf; struct sk_buff *skb;
int err; int err;
BT_DBG("sock %p, sk %p", sock, sk); BT_DBG("sock %p, sk %p", sock, sk);
...@@ -740,24 +732,20 @@ static int sco_sock_sendmsg(struct socket *sock, struct msghdr *msg, ...@@ -740,24 +732,20 @@ static int sco_sock_sendmsg(struct socket *sock, struct msghdr *msg,
if (msg->msg_flags & MSG_OOB) if (msg->msg_flags & MSG_OOB)
return -EOPNOTSUPP; return -EOPNOTSUPP;
buf = kmalloc(len, GFP_KERNEL); skb = bt_skb_sendmsg(sk, msg, len, len, 0, 0);
if (!buf) if (IS_ERR_OR_NULL(skb))
return -ENOMEM; return PTR_ERR(skb);
if (memcpy_from_msg(buf, msg, len)) {
kfree(buf);
return -EFAULT;
}
lock_sock(sk); lock_sock(sk);
if (sk->sk_state == BT_CONNECTED) if (sk->sk_state == BT_CONNECTED)
err = sco_send_frame(sk, buf, len, msg->msg_flags); err = sco_send_frame(sk, skb);
else else
err = -ENOTCONN; err = -ENOTCONN;
release_sock(sk); release_sock(sk);
kfree(buf); if (err)
kfree_skb(skb);
return err; return err;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment