Re: [1/1] w1: w1 temp calculation overflow fix.

Harvey Harrison
2009-02-09T21:48:56Z

On Tue, 2009-02-10 at 00:42 +0300, Evgeniy Polyakov wrote:
> Signed-off-by: Ian Dall <ian@beware.dropbear.id.au>
> Signed-off-by: Evgeniy Polyakov <zbr@ioremap.net>
>
> diff --git a/drivers/w1/slaves/w1_therm.c b/drivers/w1/slaves/w1_therm.c
> index 2c8dff9..1ed3d55 100644
> --- a/drivers/w1/slaves/w1_therm.c
> +++ b/drivers/w1/slaves/w1_therm.c
> @@ -115,7 +115,7 @@ static struct w1_therm_family_converter w1_therm_families[] = {
>
> static inline int w1_DS18B20_convert_temp(u8 rom[9])
> {
> - s16 t = (rom[1] << 8) | rom[0];
> + int t = ((s16)rom[1] << 8) | rom[0];

Alternatively,

int t = (s16)le16_to_cpup((__le16 *)rom);

Cheers,

Harvey