Skip to content

Commit 1c010ff

Browse files
author
Jean Delvare
committed
i2c-tiny-usb: Fix on big-endian systems
The functionality bit vector is always returned as a little-endian 32-bit number by the device, so it must be byte-swapped to the host endianness. On the other hand, the delay value is handled by the USB stack, so no byte swapping is needed on our side. This fixes bug #15105: http://bugzilla.kernel.org/show_bug.cgi?id=15105 Reported-by: Jens Richter <jens@richter-stutensee.de> Signed-off-by: Jean Delvare <khali@linux-fr.org> Tested-by: Jens Richter <jens@richter-stutensee.de> Cc: Till Harbaum <till@harbaum.org> Cc: stable@kernel.org
1 parent fc76be4 commit 1c010ff

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

drivers/i2c/busses/i2c-tiny-usb.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include <linux/kernel.h>
1414
#include <linux/errno.h>
1515
#include <linux/module.h>
16+
#include <linux/types.h>
1617

1718
/* include interfaces to usb layer */
1819
#include <linux/usb.h>
@@ -31,8 +32,8 @@
3132
#define CMD_I2C_IO_END (1<<1)
3233

3334
/* i2c bit delay, default is 10us -> 100kHz */
34-
static int delay = 10;
35-
module_param(delay, int, 0);
35+
static unsigned short delay = 10;
36+
module_param(delay, ushort, 0);
3637
MODULE_PARM_DESC(delay, "bit delay in microseconds, "
3738
"e.g. 10 for 100kHz (default is 100kHz)");
3839

@@ -109,7 +110,7 @@ static int usb_xfer(struct i2c_adapter *adapter, struct i2c_msg *msgs, int num)
109110

110111
static u32 usb_func(struct i2c_adapter *adapter)
111112
{
112-
u32 func;
113+
__le32 func;
113114

114115
/* get functionality from adapter */
115116
if (usb_read(adapter, CMD_GET_FUNC, 0, 0, &func, sizeof(func)) !=
@@ -118,7 +119,7 @@ static u32 usb_func(struct i2c_adapter *adapter)
118119
return 0;
119120
}
120121

121-
return func;
122+
return le32_to_cpu(func);
122123
}
123124

124125
/* This is the actual algorithm we define */
@@ -216,8 +217,7 @@ static int i2c_tiny_usb_probe(struct usb_interface *interface,
216217
"i2c-tiny-usb at bus %03d device %03d",
217218
dev->usb_dev->bus->busnum, dev->usb_dev->devnum);
218219

219-
if (usb_write(&dev->adapter, CMD_SET_DELAY,
220-
cpu_to_le16(delay), 0, NULL, 0) != 0) {
220+
if (usb_write(&dev->adapter, CMD_SET_DELAY, delay, 0, NULL, 0) != 0) {
221221
dev_err(&dev->adapter.dev,
222222
"failure setting delay to %dus\n", delay);
223223
retval = -EIO;

0 commit comments

Comments
 (0)