Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1758205AbYCTRe3 (ORCPT ); Thu, 20 Mar 2008 13:34:29 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1755474AbYCTReT (ORCPT ); Thu, 20 Mar 2008 13:34:19 -0400 Received: from wa-out-1112.google.com ([209.85.146.182]:13745 "EHLO wa-out-1112.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754433AbYCTReS (ORCPT ); Thu, 20 Mar 2008 13:34:18 -0400 DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=subject:from:to:cc:content-type:date:message-id:mime-version:x-mailer:content-transfer-encoding; b=TGJTvfDL1cMZ+Yr3LovCVSWRQC6TieFApVqjR3xvF+XQm7mplnp565TsVlv4+owzcbFZ1U9uNGtEfx7t8XNRX/54iFbAPpmTEIA1A/U3X67bIbqoP13iemuv2FYf68y97A8L4MkaMxcLOzk94jedaE8Az2LBy3I9EcBoqEpnjQw= Subject: [RFC PATCH] kernel: add byteorder macros with alignment fixups From: Harvey Harrison To: Andrew Morton Cc: LKML , linux-netdev Content-Type: text/plain Date: Thu, 20 Mar 2008 10:34:14 -0700 Message-Id: <1206034454.17059.4.camel@brick> Mime-Version: 1.0 X-Mailer: Evolution 2.12.1 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2111 Lines: 64 A common pattern in the kernel (especially networking) is: le32_to_cpu(get_unaligned((__le32 *)x)); Repeat for various combinations of le/be and 64/32/16 bit. Add a variant that operates on possibly unaligned pointers to byteorder/generic.h Signed-off-by: Harvey Harrison --- include/linux/byteorder/generic.h | 16 ++++++++++++++++ 1 files changed, 16 insertions(+), 0 deletions(-) diff --git a/include/linux/byteorder/generic.h b/include/linux/byteorder/generic.h index d377155..9b1a7a4 100644 --- a/include/linux/byteorder/generic.h +++ b/include/linux/byteorder/generic.h @@ -73,6 +73,10 @@ * cpu_to_[bl]eXXp(__uXX x) * [bl]eXX_to_cpup(__uXX x) * + * The same, but takes a possibly unaligned pointer to the value to convert + * cpu_to_[bl]eXXp_un(__uXX x) + * [bl]eXX_to_cpup_un(__uXX x) + * * The same, but change in situ * cpu_to_[bl]eXXs(__uXX x) * [bl]eXX_to_cpus(__uXX x) @@ -84,6 +88,8 @@ #if defined(__KERNEL__) +#include + /* * inside the kernel, we can use nicknames; * outside of it, we must avoid POSIX namespace pollution... @@ -126,6 +132,16 @@ #define be16_to_cpus __be16_to_cpus /* + * Operates on possibly unaligned pointers + */ +#define le64_to_cpup_un(x) __le64_to_cpu(get_unaligned((__le64 *)(x))) +#define le32_to_cpup_un(x) __le32_to_cpu(get_unaligned((__le32 *)(x))) +#define le16_to_cpup_un(x) __le16_to_cpu(get_unaligned((__le16 *)(x))) +#define be64_to_cpup_un(x) __be64_to_cpu(get_unaligned((__be64 *)(x))) +#define be32_to_cpup_un(x) __be32_to_cpu(get_unaligned((__be32 *)(x))) +#define be16_to_cpup_un(x) __be16_to_cpu(get_unaligned((__be16 *)(x))) + +/* * They have to be macros in order to do the constant folding * correctly - if the argument passed into a inline function * it is no longer constant according to gcc.. -- 1.5.4.4.684.g0e08 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/