Re: [PATCH RFC 02/13] sunrpc: ntoh -> be*_to_cpu

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Sep. 12, 2009, 17:00 +0300, Al Viro <viro@xxxxxxxxxxxxxxxxxx> wrote:
> On Wed, Aug 12, 2009 at 06:21:48PM +0300, Benny Halevy wrote:
>> ntohl is already defined as be32_to_cpu.
>> be64_to_cpu has architecture specific optimized implementations.
> 
>>  static inline __be32 *
>>  xdr_decode_hyper(__be32 *p, __u64 *valp)
>>  {
>> -	*valp  = ((__u64) ntohl(*p++)) << 32;
>> -	*valp |= ntohl(*p++);
>> -	return p;
>> +	*valp = be64_to_cpup((__be64 *)p);
>> +	return p + 2;
>>  }
> 
> Erm...  Who has promised you that p will be 64bit-aligned?

Good point.
The following should do then, right?

Benny

git diff --stat -p
 include/linux/sunrpc/xdr.h |    5 +++--
 1 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/include/linux/sunrpc/xdr.h b/include/linux/sunrpc/xdr.h
index 7da466b..f5cc089 100644
--- a/include/linux/sunrpc/xdr.h
+++ b/include/linux/sunrpc/xdr.h
@@ -11,6 +11,7 @@
 
 #include <linux/uio.h>
 #include <asm/byteorder.h>
+#include <asm/unaligned.h>
 #include <linux/scatterlist.h>
 
 /*
@@ -117,14 +118,14 @@ static inline __be32 *xdr_encode_array(__be32 *p, const void *s, unsigned int le
 static inline __be32 *
 xdr_encode_hyper(__be32 *p, __u64 val)
 {
-	*(__be64 *)p = cpu_to_be64(val);
+	put_unaligned_be64(val, p);
 	return p + 2;
 }
 
 static inline __be32 *
 xdr_decode_hyper(__be32 *p, __u64 *valp)
 {
-	*valp = be64_to_cpup((__be64 *)p);
+	*valp = get_unaligned_be64(p);
 	return p + 2;
 }
 
--
To unsubscribe from this list: send the line "unsubscribe linux-nfs" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Filesystem Development]     [Linux USB Development]     [Linux Media Development]     [Video for Linux]     [Linux NILFS]     [Linux Audio Users]     [Yosemite Info]     [Linux SCSI]

  Powered by Linux