lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Date:   Tue, 12 Apr 2022 15:53:46 +0100
From:   Jonathan Cameron <Jonathan.Cameron@...wei.com>
To:     Gabriel Krisman Bertazi <krisman@...labora.com>
CC:     Shreeya Patel <shreeya.patel@...labora.com>,
        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

On Tue, 12 Apr 2022 10:06:18 -0400
Gabriel Krisman Bertazi <krisman@...labora.com> wrote:

> 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);

> 
I was being silly.  It's not aligned for obvious reasons that we don't do
24bit alignment, so you need
get_unaligned_le24()

Jonathan



Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ