Commit 7c7cd3bf authored by Samuel Ortiz's avatar Samuel Ortiz Committed by John W. Linville

NFC: Add tx skb allocation routine

This is a factorization of the current rawsock tx skb allocation routine,
as it will be used by the LLCP code.
We also rename nfc_alloc_skb to nfc_alloc_recv_skb for consistency sake.
Signed-off-by: default avatarSamuel Ortiz <sameo@linux.intel.com>
Signed-off-by: default avatarJohn W. Linville <linville@tuxdriver.com>
parent 52858b51
...@@ -1368,7 +1368,7 @@ static int pn533_data_exchange(struct nfc_dev *nfc_dev, u32 target_idx, ...@@ -1368,7 +1368,7 @@ static int pn533_data_exchange(struct nfc_dev *nfc_dev, u32 target_idx,
PN533_CMD_DATAEXCH_DATA_MAXLEN + PN533_CMD_DATAEXCH_DATA_MAXLEN +
PN533_FRAME_TAIL_SIZE; PN533_FRAME_TAIL_SIZE;
skb_resp = nfc_alloc_skb(skb_resp_len, GFP_KERNEL); skb_resp = nfc_alloc_recv_skb(skb_resp_len, GFP_KERNEL);
if (!skb_resp) { if (!skb_resp) {
rc = -ENOMEM; rc = -ENOMEM;
goto error; goto error;
......
...@@ -157,7 +157,10 @@ static inline const char *nfc_device_name(struct nfc_dev *dev) ...@@ -157,7 +157,10 @@ static inline const char *nfc_device_name(struct nfc_dev *dev)
return dev_name(&dev->dev); return dev_name(&dev->dev);
} }
struct sk_buff *nfc_alloc_skb(unsigned int size, gfp_t gfp); struct sk_buff *nfc_alloc_send_skb(struct nfc_dev *dev, struct sock *sk,
unsigned int flags, unsigned int size,
unsigned int *err);
struct sk_buff *nfc_alloc_recv_skb(unsigned int size, gfp_t gfp);
int nfc_targets_found(struct nfc_dev *dev, struct nfc_target *targets, int nfc_targets_found(struct nfc_dev *dev, struct nfc_target *targets,
int ntargets); int ntargets);
......
...@@ -27,6 +27,7 @@ ...@@ -27,6 +27,7 @@
#include <linux/kernel.h> #include <linux/kernel.h>
#include <linux/module.h> #include <linux/module.h>
#include <linux/slab.h> #include <linux/slab.h>
#include <linux/nfc.h>
#include "nfc.h" #include "nfc.h"
...@@ -275,12 +276,35 @@ int nfc_data_exchange(struct nfc_dev *dev, u32 target_idx, ...@@ -275,12 +276,35 @@ int nfc_data_exchange(struct nfc_dev *dev, u32 target_idx,
} }
/** /**
* nfc_alloc_skb - allocate a skb for data exchange responses * nfc_alloc_send_skb - allocate a skb for data exchange responses
* *
* @size: size to allocate * @size: size to allocate
* @gfp: gfp flags * @gfp: gfp flags
*/ */
struct sk_buff *nfc_alloc_skb(unsigned int size, gfp_t gfp) struct sk_buff *nfc_alloc_send_skb(struct nfc_dev *dev, struct sock *sk,
unsigned int flags, unsigned int size,
unsigned int *err)
{
struct sk_buff *skb;
unsigned int total_size;
total_size = size +
dev->tx_headroom + dev->tx_tailroom + NFC_HEADER_SIZE;
skb = sock_alloc_send_skb(sk, total_size, flags & MSG_DONTWAIT, err);
if (skb)
skb_reserve(skb, dev->tx_headroom + NFC_HEADER_SIZE);
return skb;
}
/**
* nfc_alloc_recv_skb - allocate a skb for data exchange responses
*
* @size: size to allocate
* @gfp: gfp flags
*/
struct sk_buff *nfc_alloc_recv_skb(unsigned int size, gfp_t gfp)
{ {
struct sk_buff *skb; struct sk_buff *skb;
unsigned int total_size; unsigned int total_size;
...@@ -293,7 +317,7 @@ struct sk_buff *nfc_alloc_skb(unsigned int size, gfp_t gfp) ...@@ -293,7 +317,7 @@ struct sk_buff *nfc_alloc_skb(unsigned int size, gfp_t gfp)
return skb; return skb;
} }
EXPORT_SYMBOL(nfc_alloc_skb); EXPORT_SYMBOL(nfc_alloc_recv_skb);
/** /**
* nfc_targets_found - inform that targets were found * nfc_targets_found - inform that targets were found
......
...@@ -208,13 +208,10 @@ static int rawsock_sendmsg(struct kiocb *iocb, struct socket *sock, ...@@ -208,13 +208,10 @@ static int rawsock_sendmsg(struct kiocb *iocb, struct socket *sock,
if (sock->state != SS_CONNECTED) if (sock->state != SS_CONNECTED)
return -ENOTCONN; return -ENOTCONN;
skb = sock_alloc_send_skb(sk, len + dev->tx_headroom + dev->tx_tailroom + NFC_HEADER_SIZE, skb = nfc_alloc_send_skb(dev, sk, msg->msg_flags, len, &rc);
msg->msg_flags & MSG_DONTWAIT, &rc); if (skb == NULL)
if (!skb)
return rc; return rc;
skb_reserve(skb, dev->tx_headroom + NFC_HEADER_SIZE);
rc = memcpy_fromiovec(skb_put(skb, len), msg->msg_iov, len); rc = memcpy_fromiovec(skb_put(skb, len), msg->msg_iov, len);
if (rc < 0) { if (rc < 0) {
kfree_skb(skb); kfree_skb(skb);
......
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