gpio: pcf857x: Use le16_to_cpu() and cpu_to_le16() in IO accessors
PATCH 1/1 gpio: pcf857x: Use le16_to_cpu() and cpu_to_le16() in IO accessors
16-bit expander data is an __le16, use le16_to_cpu() to read it. In the similar way use cpu_to_le16() to write __le16 value.
--- drivers/gpio/gpio-pcf857x.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-)
drivers/gpio/gpio-pcf857x.c +8 -5
@@ -18,6 +18,8 @@#include <linux/slab.h> #include <linux/spinlock.h> +#include <asm/byteorder.h> +static const struct i2c_device_id pcf857x_id[] = { { .name ="pcf8574" , .driver_data =8 }, { .name ="pcf8574a" , .driver_data =8 },
@@ -96,22 +98,23 @@ static int i2c_read_le8(struct i2c_client *client)static int i2c_write_le16 (struct i2c_client *client,unsigned int word) { -u8 buf[2 ] = { word &0xff , word >>8 , }; +__le16 buf =cpu_to_le16 (word);int status; - status =i2c_master_send (client, buf,2 ); + status =i2c_master_send (client, (char *)&buf,sizeof (buf));return (status <0 ) ? status :0 ; }static int i2c_read_le16 (struct i2c_client *client) { -u8 buf[2 ]; +__le16 buf;int status; - status =i2c_master_recv (client, buf,2 ); + status =i2c_master_recv (client, (char *)&buf,sizeof (buf));if (status <0 )return status; -return (buf[1 ] <<8 ) | buf[0 ]; + +return le16_to_cpu (buf); }/*-------------------------------------------------------------------------*/
Signature · 1 line
2.50.1
Bartosz Golaszewski
maintainerQuoted 5 lines · Andy Shevchenko
16-bit expander data is an
__le16, usele16_to_cpu()to read it. In the similar way usecpu_to_le16()to write__le16value.Signed-off-by Andy Shevchenko <[email protected]>---
Bart
Quoted 6 lines · Bartosz Golaszewski
Quoted 2 lines · Andy Shevchenko
16-bit expander data is an
__le16, usele16_to_cpu()to read it. In the similar way usecpu_to_le16()to write__le16value.Fixes and Cc: stable?
It just changes the open coded approach with the provided APIs, no fix of anything other than source code.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Bartosz Golaszewski
AppliedQuoted 4 lines · Andy Shevchenko
16-bit expander data is an
__le16, usele16_to_cpu()to read it. In the similar way usecpu_to_le16()to write__le16value.
Applied, thanks!
[1/1] gpio: pcf857x: Use le16_to_cpu() and cpu_to_le16() in IO accessors
https://git.kernel.org/brgl/c/fbd35c8cc6c6e817385f2bfa07fa4227370a3010
Best regards,
Signature · 1 line
Bartosz Golaszewski <[email protected]>