mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: DM <dm.n9107@gmail.com>
To: "Daniel Drake" <dsd@gentoo.org>
Cc: linux-kernel@vger.kernel.org
Subject: Re: [RFC v2] Documentation about unaligned memory access
Date: Fri, 30 Nov 2007 08:58:28 +0100	[thread overview]
Message-ID: <5eeb9ad90711292358q2e8cf5few8d9c1b99195e1ee@mail.gmail.com> (raw)
In-Reply-To: <20071129161523.E0C349D4B52@zog.reactivated.net>

On Nov 29, 2007 5:15 PM, Daniel Drake <dsd@gentoo.org> wrote:
[...]
> To avoid the unaligned memory access, you would rewrite it as follows:
>
>        void myfunc(u8 *data, u32 value)
>        {
>                [...]
>                value = cpu_to_le32(value);
>                put_unaligned(value, data);
>                [...]
>        }
>
> The get_unaligned() macro works similarly. Assuming 'data' is a pointer to
> memory and you wish to avoid unaligned access, its usage is as follows:
>
>        u32 value = get_unaligned(data);
>
> These macros work work for memory accesses of any length (not just 32 bits as
> in the examples above). Be aware that when compared to standard access of
> aligned memory, using these macros to access unaligned memory can be costy in
> terms of performance.
>

The get_unaligned call above will not do what you intended given the,
at least as I read it, implied context of myfunc. Since data is a u8*
it will only get one byte of data. To avoid misunderstandings the code
should probably read:

u32 value = get_unaligned((u32 *)data);

/DM

  parent reply	other threads:[~2007-11-30  7:58 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-11-29 16:15 Daniel Drake
2007-11-29 17:04 ` Kyle McMartin
2007-11-29 18:00   ` Jan Engelhardt
2007-11-29 17:44 ` Randy Dunlap
2007-11-30  7:58 ` DM [this message]
2007-12-03  9:26 ` Johannes Berg
2007-12-05 11:41 ` Jan Kara

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=5eeb9ad90711292358q2e8cf5few8d9c1b99195e1ee@mail.gmail.com \
    --to=dm.n9107@gmail.com \
    --cc=dsd@gentoo.org \
    --cc=linux-kernel@vger.kernel.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®