lkml.org 
[lkml]   [2022]   [Apr]   [12]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
From
SubjectRe: [PATCH 3/3] iio: light: Add support for ltrf216a sensor
Date
Shreeya Patel <shreeya.patel@collabora.com> writes:

>>> + val_1 = i2c_smbus_read_byte_data(data->client, addr + 1);
>>> + val_2 = i2c_smbus_read_byte_data(data->client, addr + 2);
>>> + ret = (val_2 << 16) + (val_1 << 8) + val_0;
>> This is a le24_to_cpu() conversion.
>> Preferred choice would be to use something like
>> u8 buf[3];
>> int i;
>>
>> for (i = 0; i < 3; i++) {
>> ret = i2c_smbus_read_byte_data(data->client, addr);
>> if (ret < 0)
>> return ret;
>> buf[i] = ret;
>> }
>> return le24_to_cpu(buf);
>>
>
> We do not have any le24_to_cpu() function in current kernel source code.
> I was thinking to use le32_to_cpu() instead but it requires an argument of
> type __le32 and our case we storing the values in u8 buf[3] so I'm not
> really sure if it's possible to use le32_to_cpu() or any other function.

I guess you could make it a 32-bit buffer, keep the most
significant byte zeroed and return le32_to_cpu:

u8 buf[4];

memset(buf, 0x0, sizeof(buf));

for (i = 0; i < 3; i++) {
ret = i2c_smbus_read_byte_data(data->client, addr);
if (ret < 0)
return ret;
buf[i] = ret;
}
return le32_to_cpu(buf);

--
Gabriel Krisman Bertazi

\
 
 \ /
  Last update: 2022-04-12 16:08    [W:0.111 / U:0.136 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site