Commit 96545aeb authored by Changli Gao's avatar Changli Gao Committed by David S. Miller

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

Signed-off-by: default avatarChangli Gao <xiaosuo@gmail.com>
Reviewed-by: default avatarHarvey Harrison <harvey.harrison@gmail.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent d7b92aff
...@@ -32,6 +32,7 @@ ...@@ -32,6 +32,7 @@
#include <linux/init.h> #include <linux/init.h>
#include <linux/jiffies.h> #include <linux/jiffies.h>
#include <linux/slab.h> #include <linux/slab.h>
#include <asm/unaligned.h>
#include <asm/uaccess.h> #include <asm/uaccess.h>
#include <asm/string.h> #include <asm/string.h>
...@@ -542,7 +543,7 @@ ppp_async_encode(struct asyncppp *ap) ...@@ -542,7 +543,7 @@ ppp_async_encode(struct asyncppp *ap)
data = ap->tpkt->data; data = ap->tpkt->data;
count = ap->tpkt->len; count = ap->tpkt->len;
fcs = ap->tfcs; fcs = ap->tfcs;
proto = (data[0] << 8) + data[1]; proto = get_unaligned_be16(data);
/* /*
* LCP packets with code values between 1 (configure-reqest) * LCP packets with code values between 1 (configure-reqest)
...@@ -963,7 +964,7 @@ static void async_lcp_peek(struct asyncppp *ap, unsigned char *data, ...@@ -963,7 +964,7 @@ static void async_lcp_peek(struct asyncppp *ap, unsigned char *data,
code = data[0]; code = data[0];
if (code != CONFACK && code != CONFREQ) if (code != CONFACK && code != CONFREQ)
return; return;
dlen = (data[2] << 8) + data[3]; dlen = get_unaligned_be16(data + 2);
if (len < dlen) if (len < dlen)
return; /* packet got truncated or length is bogus */ return; /* packet got truncated or length is bogus */
...@@ -997,15 +998,14 @@ static void async_lcp_peek(struct asyncppp *ap, unsigned char *data, ...@@ -997,15 +998,14 @@ static void async_lcp_peek(struct asyncppp *ap, unsigned char *data,
while (dlen >= 2 && dlen >= data[1] && data[1] >= 2) { while (dlen >= 2 && dlen >= data[1] && data[1] >= 2) {
switch (data[0]) { switch (data[0]) {
case LCP_MRU: case LCP_MRU:
val = (data[2] << 8) + data[3]; val = get_unaligned_be16(data + 2);
if (inbound) if (inbound)
ap->mru = val; ap->mru = val;
else else
ap->chan.mtu = val; ap->chan.mtu = val;
break; break;
case LCP_ASYNCMAP: case LCP_ASYNCMAP:
val = (data[2] << 24) + (data[3] << 16) val = get_unaligned_be32(data + 2);
+ (data[4] << 8) + data[5];
if (inbound) if (inbound)
ap->raccm = val; ap->raccm = val;
else else
......
...@@ -41,6 +41,7 @@ ...@@ -41,6 +41,7 @@
#include <linux/ppp-comp.h> #include <linux/ppp-comp.h>
#include <linux/zlib.h> #include <linux/zlib.h>
#include <asm/unaligned.h>
/* /*
* State for a Deflate (de)compressor. * State for a Deflate (de)compressor.
...@@ -232,11 +233,9 @@ static int z_compress(void *arg, unsigned char *rptr, unsigned char *obuf, ...@@ -232,11 +233,9 @@ static int z_compress(void *arg, unsigned char *rptr, unsigned char *obuf,
*/ */
wptr[0] = PPP_ADDRESS(rptr); wptr[0] = PPP_ADDRESS(rptr);
wptr[1] = PPP_CONTROL(rptr); wptr[1] = PPP_CONTROL(rptr);
wptr[2] = PPP_COMP >> 8; put_unaligned_be16(PPP_COMP, wptr + 2);
wptr[3] = PPP_COMP;
wptr += PPP_HDRLEN; wptr += PPP_HDRLEN;
wptr[0] = state->seqno >> 8; put_unaligned_be16(state->seqno, wptr);
wptr[1] = state->seqno;
wptr += DEFLATE_OVHD; wptr += DEFLATE_OVHD;
olen = PPP_HDRLEN + DEFLATE_OVHD; olen = PPP_HDRLEN + DEFLATE_OVHD;
state->strm.next_out = wptr; state->strm.next_out = wptr;
...@@ -451,7 +450,7 @@ static int z_decompress(void *arg, unsigned char *ibuf, int isize, ...@@ -451,7 +450,7 @@ static int z_decompress(void *arg, unsigned char *ibuf, int isize,
} }
/* Check the sequence number. */ /* Check the sequence number. */
seq = (ibuf[PPP_HDRLEN] << 8) + ibuf[PPP_HDRLEN+1]; seq = get_unaligned_be16(ibuf + PPP_HDRLEN);
if (seq != (state->seqno & 0xffff)) { if (seq != (state->seqno & 0xffff)) {
if (state->debug) if (state->debug)
printk(KERN_DEBUG "z_decompress%d: bad seq # %d, expected %d\n", printk(KERN_DEBUG "z_decompress%d: bad seq # %d, expected %d\n",
......
...@@ -46,6 +46,7 @@ ...@@ -46,6 +46,7 @@
#include <linux/device.h> #include <linux/device.h>
#include <linux/mutex.h> #include <linux/mutex.h>
#include <linux/slab.h> #include <linux/slab.h>
#include <asm/unaligned.h>
#include <net/slhc_vj.h> #include <net/slhc_vj.h>
#include <asm/atomic.h> #include <asm/atomic.h>
...@@ -210,7 +211,7 @@ struct ppp_net { ...@@ -210,7 +211,7 @@ struct ppp_net {
}; };
/* Get the PPP protocol number from a skb */ /* Get the PPP protocol number from a skb */
#define PPP_PROTO(skb) (((skb)->data[0] << 8) + (skb)->data[1]) #define PPP_PROTO(skb) get_unaligned_be16((skb)->data)
/* We limit the length of ppp->file.rq to this (arbitrary) value */ /* We limit the length of ppp->file.rq to this (arbitrary) value */
#define PPP_MAX_RQLEN 32 #define PPP_MAX_RQLEN 32
...@@ -964,8 +965,7 @@ ppp_start_xmit(struct sk_buff *skb, struct net_device *dev) ...@@ -964,8 +965,7 @@ ppp_start_xmit(struct sk_buff *skb, struct net_device *dev)
pp = skb_push(skb, 2); pp = skb_push(skb, 2);
proto = npindex_to_proto[npi]; proto = npindex_to_proto[npi];
pp[0] = proto >> 8; put_unaligned_be16(proto, pp);
pp[1] = proto;
netif_stop_queue(dev); netif_stop_queue(dev);
skb_queue_tail(&ppp->file.xq, skb); skb_queue_tail(&ppp->file.xq, skb);
...@@ -1473,8 +1473,7 @@ static int ppp_mp_explode(struct ppp *ppp, struct sk_buff *skb) ...@@ -1473,8 +1473,7 @@ static int ppp_mp_explode(struct ppp *ppp, struct sk_buff *skb)
q = skb_put(frag, flen + hdrlen); q = skb_put(frag, flen + hdrlen);
/* make the MP header */ /* make the MP header */
q[0] = PPP_MP >> 8; put_unaligned_be16(PPP_MP, q);
q[1] = PPP_MP;
if (ppp->flags & SC_MP_XSHORTSEQ) { if (ppp->flags & SC_MP_XSHORTSEQ) {
q[2] = bits + ((ppp->nxseq >> 8) & 0xf); q[2] = bits + ((ppp->nxseq >> 8) & 0xf);
q[3] = ppp->nxseq; q[3] = ppp->nxseq;
......
...@@ -55,6 +55,7 @@ ...@@ -55,6 +55,7 @@
#include <linux/ppp_defs.h> #include <linux/ppp_defs.h>
#include <linux/ppp-comp.h> #include <linux/ppp-comp.h>
#include <linux/scatterlist.h> #include <linux/scatterlist.h>
#include <asm/unaligned.h>
#include "ppp_mppe.h" #include "ppp_mppe.h"
...@@ -395,16 +396,14 @@ mppe_compress(void *arg, unsigned char *ibuf, unsigned char *obuf, ...@@ -395,16 +396,14 @@ mppe_compress(void *arg, unsigned char *ibuf, unsigned char *obuf,
*/ */
obuf[0] = PPP_ADDRESS(ibuf); obuf[0] = PPP_ADDRESS(ibuf);
obuf[1] = PPP_CONTROL(ibuf); obuf[1] = PPP_CONTROL(ibuf);
obuf[2] = PPP_COMP >> 8; /* isize + MPPE_OVHD + 1 */ put_unaligned_be16(PPP_COMP, obuf + 2);
obuf[3] = PPP_COMP; /* isize + MPPE_OVHD + 2 */
obuf += PPP_HDRLEN; obuf += PPP_HDRLEN;
state->ccount = (state->ccount + 1) % MPPE_CCOUNT_SPACE; state->ccount = (state->ccount + 1) % MPPE_CCOUNT_SPACE;
if (state->debug >= 7) if (state->debug >= 7)
printk(KERN_DEBUG "mppe_compress[%d]: ccount %d\n", state->unit, printk(KERN_DEBUG "mppe_compress[%d]: ccount %d\n", state->unit,
state->ccount); state->ccount);
obuf[0] = state->ccount >> 8; put_unaligned_be16(state->ccount, obuf);
obuf[1] = state->ccount & 0xff;
if (!state->stateful || /* stateless mode */ if (!state->stateful || /* stateless mode */
((state->ccount & 0xff) == 0xff) || /* "flag" packet */ ((state->ccount & 0xff) == 0xff) || /* "flag" packet */
......
...@@ -45,6 +45,7 @@ ...@@ -45,6 +45,7 @@
#include <linux/completion.h> #include <linux/completion.h>
#include <linux/init.h> #include <linux/init.h>
#include <linux/slab.h> #include <linux/slab.h>
#include <asm/unaligned.h>
#include <asm/uaccess.h> #include <asm/uaccess.h>
#define PPP_VERSION "2.4.2" #define PPP_VERSION "2.4.2"
...@@ -563,7 +564,7 @@ ppp_sync_txmunge(struct syncppp *ap, struct sk_buff *skb) ...@@ -563,7 +564,7 @@ ppp_sync_txmunge(struct syncppp *ap, struct sk_buff *skb)
int islcp; int islcp;
data = skb->data; data = skb->data;
proto = (data[0] << 8) + data[1]; proto = get_unaligned_be16(data);
/* LCP packets with codes between 1 (configure-request) /* LCP packets with codes between 1 (configure-request)
* and 7 (code-reject) must be sent as though no options * and 7 (code-reject) must be sent as though no options
......
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