[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <875ynexup1.fsf@collabora.com>
Date: Tue, 12 Apr 2022 10:06:18 -0400
From: Gabriel Krisman Bertazi <krisman@...labora.com>
To: Shreeya Patel <shreeya.patel@...labora.com>
Cc: Jonathan Cameron <jic23@...nel.org>, krzk@...nel.org,
lars@...afoo.de, robh+dt@...nel.org, Zhigang.Shi@...eon.com,
linux-iio@...r.kernel.org, devicetree@...r.kernel.org,
linux-kernel@...r.kernel.org, kernel@...labora.com,
alvaro.soliverez@...labora.com
Subject: Re: [PATCH 3/3] iio: light: Add support for ltrf216a sensor
Shreeya Patel <shreeya.patel@...labora.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
Powered by blists - more mailing lists