Re: [PATCH] drivers/net/slip: prevent data alignment fault

William Tambe <[email protected]>
Newsgroups gmane.linux.ppp
Message-ID <CAF8i9mO24ByRSjNR6N0ym-LU30z-NTfiw=Q_+Dvx6L6baEq0HQ@mail.gmail.com>
Thanks, sending v2 of the patch that uses put_unaligned() here, and
get_unaligned().

William

On Mon, Oct 2, 2023 at 1:31 AM Paul Mackerras <[email protected]> wrote:
>
> On Sun, Oct 01, 2023 at 09:45:57PM -0500, William Tambe wrote:
> > >From 594e53fa4913b1cb6232dbcc73d905a94c0cae73 Mon Sep 17 00:00:00 2001
> > From: William Tambe <[email protected]>
> > Date: Sun, 1 Oct 2023 21:38:15 -0500
> > Subject: [PATCH] drivers/net/slip: prevent data alignment fault
> >
> > Prevent data alignment fault on architectures which cannot
> > do unaligned memory access.
> > ---
> >  drivers/net/slip/slhc.c | 6 +++---
> >  1 file changed, 3 insertions(+), 3 deletions(-)
> >
> > diff --git a/drivers/net/slip/slhc.c b/drivers/net/slip/slhc.c
> > index ba93bab948e0..08fd570a6d40 100644
> > --- a/drivers/net/slip/slhc.c
> > +++ b/drivers/net/slip/slhc.c
> > @@ -459,8 +459,8 @@ slhc_compress(struct slcompress *comp, unsigned
> > char *icp, int isize,
> >          *cpp = ocp;
> >          *cp++ = changes;
> >      }
> > -    *(__sum16 *)cp = csum;
> > -    cp += 2;
> > +    *cp++ = (char)(csum&0xff);
> > +    *cp++ = (char)((csum>>8)&0xff);
>
> You just changed the meaning of the code on big-endian machines.
>
> I think it would be better to use put_unaligned() here, and
> get_unaligned() below.
>
> >  /* deltaS is now the size of the change section of the compressed header */
> >      memcpy(cp,new_seq,deltaS);    /* Write list of deltas */
> >      memcpy(cp+deltaS,icp+hlen,isize-hlen);
> > @@ -534,7 +534,7 @@ slhc_uncompress(struct slcompress *comp, unsigned
> > char *icp, int isize)
> >      thp = &cs->cs_tcp;
> >      ip = &cs->cs_ip;
> >
> > -    thp->check = *(__sum16 *)cp;
> > +    thp->check = (((__sum16)*cp)|(((__sum16)*(cp+1))<<8));
> >      cp += 2;
> >
> >      thp->psh = (changes & TCP_PUSH_BIT) ? 1 : 0;
> > --
> > 2.34.1
>
> Paul.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.