Skip to contentSkip to conversation

Use of swab16() in drivers/hwmon/*.c

lm-sensors Roland Stigge 2 participants 3 messages Jan 7, 2011

lore
Share & tools
lore
#0 lore raw

Hi,

I wonder about a specific use of swab16() in several files in drivers/hwmon/.

Consider ds1621.c: We get big endian words from i2c_smbus_read_word_data(). To use it on a little endian arch, the driver uses swab16() for conversion by swapping bytes unconditionally.

IMHO this is not suitable on a big endian architecture. Shouldn't it be sth. like be16_to_cpu()?

Thanks in advance.

bye,
Roland

_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors

#1 lore raw

Hallo Roland,

Quoted 9 lines · Roland Stigge

I wonder about a specific use of swab16() in several files in drivers/hwmon/.

Consider ds1621.c: We get big endian words from i2c_smbus_read_word_data(). To use it on a little endian arch, the driver uses swab16() for conversion by swapping bytes unconditionally.

IMHO this is not suitable on a big endian architecture. Shouldn't it be sth. like be16_to_cpu()?

This has nothing to do with the host's endianess. This has to do with the fact that the SMBus specification says that words are sent low byte first but almost all hardware monitoring devices send the high byte first (because it makes a lot more sense.)

Signature · 6 lines
Jean Delvare

_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
#2 lore raw
In reply to Roland Stigge

Hi,

Quoted 4 lines · Jean Delvare

This has nothing to do with the host's endianess. This has to do with the fact that the SMBus specification says that words are sent low byte first but almost all hardware monitoring devices send the high byte first (because it makes a lot more sense.)

Thanks! I just ignored that the word implementation of Linux' SMBus (I2C_SMBUS_WORD_DATA etc.) already takes care of that.

bye,
Roland

_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors