mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Luke Yang" <luke.adi@gmail.com>
To: "Andrew Morton" <akpm@osdl.org>
Cc: samuel@sortiz.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] Fix an inproper alignment accessing in irda protocol stack
Date: Fri, 9 Jun 2006 11:45:06 +0800	[thread overview]
Message-ID: <489ecd0c0606082045w7456a90et586a3954f1a2fca0@mail.gmail.com> (raw)
In-Reply-To: <20060608003015.52fe1b8e.akpm@osdl.org>

[-- Attachment #1: Type: text/plain, Size: 2586 bytes --]

Hi Andrew,

   Thanks. I modified the patch (don't know if there is any way better
to solve this).

Signed-off-by: Luke Yang <luke.adi@gmail.com>

 irlmp.c |    8 +++++++-
 1 files changed, 7 insertions(+), 1 deletion(-)

--- net/irda/irlmp.c.old        2006-06-08 14:49:20.000000000 +0800
+++ net/irda/irlmp.c    2006-06-09 19:43:58.000000000 +0800
@@ -849,7 +849,13 @@
        }

        /* Construct new discovery info to be used by IrLAP, */
-       u16ho(irlmp->discovery_cmd.data.hints) = irlmp->hints.word;
+#ifdef __LITTLE_ENDIAN
+       irlmp->discovery_cmd.data.hints[0] = irlmp->hints.word & 0xff;
+       irlmp->discovery_cmd.data.hints[1] = (irlmp->hints.word & 0xff00) >> 8;
+#else /* ifdef __BIG_ENDIAN */
+       irlmp->discovery_cmd.data.hints[0] = (irlmp->hints.word & 0xff00) >> 8;
+       irlmp->discovery_cmd.data.hints[1] = irlmp->hints.word & 0xff;
+#endif

        /*
         *  Set character set for device name (we use ASCII), and

On 6/8/06, Andrew Morton <akpm@osdl.org> wrote:
> On Thu, 8 Jun 2006 15:15:11 +0800
> "Luke Yang" <luke.adi@gmail.com> wrote:
>
> > Hi all,
> >
> >  For "struct irda_device_info" in irda.h:
> > struct irda_device_info {
> >       __u32       saddr;    /* Address of local interface */
> >       __u32       daddr;    /* Address of remote device */
> >       char        info[22]; /* Description */
> >       __u8        charset;  /* Charset used for description */
> >       __u8        hints[2]; /* Hint bits */
> > };
> >    The "hints" member aligns at the third byte of a word, an odd
> > address. So if we visit "hints" as a short in irlmp.c:
> >
> >     u16ho(irlmp->discovery_cmd.data.hints) = irlmp->hints.word;
> >
> >   will cause alignment problem on some machines. Architectures with
> > strict alignment rules do not allow 16-bit read on an odd address.
> >
> > Signed-off-by: Luke Yang <luke.adi@gmail.com>
> >
> >  irlmp.c |    3 ++-
> >  1 files changed, 2 insertions(+), 1 deletion(-)
> >
> > --- net/irda/irlmp.c.old        2006-06-08 14:49:20.000000000 +0800
> > +++ net/irda/irlmp.c    2006-06-08 14:54:29.000000000 +0800
> > @@ -849,7 +849,8 @@
> >         }
> >
> >         /* Construct new discovery info to be used by IrLAP, */
> > -       u16ho(irlmp->discovery_cmd.data.hints) = irlmp->hints.word;
> > +       irlmp->discovery_cmd.data.hints[0] = irlmp->hints.word & 0xff;
> > +       irlmp->discovery_cmd.data.hints[1] = (irlmp->hints.word & 0xff00) >> 8;
>
> This change will have the effect of swapping those two bytes on big-endian
> machines.
>
>


-- 
Best regards,
Luke Yang
luke.adi@gmail.com

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: irlmp_alignment_fixing.patch --]
[-- Type: text/x-patch; name="irlmp_alignment_fixing.patch", Size: 674 bytes --]

--- net/irda/irlmp.c.old	2006-06-08 14:49:20.000000000 +0800
+++ net/irda/irlmp.c	2006-06-09 19:43:58.000000000 +0800
@@ -849,7 +849,13 @@
 	}
 
 	/* Construct new discovery info to be used by IrLAP, */
-	u16ho(irlmp->discovery_cmd.data.hints) = irlmp->hints.word;
+#ifdef __LITTLE_ENDIAN
+	irlmp->discovery_cmd.data.hints[0] = irlmp->hints.word & 0xff;
+	irlmp->discovery_cmd.data.hints[1] = (irlmp->hints.word & 0xff00) >> 8;
+#else /* ifdef __BIG_ENDIAN */
+	irlmp->discovery_cmd.data.hints[0] = (irlmp->hints.word & 0xff00) >> 8;
+	irlmp->discovery_cmd.data.hints[1] = irlmp->hints.word & 0xff;
+#endif
 
 	/*
 	 *  Set character set for device name (we use ASCII), and

  reply	other threads:[~2006-06-09  3:45 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-06-08  7:15 Luke Yang
2006-06-08  7:30 ` Andrew Morton
2006-06-09  3:45   ` Luke Yang [this message]
2006-06-09  5:01     ` David Miller
2006-06-14  2:29 ` Luke Yang
2006-06-14  3:42   ` David Miller
2006-06-18  5:14   ` David Miller
2006-07-11  2:12     ` Luke Yang
2006-07-11  3:29       ` David Miller
2006-07-11  4:19         ` Luke Yang
2006-07-11  4:33           ` David Miller

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=489ecd0c0606082045w7456a90et586a3954f1a2fca0@mail.gmail.com \
    --to=luke.adi@gmail.com \
    --cc=akpm@osdl.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=samuel@sortiz.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®