diff options
author | Samuel Ortiz <sameo@linux.intel.com> | 2011-12-14 10:43:06 -0500 |
---|---|---|
committer | John W. Linville <linville@tuxdriver.com> | 2011-12-14 14:50:12 -0500 |
commit | 7c7cd3bfec68fee33b30d177df6a6a0c4bbdc59d (patch) | |
tree | 7b7332d63303d30c73b4ecd8a300e84d801baa33 | |
parent | 52858b51b2c779a8f9db32accf774b165522ad81 (diff) |
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: Samuel Ortiz <sameo@linux.intel.com>
Signed-off-by: John W. Linville <linville@tuxdriver.com>
-rw-r--r-- | drivers/nfc/pn533.c | 2 | ||||
-rw-r--r-- | include/net/nfc/nfc.h | 5 | ||||
-rw-r--r-- | net/nfc/core.c | 30 | ||||
-rw-r--r-- | net/nfc/rawsock.c | 7 |
4 files changed, 34 insertions, 10 deletions
diff --git a/drivers/nfc/pn533.c b/drivers/nfc/pn533.c index dbf214ef7321..ea1caaeed13c 100644 --- a/drivers/nfc/pn533.c +++ b/drivers/nfc/pn533.c | |||
@@ -1368,7 +1368,7 @@ static int pn533_data_exchange(struct nfc_dev *nfc_dev, u32 target_idx, | |||
1368 | PN533_CMD_DATAEXCH_DATA_MAXLEN + | 1368 | PN533_CMD_DATAEXCH_DATA_MAXLEN + |
1369 | PN533_FRAME_TAIL_SIZE; | 1369 | PN533_FRAME_TAIL_SIZE; |
1370 | 1370 | ||
1371 | skb_resp = nfc_alloc_skb(skb_resp_len, GFP_KERNEL); | 1371 | skb_resp = nfc_alloc_recv_skb(skb_resp_len, GFP_KERNEL); |
1372 | if (!skb_resp) { | 1372 | if (!skb_resp) { |
1373 | rc = -ENOMEM; | 1373 | rc = -ENOMEM; |
1374 | goto error; | 1374 | goto error; |
diff --git a/include/net/nfc/nfc.h b/include/net/nfc/nfc.h index 6a7f602aa841..3a3304c094d7 100644 --- a/include/net/nfc/nfc.h +++ b/include/net/nfc/nfc.h | |||
@@ -157,7 +157,10 @@ static inline const char *nfc_device_name(struct nfc_dev *dev) | |||
157 | return dev_name(&dev->dev); | 157 | return dev_name(&dev->dev); |
158 | } | 158 | } |
159 | 159 | ||
160 | struct sk_buff *nfc_alloc_skb(unsigned int size, gfp_t gfp); | 160 | struct sk_buff *nfc_alloc_send_skb(struct nfc_dev *dev, struct sock *sk, |
161 | unsigned int flags, unsigned int size, | ||
162 | unsigned int *err); | ||
163 | struct sk_buff *nfc_alloc_recv_skb(unsigned int size, gfp_t gfp); | ||
161 | 164 | ||
162 | int nfc_targets_found(struct nfc_dev *dev, struct nfc_target *targets, | 165 | int nfc_targets_found(struct nfc_dev *dev, struct nfc_target *targets, |
163 | int ntargets); | 166 | int ntargets); |
diff --git a/net/nfc/core.c b/net/nfc/core.c index 2a838b099d82..f53f88ada687 100644 --- a/net/nfc/core.c +++ b/net/nfc/core.c | |||
@@ -27,6 +27,7 @@ | |||
27 | #include <linux/kernel.h> | 27 | #include <linux/kernel.h> |
28 | #include <linux/module.h> | 28 | #include <linux/module.h> |
29 | #include <linux/slab.h> | 29 | #include <linux/slab.h> |
30 | #include <linux/nfc.h> | ||
30 | 31 | ||
31 | #include "nfc.h" | 32 | #include "nfc.h" |
32 | 33 | ||
@@ -275,12 +276,35 @@ error: | |||
275 | } | 276 | } |
276 | 277 | ||
277 | /** | 278 | /** |
278 | * nfc_alloc_skb - allocate a skb for data exchange responses | 279 | * nfc_alloc_send_skb - allocate a skb for data exchange responses |
279 | * | 280 | * |
280 | * @size: size to allocate | 281 | * @size: size to allocate |
281 | * @gfp: gfp flags | 282 | * @gfp: gfp flags |
282 | */ | 283 | */ |
283 | struct sk_buff *nfc_alloc_skb(unsigned int size, gfp_t gfp) | 284 | struct sk_buff *nfc_alloc_send_skb(struct nfc_dev *dev, struct sock *sk, |
285 | unsigned int flags, unsigned int size, | ||
286 | unsigned int *err) | ||
287 | { | ||
288 | struct sk_buff *skb; | ||
289 | unsigned int total_size; | ||
290 | |||
291 | total_size = size + | ||
292 | dev->tx_headroom + dev->tx_tailroom + NFC_HEADER_SIZE; | ||
293 | |||
294 | skb = sock_alloc_send_skb(sk, total_size, flags & MSG_DONTWAIT, err); | ||
295 | if (skb) | ||
296 | skb_reserve(skb, dev->tx_headroom + NFC_HEADER_SIZE); | ||
297 | |||
298 | return skb; | ||
299 | } | ||
300 | |||
301 | /** | ||
302 | * nfc_alloc_recv_skb - allocate a skb for data exchange responses | ||
303 | * | ||
304 | * @size: size to allocate | ||
305 | * @gfp: gfp flags | ||
306 | */ | ||
307 | struct sk_buff *nfc_alloc_recv_skb(unsigned int size, gfp_t gfp) | ||
284 | { | 308 | { |
285 | struct sk_buff *skb; | 309 | struct sk_buff *skb; |
286 | unsigned int total_size; | 310 | unsigned int total_size; |
@@ -293,7 +317,7 @@ struct sk_buff *nfc_alloc_skb(unsigned int size, gfp_t gfp) | |||
293 | 317 | ||
294 | return skb; | 318 | return skb; |
295 | } | 319 | } |
296 | EXPORT_SYMBOL(nfc_alloc_skb); | 320 | EXPORT_SYMBOL(nfc_alloc_recv_skb); |
297 | 321 | ||
298 | /** | 322 | /** |
299 | * nfc_targets_found - inform that targets were found | 323 | * nfc_targets_found - inform that targets were found |
diff --git a/net/nfc/rawsock.c b/net/nfc/rawsock.c index 5e9b991eac13..11ac0a17156e 100644 --- a/net/nfc/rawsock.c +++ b/net/nfc/rawsock.c | |||
@@ -208,13 +208,10 @@ static int rawsock_sendmsg(struct kiocb *iocb, struct socket *sock, | |||
208 | if (sock->state != SS_CONNECTED) | 208 | if (sock->state != SS_CONNECTED) |
209 | return -ENOTCONN; | 209 | return -ENOTCONN; |
210 | 210 | ||
211 | skb = sock_alloc_send_skb(sk, len + dev->tx_headroom + dev->tx_tailroom + NFC_HEADER_SIZE, | 211 | skb = nfc_alloc_send_skb(dev, sk, msg->msg_flags, len, &rc); |
212 | msg->msg_flags & MSG_DONTWAIT, &rc); | 212 | if (skb == NULL) |
213 | if (!skb) | ||
214 | return rc; | 213 | return rc; |
215 | 214 | ||
216 | skb_reserve(skb, dev->tx_headroom + NFC_HEADER_SIZE); | ||
217 | |||
218 | rc = memcpy_fromiovec(skb_put(skb, len), msg->msg_iov, len); | 215 | rc = memcpy_fromiovec(skb_put(skb, len), msg->msg_iov, len); |
219 | if (rc < 0) { | 216 | if (rc < 0) { |
220 | kfree_skb(skb); | 217 | kfree_skb(skb); |