public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] 9p: fix endian issues [attempt 2]
@ 2009-02-05 19:05 ericvh
  2009-02-05 19:10 ` Harvey Harrison
  0 siblings, 1 reply; 4+ messages in thread
From: ericvh @ 2009-02-05 19:05 UTC (permalink / raw)
  To: v9fs-developer; +Cc: linux-kernel, Eric Van Hensbergen

From: Eric Van Hensbergen <ericvh@gmail.com>

When the changes were done to the protocol last release, some endian
bugs crept in.  This patch fixes those endian problems and has been
verified to run on 32/64 bit and x86/ppc architectures.

This version of the patch incorporates the correct annotations
for endian variables.

Signed-off-by: Eric Van Hensbergen <ericvh@gmail.com>
---
 net/9p/protocol.c |   22 +++++++++++++---------
 1 files changed, 13 insertions(+), 9 deletions(-)

diff --git a/net/9p/protocol.c b/net/9p/protocol.c
index dcd7666..185a53d 100644
--- a/net/9p/protocol.c
+++ b/net/9p/protocol.c
@@ -29,6 +29,7 @@
 #include <linux/errno.h>
 #include <linux/uaccess.h>
 #include <linux/sched.h>
+#include <linux/types.h>
 #include <net/9p/9p.h>
 #include <net/9p/client.h>
 #include "protocol.h"
@@ -160,29 +161,32 @@ p9pdu_vreadf(struct p9_fcall *pdu, int optional, const char *fmt, va_list ap)
 			break;
 		case 'w':{
 				int16_t *val = va_arg(ap, int16_t *);
-				if (pdu_read(pdu, val, sizeof(*val))) {
+				__le16 le_val; 
+				if (pdu_read(pdu, &le_val, sizeof(le_val))) {
 					errcode = -EFAULT;
 					break;
 				}
-				*val = cpu_to_le16(*val);
+				*val = le16_to_cpu(le_val);
 			}
 			break;
 		case 'd':{
 				int32_t *val = va_arg(ap, int32_t *);
-				if (pdu_read(pdu, val, sizeof(*val))) {
+				__le32 le_val;
+				if (pdu_read(pdu, &le_val, sizeof(le_val))) {
 					errcode = -EFAULT;
 					break;
 				}
-				*val = cpu_to_le32(*val);
+				*val = le32_to_cpu(le_val);
 			}
 			break;
 		case 'q':{
 				int64_t *val = va_arg(ap, int64_t *);
-				if (pdu_read(pdu, val, sizeof(*val))) {
+				__le64 le_val;
+				if (pdu_read(pdu, &le_val, sizeof(le_val))) {
 					errcode = -EFAULT;
 					break;
 				}
-				*val = cpu_to_le64(*val);
+				*val = le64_to_cpu(le_val);
 			}
 			break;
 		case 's':{
@@ -362,19 +366,19 @@ p9pdu_vwritef(struct p9_fcall *pdu, int optional, const char *fmt, va_list ap)
 			}
 			break;
 		case 'w':{
-				int16_t val = va_arg(ap, int);
+				__le16 val = cpu_to_le16(va_arg(ap, int));
 				if (pdu_write(pdu, &val, sizeof(val)))
 					errcode = -EFAULT;
 			}
 			break;
 		case 'd':{
-				int32_t val = va_arg(ap, int32_t);
+				__le32 val = cpu_to_le32(va_arg(ap, int32_t));
 				if (pdu_write(pdu, &val, sizeof(val)))
 					errcode = -EFAULT;
 			}
 			break;
 		case 'q':{
-				int64_t val = va_arg(ap, int64_t);
+				__le64 val = cpu_to_le64(va_arg(ap, int64_t));
 				if (pdu_write(pdu, &val, sizeof(val)))
 					errcode = -EFAULT;
 			}
-- 
1.5.6.3


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] 9p: fix endian issues [attempt 2]
  2009-02-05 19:05 [PATCH] 9p: fix endian issues [attempt 2] ericvh
@ 2009-02-05 19:10 ` Harvey Harrison
  2009-02-05 19:16   ` Eric Van Hensbergen
  0 siblings, 1 reply; 4+ messages in thread
From: Harvey Harrison @ 2009-02-05 19:10 UTC (permalink / raw)
  To: ericvh; +Cc: v9fs-developer, linux-kernel

On Thu, 2009-02-05 at 13:05 -0600, ericvh@gmail.com wrote:
> From: Eric Van Hensbergen <ericvh@gmail.com>
> 
> When the changes were done to the protocol last release, some endian
> bugs crept in.  This patch fixes those endian problems and has been
> verified to run on 32/64 bit and x86/ppc architectures.
> 
> This version of the patch incorporates the correct annotations
> for endian variables.
> 
> Signed-off-by: Eric Van Hensbergen <ericvh@gmail.com>

Looks better to me.

Cheers,

Harvey


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] 9p: fix endian issues [attempt 2]
  2009-02-05 19:10 ` Harvey Harrison
@ 2009-02-05 19:16   ` Eric Van Hensbergen
  2009-02-05 19:30     ` Harvey Harrison
  0 siblings, 1 reply; 4+ messages in thread
From: Eric Van Hensbergen @ 2009-02-05 19:16 UTC (permalink / raw)
  To: Harvey Harrison; +Cc: v9fs-developer, linux-kernel

On Thu, Feb 5, 2009 at 1:10 PM, Harvey Harrison
<harvey.harrison@gmail.com> wrote:
> On Thu, 2009-02-05 at 13:05 -0600, ericvh@gmail.com wrote:
>> From: Eric Van Hensbergen <ericvh@gmail.com>
>>
>> When the changes were done to the protocol last release, some endian
>> bugs crept in.  This patch fixes those endian problems and has been
>> verified to run on 32/64 bit and x86/ppc architectures.
>>
>> This version of the patch incorporates the correct annotations
>> for endian variables.
>>
>> Signed-off-by: Eric Van Hensbergen <ericvh@gmail.com>
>
> Looks better to me.
>

Thanks for your help.  Unfortunately, I was trigger happy with the
commit and added whitespace, so everyone gets to see this patch one
more time (sorry).

           -eric

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] 9p: fix endian issues [attempt 2]
  2009-02-05 19:16   ` Eric Van Hensbergen
@ 2009-02-05 19:30     ` Harvey Harrison
  0 siblings, 0 replies; 4+ messages in thread
From: Harvey Harrison @ 2009-02-05 19:30 UTC (permalink / raw)
  To: Eric Van Hensbergen; +Cc: v9fs-developer, linux-kernel

On Thu, 2009-02-05 at 13:16 -0600, Eric Van Hensbergen wrote:
> On Thu, Feb 5, 2009 at 1:10 PM, Harvey Harrison
> <harvey.harrison@gmail.com> wrote:
> > On Thu, 2009-02-05 at 13:05 -0600, ericvh@gmail.com wrote:
> >> From: Eric Van Hensbergen <ericvh@gmail.com>
> >>
> >> When the changes were done to the protocol last release, some endian
> >> bugs crept in.  This patch fixes those endian problems and has been
> >> verified to run on 32/64 bit and x86/ppc architectures.
> >>
> >> This version of the patch incorporates the correct annotations
> >> for endian variables.
> >>
> >> Signed-off-by: Eric Van Hensbergen <ericvh@gmail.com>
> >
> > Looks better to me.
> >
> 
> Thanks for your help.  Unfortunately, I was trigger happy with the
> commit and added whitespace, so everyone gets to see this patch one
> more time (sorry).
> 

Actually for the read case, you may want to look at leXX_to_cpus which
will swap the value in-place through a pointer, so you can avoid the
temporary endian variable.


Harvey


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2009-02-05 19:30 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-02-05 19:05 [PATCH] 9p: fix endian issues [attempt 2] ericvh
2009-02-05 19:10 ` Harvey Harrison
2009-02-05 19:16   ` Eric Van Hensbergen
2009-02-05 19:30     ` Harvey Harrison

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox