Re: [PATCH] hwmon: (ads1015) Handle negative conversion values correctly

From: Peter Rosin
Date: Thu Feb 18 2016 - 18:13:51 EST


Hi!

Sorry for the noise, but...

On 2016-02-18 14:07, Peter Rosin wrote:
> From: Peter Rosin <peda@xxxxxxxxxx>
>
> Make the divisor signed as DIV_ROUND_CLOSEST is undefined for negative
> dividends when the divisor is unsigned.
>
> Signed-off-by: Peter Rosin <peda@xxxxxxxxxx>

...I forgot to add this to the commit message
Cc: stable@xxxxxxxxxxxxxxx

I also didn't explicitly mention any example platform where this
bug causes real problems; it was triggered on ARM (atmel sama5d).

Cheers,
Peter

> ---
> drivers/hwmon/ads1015.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/hwmon/ads1015.c b/drivers/hwmon/ads1015.c
> index f155b8380481..2b3105c8aed3 100644
> --- a/drivers/hwmon/ads1015.c
> +++ b/drivers/hwmon/ads1015.c
> @@ -126,7 +126,7 @@ static int ads1015_reg_to_mv(struct i2c_client *client, unsigned int channel,
> struct ads1015_data *data = i2c_get_clientdata(client);
> unsigned int pga = data->channel_data[channel].pga;
> int fullscale = fullscale_table[pga];
> - const unsigned mask = data->id == ads1115 ? 0x7fff : 0x7ff0;
> + const int mask = data->id == ads1115 ? 0x7fff : 0x7ff0;
>
> return DIV_ROUND_CLOSEST(reg * fullscale, mask);
> }
>