All of lore.kernel.org
 help / color / mirror / Atom feed
From: Paul Mackerras <paulus@ozlabs.org>
To: William Tambe <tambewilliam@gmail.com>
Cc: linux-ppp@vger.kernel.org
Subject: Re: [PATCH] drivers/net/slip: prevent data alignment fault
Date: Mon, 2 Oct 2023 17:31:44 +1100	[thread overview]
Message-ID: <ZRpj0LotoVlBRWs7@cleo> (raw)
In-Reply-To: <CAF8i9mO42DbVzPhz9cpaL2frpYUyOcSC7qdx6r6bYxkS+QYrKw@mail.gmail.com>

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 <tambewilliam@gmail.com>
> 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.

  reply	other threads:[~2023-10-02  6:31 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-10-02  2:45 [PATCH] drivers/net/slip: prevent data alignment fault William Tambe
2023-10-02  6:31 ` Paul Mackerras [this message]
2023-10-02 15:24   ` William Tambe
2023-11-13  1:21     ` Willem de Bruijn
  -- strict thread matches above, loose matches on Subject: below --
2023-10-01 22:19 William Tambe
2023-10-02  1:10 ` William Tambe

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ZRpj0LotoVlBRWs7@cleo \
    --to=paulus@ozlabs.org \
    --cc=linux-ppp@vger.kernel.org \
    --cc=tambewilliam@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.