diff options
Diffstat (limited to 'net/caif/cfpkt_skbuff.c')
-rw-r--r-- | net/caif/cfpkt_skbuff.c | 48 |
1 files changed, 24 insertions, 24 deletions
diff --git a/net/caif/cfpkt_skbuff.c b/net/caif/cfpkt_skbuff.c index c49a6695793a..d7e865e2ff65 100644 --- a/net/caif/cfpkt_skbuff.c +++ b/net/caif/cfpkt_skbuff.c | |||
@@ -4,6 +4,8 @@ | |||
4 | * License terms: GNU General Public License (GPL) version 2 | 4 | * License terms: GNU General Public License (GPL) version 2 |
5 | */ | 5 | */ |
6 | 6 | ||
7 | #define pr_fmt(fmt) KBUILD_MODNAME ":%s(): " fmt, __func__ | ||
8 | |||
7 | #include <linux/string.h> | 9 | #include <linux/string.h> |
8 | #include <linux/skbuff.h> | 10 | #include <linux/skbuff.h> |
9 | #include <linux/hardirq.h> | 11 | #include <linux/hardirq.h> |
@@ -12,11 +14,12 @@ | |||
12 | #define PKT_PREFIX 48 | 14 | #define PKT_PREFIX 48 |
13 | #define PKT_POSTFIX 2 | 15 | #define PKT_POSTFIX 2 |
14 | #define PKT_LEN_WHEN_EXTENDING 128 | 16 | #define PKT_LEN_WHEN_EXTENDING 128 |
15 | #define PKT_ERROR(pkt, errmsg) do { \ | 17 | #define PKT_ERROR(pkt, errmsg) \ |
16 | cfpkt_priv(pkt)->erronous = true; \ | 18 | do { \ |
17 | skb_reset_tail_pointer(&pkt->skb); \ | 19 | cfpkt_priv(pkt)->erronous = true; \ |
18 | pr_warning("CAIF: " errmsg);\ | 20 | skb_reset_tail_pointer(&pkt->skb); \ |
19 | } while (0) | 21 | pr_warn(errmsg); \ |
22 | } while (0) | ||
20 | 23 | ||
21 | struct cfpktq { | 24 | struct cfpktq { |
22 | struct sk_buff_head head; | 25 | struct sk_buff_head head; |
@@ -130,13 +133,13 @@ int cfpkt_extr_head(struct cfpkt *pkt, void *data, u16 len) | |||
130 | return -EPROTO; | 133 | return -EPROTO; |
131 | 134 | ||
132 | if (unlikely(len > skb->len)) { | 135 | if (unlikely(len > skb->len)) { |
133 | PKT_ERROR(pkt, "cfpkt_extr_head read beyond end of packet\n"); | 136 | PKT_ERROR(pkt, "read beyond end of packet\n"); |
134 | return -EPROTO; | 137 | return -EPROTO; |
135 | } | 138 | } |
136 | 139 | ||
137 | if (unlikely(len > skb_headlen(skb))) { | 140 | if (unlikely(len > skb_headlen(skb))) { |
138 | if (unlikely(skb_linearize(skb) != 0)) { | 141 | if (unlikely(skb_linearize(skb) != 0)) { |
139 | PKT_ERROR(pkt, "cfpkt_extr_head linearize failed\n"); | 142 | PKT_ERROR(pkt, "linearize failed\n"); |
140 | return -EPROTO; | 143 | return -EPROTO; |
141 | } | 144 | } |
142 | } | 145 | } |
@@ -156,11 +159,11 @@ int cfpkt_extr_trail(struct cfpkt *pkt, void *dta, u16 len) | |||
156 | return -EPROTO; | 159 | return -EPROTO; |
157 | 160 | ||
158 | if (unlikely(skb_linearize(skb) != 0)) { | 161 | if (unlikely(skb_linearize(skb) != 0)) { |
159 | PKT_ERROR(pkt, "cfpkt_extr_trail linearize failed\n"); | 162 | PKT_ERROR(pkt, "linearize failed\n"); |
160 | return -EPROTO; | 163 | return -EPROTO; |
161 | } | 164 | } |
162 | if (unlikely(skb->data + len > skb_tail_pointer(skb))) { | 165 | if (unlikely(skb->data + len > skb_tail_pointer(skb))) { |
163 | PKT_ERROR(pkt, "cfpkt_extr_trail read beyond end of packet\n"); | 166 | PKT_ERROR(pkt, "read beyond end of packet\n"); |
164 | return -EPROTO; | 167 | return -EPROTO; |
165 | } | 168 | } |
166 | from = skb_tail_pointer(skb) - len; | 169 | from = skb_tail_pointer(skb) - len; |
@@ -202,7 +205,7 @@ int cfpkt_add_body(struct cfpkt *pkt, const void *data, u16 len) | |||
202 | 205 | ||
203 | /* Make sure data is writable */ | 206 | /* Make sure data is writable */ |
204 | if (unlikely(skb_cow_data(skb, addlen, &lastskb) < 0)) { | 207 | if (unlikely(skb_cow_data(skb, addlen, &lastskb) < 0)) { |
205 | PKT_ERROR(pkt, "cfpkt_add_body: cow failed\n"); | 208 | PKT_ERROR(pkt, "cow failed\n"); |
206 | return -EPROTO; | 209 | return -EPROTO; |
207 | } | 210 | } |
208 | /* | 211 | /* |
@@ -211,8 +214,7 @@ int cfpkt_add_body(struct cfpkt *pkt, const void *data, u16 len) | |||
211 | * lengths of the top SKB. | 214 | * lengths of the top SKB. |
212 | */ | 215 | */ |
213 | if (lastskb != skb) { | 216 | if (lastskb != skb) { |
214 | pr_warning("CAIF: %s(): Packet is non-linear\n", | 217 | pr_warn("Packet is non-linear\n"); |
215 | __func__); | ||
216 | skb->len += len; | 218 | skb->len += len; |
217 | skb->data_len += len; | 219 | skb->data_len += len; |
218 | } | 220 | } |
@@ -242,14 +244,14 @@ int cfpkt_add_head(struct cfpkt *pkt, const void *data2, u16 len) | |||
242 | if (unlikely(is_erronous(pkt))) | 244 | if (unlikely(is_erronous(pkt))) |
243 | return -EPROTO; | 245 | return -EPROTO; |
244 | if (unlikely(skb_headroom(skb) < len)) { | 246 | if (unlikely(skb_headroom(skb) < len)) { |
245 | PKT_ERROR(pkt, "cfpkt_add_head: no headroom\n"); | 247 | PKT_ERROR(pkt, "no headroom\n"); |
246 | return -EPROTO; | 248 | return -EPROTO; |
247 | } | 249 | } |
248 | 250 | ||
249 | /* Make sure data is writable */ | 251 | /* Make sure data is writable */ |
250 | ret = skb_cow_data(skb, 0, &lastskb); | 252 | ret = skb_cow_data(skb, 0, &lastskb); |
251 | if (unlikely(ret < 0)) { | 253 | if (unlikely(ret < 0)) { |
252 | PKT_ERROR(pkt, "cfpkt_add_head: cow failed\n"); | 254 | PKT_ERROR(pkt, "cow failed\n"); |
253 | return ret; | 255 | return ret; |
254 | } | 256 | } |
255 | 257 | ||
@@ -283,7 +285,7 @@ inline u16 cfpkt_iterate(struct cfpkt *pkt, | |||
283 | if (unlikely(is_erronous(pkt))) | 285 | if (unlikely(is_erronous(pkt))) |
284 | return -EPROTO; | 286 | return -EPROTO; |
285 | if (unlikely(skb_linearize(&pkt->skb) != 0)) { | 287 | if (unlikely(skb_linearize(&pkt->skb) != 0)) { |
286 | PKT_ERROR(pkt, "cfpkt_iterate: linearize failed\n"); | 288 | PKT_ERROR(pkt, "linearize failed\n"); |
287 | return -EPROTO; | 289 | return -EPROTO; |
288 | } | 290 | } |
289 | return iter_func(data, pkt->skb.data, cfpkt_getlen(pkt)); | 291 | return iter_func(data, pkt->skb.data, cfpkt_getlen(pkt)); |
@@ -309,7 +311,7 @@ int cfpkt_setlen(struct cfpkt *pkt, u16 len) | |||
309 | 311 | ||
310 | /* Need to expand SKB */ | 312 | /* Need to expand SKB */ |
311 | if (unlikely(!cfpkt_pad_trail(pkt, len - skb->len))) | 313 | if (unlikely(!cfpkt_pad_trail(pkt, len - skb->len))) |
312 | PKT_ERROR(pkt, "cfpkt_setlen: skb_pad_trail failed\n"); | 314 | PKT_ERROR(pkt, "skb_pad_trail failed\n"); |
313 | 315 | ||
314 | return cfpkt_getlen(pkt); | 316 | return cfpkt_getlen(pkt); |
315 | } | 317 | } |
@@ -380,8 +382,7 @@ struct cfpkt *cfpkt_split(struct cfpkt *pkt, u16 pos) | |||
380 | return NULL; | 382 | return NULL; |
381 | 383 | ||
382 | if (skb->data + pos > skb_tail_pointer(skb)) { | 384 | if (skb->data + pos > skb_tail_pointer(skb)) { |
383 | PKT_ERROR(pkt, | 385 | PKT_ERROR(pkt, "trying to split beyond end of packet\n"); |
384 | "cfpkt_split: trying to split beyond end of packet"); | ||
385 | return NULL; | 386 | return NULL; |
386 | } | 387 | } |
387 | 388 | ||
@@ -455,17 +456,17 @@ int cfpkt_raw_append(struct cfpkt *pkt, void **buf, unsigned int buflen) | |||
455 | return -EPROTO; | 456 | return -EPROTO; |
456 | /* Make sure SKB is writable */ | 457 | /* Make sure SKB is writable */ |
457 | if (unlikely(skb_cow_data(skb, 0, &lastskb) < 0)) { | 458 | if (unlikely(skb_cow_data(skb, 0, &lastskb) < 0)) { |
458 | PKT_ERROR(pkt, "cfpkt_raw_append: skb_cow_data failed\n"); | 459 | PKT_ERROR(pkt, "skb_cow_data failed\n"); |
459 | return -EPROTO; | 460 | return -EPROTO; |
460 | } | 461 | } |
461 | 462 | ||
462 | if (unlikely(skb_linearize(skb) != 0)) { | 463 | if (unlikely(skb_linearize(skb) != 0)) { |
463 | PKT_ERROR(pkt, "cfpkt_raw_append: linearize failed\n"); | 464 | PKT_ERROR(pkt, "linearize failed\n"); |
464 | return -EPROTO; | 465 | return -EPROTO; |
465 | } | 466 | } |
466 | 467 | ||
467 | if (unlikely(skb_tailroom(skb) < buflen)) { | 468 | if (unlikely(skb_tailroom(skb) < buflen)) { |
468 | PKT_ERROR(pkt, "cfpkt_raw_append: buffer too short - failed\n"); | 469 | PKT_ERROR(pkt, "buffer too short - failed\n"); |
469 | return -EPROTO; | 470 | return -EPROTO; |
470 | } | 471 | } |
471 | 472 | ||
@@ -483,14 +484,13 @@ int cfpkt_raw_extract(struct cfpkt *pkt, void **buf, unsigned int buflen) | |||
483 | return -EPROTO; | 484 | return -EPROTO; |
484 | 485 | ||
485 | if (unlikely(buflen > skb->len)) { | 486 | if (unlikely(buflen > skb->len)) { |
486 | PKT_ERROR(pkt, "cfpkt_raw_extract: buflen too large " | 487 | PKT_ERROR(pkt, "buflen too large - failed\n"); |
487 | "- failed\n"); | ||
488 | return -EPROTO; | 488 | return -EPROTO; |
489 | } | 489 | } |
490 | 490 | ||
491 | if (unlikely(buflen > skb_headlen(skb))) { | 491 | if (unlikely(buflen > skb_headlen(skb))) { |
492 | if (unlikely(skb_linearize(skb) != 0)) { | 492 | if (unlikely(skb_linearize(skb) != 0)) { |
493 | PKT_ERROR(pkt, "cfpkt_raw_extract: linearize failed\n"); | 493 | PKT_ERROR(pkt, "linearize failed\n"); |
494 | return -EPROTO; | 494 | return -EPROTO; |
495 | } | 495 | } |
496 | } | 496 | } |