From: Ping-Ke Shih <pkshih@realtek.com>
To: Johannes Berg <johannes@sipsolutions.net>,
Masashi Honma <masashi.honma@gmail.com>,
"linux-wireless@vger.kernel.org" <linux-wireless@vger.kernel.org>
Subject: RE: [PATCH v6 1/6] wifi: mac80211: Use struct instead of macro for PREQ frame
Date: Thu, 21 May 2026 07:38:13 +0000 [thread overview]
Message-ID: <7e1aac3afd714d448e5bfba4a9a113b0@realtek.com> (raw)
In-Reply-To: <93ab81b4fb7130a4d4e1048581d886568086fe24.camel@sipsolutions.net>
Johannes Berg <johannes@sipsolutions.net> wrote:
> The point is that __packed forces the compiler to emit code that doesn't
> rely on alignment.
I was not aware that __packed is a hint of unalignment to compiler.
I learned. :)
>
> So say e.g. you have
>
> __le32 *ptr = ...;
>
> u32 val = cpu_to_le32(*ptr);
>
> In this case, the compiler can emit a load instruction that assumes
> alignment, so if 'ptr' can be unaligned, we need to use
>
> u32 val = get_unaligned_le32(ptr);
Got it.
With the assignment to pointer, the hint disappeared.
>
> instead.
>
> However, if we have
>
> struct ieee80211_mesh_hwmp_preq_top *ptr = ...;
>
> u32 val = cpu_to_le32(ptr->preq_id);
>
> then the compiler _cannot_ emit a load instruction that assumes
> alignment because of the __packed, and so the compiler has to emit a
> (perhaps sequence of) instruction(s) that load the 32-bit value without
> relying on alignment. As a consequence, we don't have to explicitly
> write it the more complicated way and can just write it the more natural
> way.
I'll remember this is better style in practice. Compiler can help.
In my tests with arm-gcc compiler, I did a special case:
struct foo {
int a;
char b;
} __packed;
int bar(struct foo *foo)
{
return foo->a;
}
It is obviously aligned (offset = 0), so I guessed arm-gcc can generate
a single load instruction, but actually it doesn't (even with -O3).
But this is not the course of this thread. :)
Thank you
Ping-Ke
next prev parent reply other threads:[~2026-05-21 7:38 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-15 23:38 [PATCH v6 1/6] wifi: mac80211: Use struct instead of macro for PREQ frame Masashi Honma
2026-05-15 23:38 ` [PATCH v6 2/6] wifi: mac80211: Use struct instead of macro for PREP frame Masashi Honma
2026-05-15 23:38 ` [PATCH v6 3/6] wifi: mac80211: Use struct instead of macro for PERR frame Masashi Honma
2026-05-15 23:38 ` [PATCH v6 4/6] wifi: mac80211: Fix overread in PREQ frame processing Masashi Honma
2026-05-20 11:15 ` Johannes Berg
2026-05-21 8:55 ` Masashi Honma
2026-05-15 23:38 ` [PATCH v6 5/6] wifi: mac80211: Fix overread in PREP " Masashi Honma
2026-05-20 11:16 ` Johannes Berg
2026-05-21 8:55 ` Masashi Honma
2026-05-15 23:38 ` [PATCH v6 6/6] wifi: mac80211: Fix PERR " Masashi Honma
2026-05-20 11:14 ` [PATCH v6 1/6] wifi: mac80211: Use struct instead of macro for PREQ frame Johannes Berg
2026-05-21 0:42 ` Ping-Ke Shih
2026-05-21 6:24 ` Johannes Berg
2026-05-21 7:38 ` Ping-Ke Shih [this message]
2026-05-21 7:42 ` Johannes Berg
2026-05-21 7:53 ` Ping-Ke Shih
2026-05-21 8:54 ` Masashi Honma
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=7e1aac3afd714d448e5bfba4a9a113b0@realtek.com \
--to=pkshih@realtek.com \
--cc=johannes@sipsolutions.net \
--cc=linux-wireless@vger.kernel.org \
--cc=masashi.honma@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox