From 4ea5e988195439b479d81a869603411c0d76a583 Mon Sep 17 00:00:00 2001 From: "a.llano@usyscom.com" <a.llano@usyscom.com> Date: Mon, 7 Mar 2005 17:57:09 -0800 Subject: [PATCH] [PATCH] Fix 1-Wire Dallas in bigendian machines I've been testing the 1-Wire Dallas in a bigendian machine (through a GPIO) and I've found some problems that can easily addressed with the provided patch. (inline at the end of the message). I have a question about the implementation of w1_smem. In the line 90 of drivers/w1/w1_smem.c. for (i = 0; i < 9; ++i) count += sprintf(buf + count, "%02x ", ((u8 *)&sl->reg_num)[i]); I don't see why this loop is execute 9 times when the provided reg_num is 8 bytes long. I don't understand the purpose of the last byte. Signed-off-by: Andrew Morton <akpm@osdl.org> Signed-off-by: Linus Torvalds <torvalds@osdl.org> --- drivers/w1/w1.c | 7 ++++--- drivers/w1/w1.h | 8 ++++++++ 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/drivers/w1/w1.c b/drivers/w1/w1.c index 832c196e3a1b..1ecda516ba8e 100644 --- a/drivers/w1/w1.c +++ b/drivers/w1/w1.c @@ -521,9 +521,10 @@ void w1_slave_found(unsigned long data, u64 rn) slave_count++; } - if (slave_count == dev->slave_count && - rn && ((rn >> 56) & 0xff) == w1_calc_crc8((u8 *)&rn, 7)) { - w1_attach_slave_device(dev, (struct w1_reg_num *) &rn); + if (slave_count == dev->slave_count && rn ) { + tmp = cpu_to_le64(rn); + if(((rn >> 56) & 0xff) == w1_calc_crc8((u8 *)&tmp, 7)) + w1_attach_slave_device(dev, (struct w1_reg_num *) &rn); } atomic_dec(&dev->refcnt); diff --git a/drivers/w1/w1.h b/drivers/w1/w1.h index 0fa0baee1247..abbddaf3f8e2 100644 --- a/drivers/w1/w1.h +++ b/drivers/w1/w1.h @@ -24,9 +24,17 @@ struct w1_reg_num { +#if defined(__LITTLE_ENDIAN_BITFIELD) __u64 family:8, id:48, crc:8; +#elif defined(__BIG_ENDIAN_BITFIELD) + __u64 crc:8, + id:48, + family:8; +#else +#error "Please fix <asm/byteorder.h>" +#endif }; #ifdef __KERNEL__ -- 2.30.9