Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 29e2d6d1 authored by Ellen Wang's avatar Ellen Wang Committed by Jiri Kosina
Browse files

HID: cp2112: fix byte order in SMBUS operations



Change all occurrences of be16 to le16 in cp2112_xfer(),
because SMBUS words are little endian, not big endian.

Signed-off-by: default avatarEllen Wang <ellen@cumulusnetworks.com>
Cc: stable@vger.kernel.org
Signed-off-by: default avatarJiri Kosina <jkosina@suse.com>
parent 6d00d153
Loading
Loading
Loading
Loading
+4 −4
Original line number Original line Diff line number Diff line
@@ -589,7 +589,7 @@ static int cp2112_xfer(struct i2c_adapter *adap, u16 addr,
	struct cp2112_device *dev = (struct cp2112_device *)adap->algo_data;
	struct cp2112_device *dev = (struct cp2112_device *)adap->algo_data;
	struct hid_device *hdev = dev->hdev;
	struct hid_device *hdev = dev->hdev;
	u8 buf[64];
	u8 buf[64];
	__be16 word;
	__le16 word;
	ssize_t count;
	ssize_t count;
	size_t read_length = 0;
	size_t read_length = 0;
	unsigned int retries;
	unsigned int retries;
@@ -621,7 +621,7 @@ static int cp2112_xfer(struct i2c_adapter *adap, u16 addr,
		break;
		break;
	case I2C_SMBUS_WORD_DATA:
	case I2C_SMBUS_WORD_DATA:
		read_length = 2;
		read_length = 2;
		word = cpu_to_be16(data->word);
		word = cpu_to_le16(data->word);


		if (I2C_SMBUS_READ == read_write)
		if (I2C_SMBUS_READ == read_write)
			count = cp2112_write_read_req(buf, addr, read_length,
			count = cp2112_write_read_req(buf, addr, read_length,
@@ -634,7 +634,7 @@ static int cp2112_xfer(struct i2c_adapter *adap, u16 addr,
		size = I2C_SMBUS_WORD_DATA;
		size = I2C_SMBUS_WORD_DATA;
		read_write = I2C_SMBUS_READ;
		read_write = I2C_SMBUS_READ;
		read_length = 2;
		read_length = 2;
		word = cpu_to_be16(data->word);
		word = cpu_to_le16(data->word);


		count = cp2112_write_read_req(buf, addr, read_length, command,
		count = cp2112_write_read_req(buf, addr, read_length, command,
					      (u8 *)&word, 2);
					      (u8 *)&word, 2);
@@ -727,7 +727,7 @@ static int cp2112_xfer(struct i2c_adapter *adap, u16 addr,
		data->byte = buf[0];
		data->byte = buf[0];
		break;
		break;
	case I2C_SMBUS_WORD_DATA:
	case I2C_SMBUS_WORD_DATA:
		data->word = be16_to_cpup((__be16 *)buf);
		data->word = le16_to_cpup((__le16 *)buf);
		break;
		break;
	case I2C_SMBUS_BLOCK_DATA:
	case I2C_SMBUS_BLOCK_DATA:
		if (read_length > I2C_SMBUS_BLOCK_MAX) {
		if (read_length > I2C_SMBUS_BLOCK_MAX) {