Skip to content

Commit 423ad0c

Browse files
Hartmut Knaackjic23
authored andcommitted
iio:light:stk3310: make endianness independent of host
Data is stored in the device in be16 format. Make use of be16_to_cpu and cpu_to_be16 to have correct endianness on any host architecture. Signed-off-by: Hartmut Knaack <[email protected]> Reviewed-by: Tiberiu Breana <[email protected]> Signed-off-by: Jonathan Cameron <[email protected]>
1 parent 037e966 commit 423ad0c

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

drivers/iio/light/stk3310.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ static int stk3310_read_event(struct iio_dev *indio_dev,
200200
int *val, int *val2)
201201
{
202202
u8 reg;
203-
u16 buf;
203+
__be16 buf;
204204
int ret;
205205
struct stk3310_data *data = iio_priv(indio_dev);
206206

@@ -222,7 +222,7 @@ static int stk3310_read_event(struct iio_dev *indio_dev,
222222
dev_err(&data->client->dev, "register read failed\n");
223223
return ret;
224224
}
225-
*val = swab16(buf);
225+
*val = be16_to_cpu(buf);
226226

227227
return IIO_VAL_INT;
228228
}
@@ -235,7 +235,7 @@ static int stk3310_write_event(struct iio_dev *indio_dev,
235235
int val, int val2)
236236
{
237237
u8 reg;
238-
u16 buf;
238+
__be16 buf;
239239
int ret;
240240
unsigned int index;
241241
struct stk3310_data *data = iio_priv(indio_dev);
@@ -252,7 +252,7 @@ static int stk3310_write_event(struct iio_dev *indio_dev,
252252
else
253253
return -EINVAL;
254254

255-
buf = swab16(val);
255+
buf = cpu_to_be16(val);
256256
ret = regmap_bulk_write(data->regmap, reg, &buf, 2);
257257
if (ret < 0)
258258
dev_err(&client->dev, "failed to set PS threshold!\n");
@@ -301,7 +301,7 @@ static int stk3310_read_raw(struct iio_dev *indio_dev,
301301
int *val, int *val2, long mask)
302302
{
303303
u8 reg;
304-
u16 buf;
304+
__be16 buf;
305305
int ret;
306306
unsigned int index;
307307
struct stk3310_data *data = iio_priv(indio_dev);
@@ -322,7 +322,7 @@ static int stk3310_read_raw(struct iio_dev *indio_dev,
322322
mutex_unlock(&data->lock);
323323
return ret;
324324
}
325-
*val = swab16(buf);
325+
*val = be16_to_cpu(buf);
326326
mutex_unlock(&data->lock);
327327
return IIO_VAL_INT;
328328
case IIO_CHAN_INFO_INT_TIME:

0 commit comments

Comments
 (0)