Commit 96545aeb7b4457594d764af4d689a738e97f14b8

Authored by Changli Gao
Committed by David S. Miller
1 parent d7b92affba

net: ppp: use {get,put}_unaligned_be{16,32}

Signed-off-by: Changli Gao <xiaosuo@gmail.com>
Reviewed-by: Harvey Harrison <harvey.harrison@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>

Showing 5 changed files with 18 additions and 20 deletions Side-by-side Diff

drivers/net/ppp_async.c
... ... @@ -32,6 +32,7 @@
32 32 #include <linux/init.h>
33 33 #include <linux/jiffies.h>
34 34 #include <linux/slab.h>
  35 +#include <asm/unaligned.h>
35 36 #include <asm/uaccess.h>
36 37 #include <asm/string.h>
37 38  
... ... @@ -542,7 +543,7 @@
542 543 data = ap->tpkt->data;
543 544 count = ap->tpkt->len;
544 545 fcs = ap->tfcs;
545   - proto = (data[0] << 8) + data[1];
  546 + proto = get_unaligned_be16(data);
546 547  
547 548 /*
548 549 * LCP packets with code values between 1 (configure-reqest)
... ... @@ -963,7 +964,7 @@
963 964 code = data[0];
964 965 if (code != CONFACK && code != CONFREQ)
965 966 return;
966   - dlen = (data[2] << 8) + data[3];
  967 + dlen = get_unaligned_be16(data + 2);
967 968 if (len < dlen)
968 969 return; /* packet got truncated or length is bogus */
969 970  
970 971  
... ... @@ -997,15 +998,14 @@
997 998 while (dlen >= 2 && dlen >= data[1] && data[1] >= 2) {
998 999 switch (data[0]) {
999 1000 case LCP_MRU:
1000   - val = (data[2] << 8) + data[3];
  1001 + val = get_unaligned_be16(data + 2);
1001 1002 if (inbound)
1002 1003 ap->mru = val;
1003 1004 else
1004 1005 ap->chan.mtu = val;
1005 1006 break;
1006 1007 case LCP_ASYNCMAP:
1007   - val = (data[2] << 24) + (data[3] << 16)
1008   - + (data[4] << 8) + data[5];
  1008 + val = get_unaligned_be32(data + 2);
1009 1009 if (inbound)
1010 1010 ap->raccm = val;
1011 1011 else
drivers/net/ppp_deflate.c
... ... @@ -41,6 +41,7 @@
41 41 #include <linux/ppp-comp.h>
42 42  
43 43 #include <linux/zlib.h>
  44 +#include <asm/unaligned.h>
44 45  
45 46 /*
46 47 * State for a Deflate (de)compressor.
47 48  
... ... @@ -232,11 +233,9 @@
232 233 */
233 234 wptr[0] = PPP_ADDRESS(rptr);
234 235 wptr[1] = PPP_CONTROL(rptr);
235   - wptr[2] = PPP_COMP >> 8;
236   - wptr[3] = PPP_COMP;
  236 + put_unaligned_be16(PPP_COMP, wptr + 2);
237 237 wptr += PPP_HDRLEN;
238   - wptr[0] = state->seqno >> 8;
239   - wptr[1] = state->seqno;
  238 + put_unaligned_be16(state->seqno, wptr);
240 239 wptr += DEFLATE_OVHD;
241 240 olen = PPP_HDRLEN + DEFLATE_OVHD;
242 241 state->strm.next_out = wptr;
... ... @@ -451,7 +450,7 @@
451 450 }
452 451  
453 452 /* Check the sequence number. */
454   - seq = (ibuf[PPP_HDRLEN] << 8) + ibuf[PPP_HDRLEN+1];
  453 + seq = get_unaligned_be16(ibuf + PPP_HDRLEN);
455 454 if (seq != (state->seqno & 0xffff)) {
456 455 if (state->debug)
457 456 printk(KERN_DEBUG "z_decompress%d: bad seq # %d, expected %d\n",
drivers/net/ppp_generic.c
... ... @@ -46,6 +46,7 @@
46 46 #include <linux/device.h>
47 47 #include <linux/mutex.h>
48 48 #include <linux/slab.h>
  49 +#include <asm/unaligned.h>
49 50 #include <net/slhc_vj.h>
50 51 #include <asm/atomic.h>
51 52  
... ... @@ -210,7 +211,7 @@
210 211 };
211 212  
212 213 /* Get the PPP protocol number from a skb */
213   -#define PPP_PROTO(skb) (((skb)->data[0] << 8) + (skb)->data[1])
  214 +#define PPP_PROTO(skb) get_unaligned_be16((skb)->data)
214 215  
215 216 /* We limit the length of ppp->file.rq to this (arbitrary) value */
216 217 #define PPP_MAX_RQLEN 32
... ... @@ -964,8 +965,7 @@
964 965  
965 966 pp = skb_push(skb, 2);
966 967 proto = npindex_to_proto[npi];
967   - pp[0] = proto >> 8;
968   - pp[1] = proto;
  968 + put_unaligned_be16(proto, pp);
969 969  
970 970 netif_stop_queue(dev);
971 971 skb_queue_tail(&ppp->file.xq, skb);
... ... @@ -1473,8 +1473,7 @@
1473 1473 q = skb_put(frag, flen + hdrlen);
1474 1474  
1475 1475 /* make the MP header */
1476   - q[0] = PPP_MP >> 8;
1477   - q[1] = PPP_MP;
  1476 + put_unaligned_be16(PPP_MP, q);
1478 1477 if (ppp->flags & SC_MP_XSHORTSEQ) {
1479 1478 q[2] = bits + ((ppp->nxseq >> 8) & 0xf);
1480 1479 q[3] = ppp->nxseq;
drivers/net/ppp_mppe.c
... ... @@ -55,6 +55,7 @@
55 55 #include <linux/ppp_defs.h>
56 56 #include <linux/ppp-comp.h>
57 57 #include <linux/scatterlist.h>
  58 +#include <asm/unaligned.h>
58 59  
59 60 #include "ppp_mppe.h"
60 61  
61 62  
... ... @@ -395,16 +396,14 @@
395 396 */
396 397 obuf[0] = PPP_ADDRESS(ibuf);
397 398 obuf[1] = PPP_CONTROL(ibuf);
398   - obuf[2] = PPP_COMP >> 8; /* isize + MPPE_OVHD + 1 */
399   - obuf[3] = PPP_COMP; /* isize + MPPE_OVHD + 2 */
  399 + put_unaligned_be16(PPP_COMP, obuf + 2);
400 400 obuf += PPP_HDRLEN;
401 401  
402 402 state->ccount = (state->ccount + 1) % MPPE_CCOUNT_SPACE;
403 403 if (state->debug >= 7)
404 404 printk(KERN_DEBUG "mppe_compress[%d]: ccount %d\n", state->unit,
405 405 state->ccount);
406   - obuf[0] = state->ccount >> 8;
407   - obuf[1] = state->ccount & 0xff;
  406 + put_unaligned_be16(state->ccount, obuf);
408 407  
409 408 if (!state->stateful || /* stateless mode */
410 409 ((state->ccount & 0xff) == 0xff) || /* "flag" packet */
drivers/net/ppp_synctty.c
... ... @@ -45,6 +45,7 @@
45 45 #include <linux/completion.h>
46 46 #include <linux/init.h>
47 47 #include <linux/slab.h>
  48 +#include <asm/unaligned.h>
48 49 #include <asm/uaccess.h>
49 50  
50 51 #define PPP_VERSION "2.4.2"
... ... @@ -563,7 +564,7 @@
563 564 int islcp;
564 565  
565 566 data = skb->data;
566   - proto = (data[0] << 8) + data[1];
  567 + proto = get_unaligned_be16(data);
567 568  
568 569 /* LCP packets with codes between 1 (configure-request)
569 570 * and 7 (code-reject) must be sent as though no options