lists.openwall.net | lists / announce owl-users owl-dev john-users john-dev passwdqc-users yescrypt popa3d-users / oss-security kernel-hardening musl sabotage tlsify passwords / crypt-dev xvendor / Bugtraq Full-Disclosure linux-kernel linux-netdev linux-ext4 linux-hardening linux-cve-announce PHC | |
Open Source and information security mailing list archives
| ||
|
Date: Fri, 30 Nov 2007 08:58:28 +0100 From: DM <dm.n9107@...il.com> To: "Daniel Drake" <dsd@...too.org> Cc: linux-kernel@...r.kernel.org Subject: Re: [RFC v2] Documentation about unaligned memory access On Nov 29, 2007 5:15 PM, Daniel Drake <dsd@...too.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 - To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@...r.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists