* [PATCH v3 1/2] iio: humidity: si7020: replaced bitmask on humidity values with range check
@ 2015-08-23 12:34 Nicola Corna
2015-08-23 15:48 ` Jonathan Cameron
0 siblings, 1 reply; 5+ messages in thread
From: Nicola Corna @ 2015-08-23 12:34 UTC (permalink / raw)
To: Jonathan Cameron, Hartmut Knaack, Lars-Peter Clausen,
Peter Meerwald
Cc: linux-iio, Nicola Corna
The maximum possible value for the relative humidity is 55575 (100%RH).
This value, if shifted right by 2 bits, uses 14 bits and masking it with
a 12 bit mask removes 2 meaningful bits.
The masking has been replaced with a range check that sets the minimum
value at 786 (0%RH) and the maximum at 13893 (99.998%RH).
Signed-off-by: Nicola Corna <nicola@corna.info>
Reviewed-by: Hartmut Knaack <knaack.h@gmx.de>
---
drivers/iio/humidity/si7020.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/drivers/iio/humidity/si7020.c b/drivers/iio/humidity/si7020.c
index fa3b809..06e6659 100644
--- a/drivers/iio/humidity/si7020.c
+++ b/drivers/iio/humidity/si7020.c
@@ -57,8 +57,12 @@ static int si7020_read_raw(struct iio_dev *indio_dev,
if (ret < 0)
return ret;
*val = ret >> 2;
+ /*
+ * Humidity values can slightly exceed the 0-100%RH
+ * range and should be corrected by software
+ */
if (chan->type == IIO_HUMIDITYRELATIVE)
- *val &= GENMASK(11, 0);
+ clamp_val(*val, 786, 13893);
return IIO_VAL_INT;
case IIO_CHAN_INFO_SCALE:
if (chan->type == IIO_TEMP)
--
2.5.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH v3 1/2] iio: humidity: si7020: replaced bitmask on humidity values with range check
2015-08-23 12:34 [PATCH v3 1/2] iio: humidity: si7020: replaced bitmask on humidity values with range check Nicola Corna
@ 2015-08-23 15:48 ` Jonathan Cameron
2015-08-23 19:08 ` Hartmut Knaack
0 siblings, 1 reply; 5+ messages in thread
From: Jonathan Cameron @ 2015-08-23 15:48 UTC (permalink / raw)
To: Nicola Corna, Hartmut Knaack, Lars-Peter Clausen, Peter Meerwald
Cc: linux-iio
On 23/08/15 13:34, Nicola Corna wrote:
> The maximum possible value for the relative humidity is 55575 (100%RH).
> This value, if shifted right by 2 bits, uses 14 bits and masking it with
> a 12 bit mask removes 2 meaningful bits.
> The masking has been replaced with a range check that sets the minimum
> value at 786 (0%RH) and the maximum at 13893 (99.998%RH).
>
> Signed-off-by: Nicola Corna <nicola@corna.info>
> Reviewed-by: Hartmut Knaack <knaack.h@gmx.de>
Applied. I have taken the view that previously the driver
was 'limited' by this rather than a nasty bug.
Hence I've queued it up for the next merge window.
Applied to the togreg branch of iio.git
Thanks,
Jonathan
> ---
> drivers/iio/humidity/si7020.c | 6 +++++-
> 1 file changed, 5 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/iio/humidity/si7020.c b/drivers/iio/humidity/si7020.c
> index fa3b809..06e6659 100644
> --- a/drivers/iio/humidity/si7020.c
> +++ b/drivers/iio/humidity/si7020.c
> @@ -57,8 +57,12 @@ static int si7020_read_raw(struct iio_dev *indio_dev,
> if (ret < 0)
> return ret;
> *val = ret >> 2;
> + /*
> + * Humidity values can slightly exceed the 0-100%RH
> + * range and should be corrected by software
> + */
> if (chan->type == IIO_HUMIDITYRELATIVE)
> - *val &= GENMASK(11, 0);
> + clamp_val(*val, 786, 13893);
> return IIO_VAL_INT;
> case IIO_CHAN_INFO_SCALE:
> if (chan->type == IIO_TEMP)
>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v3 1/2] iio: humidity: si7020: replaced bitmask on humidity values with range check
2015-08-23 15:48 ` Jonathan Cameron
@ 2015-08-23 19:08 ` Hartmut Knaack
2015-08-23 20:12 ` Jonathan Cameron
2015-08-23 20:58 ` Nicola Corna
0 siblings, 2 replies; 5+ messages in thread
From: Hartmut Knaack @ 2015-08-23 19:08 UTC (permalink / raw)
To: Jonathan Cameron, Nicola Corna, Lars-Peter Clausen,
Peter Meerwald
Cc: linux-iio
Jonathan Cameron schrieb am 23.08.2015 um 17:48:
> On 23/08/15 13:34, Nicola Corna wrote:
>> The maximum possible value for the relative humidity is 55575 (100%RH).
>> This value, if shifted right by 2 bits, uses 14 bits and masking it with
>> a 12 bit mask removes 2 meaningful bits.
>> The masking has been replaced with a range check that sets the minimum
>> value at 786 (0%RH) and the maximum at 13893 (99.998%RH).
>>
>> Signed-off-by: Nicola Corna <nicola@corna.info>
>> Reviewed-by: Hartmut Knaack <knaack.h@gmx.de>
> Applied. I have taken the view that previously the driver
> was 'limited' by this rather than a nasty bug.
> Hence I've queued it up for the next merge window.
> Applied to the togreg branch of iio.git
>
This doesn't work, clamp_val() returns a result, which has to be assigned
to a variable (*val) in this case. I thought I pointed that out in V2.
> Thanks,
>
> Jonathan
>> ---
>> drivers/iio/humidity/si7020.c | 6 +++++-
>> 1 file changed, 5 insertions(+), 1 deletion(-)
>>
>> diff --git a/drivers/iio/humidity/si7020.c b/drivers/iio/humidity/si7020.c
>> index fa3b809..06e6659 100644
>> --- a/drivers/iio/humidity/si7020.c
>> +++ b/drivers/iio/humidity/si7020.c
>> @@ -57,8 +57,12 @@ static int si7020_read_raw(struct iio_dev *indio_dev,
>> if (ret < 0)
>> return ret;
>> *val = ret >> 2;
>> + /*
>> + * Humidity values can slightly exceed the 0-100%RH
>> + * range and should be corrected by software
>> + */
>> if (chan->type == IIO_HUMIDITYRELATIVE)
>> - *val &= GENMASK(11, 0);
>> + clamp_val(*val, 786, 13893);
This needs to be: *val = clamp_val(...)
>> return IIO_VAL_INT;
>> case IIO_CHAN_INFO_SCALE:
>> if (chan->type == IIO_TEMP)
>>
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-iio" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v3 1/2] iio: humidity: si7020: replaced bitmask on humidity values with range check
2015-08-23 19:08 ` Hartmut Knaack
@ 2015-08-23 20:12 ` Jonathan Cameron
2015-08-23 20:58 ` Nicola Corna
1 sibling, 0 replies; 5+ messages in thread
From: Jonathan Cameron @ 2015-08-23 20:12 UTC (permalink / raw)
To: Hartmut Knaack, Nicola Corna, Lars-Peter Clausen, Peter Meerwald
Cc: linux-iio
On 23/08/15 20:08, Hartmut Knaack wrote:
> Jonathan Cameron schrieb am 23.08.2015 um 17:48:
>> On 23/08/15 13:34, Nicola Corna wrote:
>>> The maximum possible value for the relative humidity is 55575 (100%RH).
>>> This value, if shifted right by 2 bits, uses 14 bits and masking it with
>>> a 12 bit mask removes 2 meaningful bits.
>>> The masking has been replaced with a range check that sets the minimum
>>> value at 786 (0%RH) and the maximum at 13893 (99.998%RH).
>>>
>>> Signed-off-by: Nicola Corna <nicola@corna.info>
>>> Reviewed-by: Hartmut Knaack <knaack.h@gmx.de>
>> Applied. I have taken the view that previously the driver
>> was 'limited' by this rather than a nasty bug.
>> Hence I've queued it up for the next merge window.
>> Applied to the togreg branch of iio.git
>>
>
> This doesn't work, clamp_val() returns a result, which has to be assigned
> to a variable (*val) in this case. I thought I pointed that out in V2.
backed out...
(hadn't pushed it out anywhere yet anyway ;)
Thanks Harmut.
>
>> Thanks,
>>
>> Jonathan
>>> ---
>>> drivers/iio/humidity/si7020.c | 6 +++++-
>>> 1 file changed, 5 insertions(+), 1 deletion(-)
>>>
>>> diff --git a/drivers/iio/humidity/si7020.c b/drivers/iio/humidity/si7020.c
>>> index fa3b809..06e6659 100644
>>> --- a/drivers/iio/humidity/si7020.c
>>> +++ b/drivers/iio/humidity/si7020.c
>>> @@ -57,8 +57,12 @@ static int si7020_read_raw(struct iio_dev *indio_dev,
>>> if (ret < 0)
>>> return ret;
>>> *val = ret >> 2;
>>> + /*
>>> + * Humidity values can slightly exceed the 0-100%RH
>>> + * range and should be corrected by software
>>> + */
>>> if (chan->type == IIO_HUMIDITYRELATIVE)
>>> - *val &= GENMASK(11, 0);
>>> + clamp_val(*val, 786, 13893);
>
> This needs to be: *val = clamp_val(...)
>
>>> return IIO_VAL_INT;
>>> case IIO_CHAN_INFO_SCALE:
>>> if (chan->type == IIO_TEMP)
>>>
>>
>> --
>> To unsubscribe from this list: send the line "unsubscribe linux-iio" in
>> the body of a message to majordomo@vger.kernel.org
>> More majordomo info at http://vger.kernel.org/majordomo-info.html
>>
>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v3 1/2] iio: humidity: si7020: replaced bitmask on humidity values with range check
2015-08-23 19:08 ` Hartmut Knaack
2015-08-23 20:12 ` Jonathan Cameron
@ 2015-08-23 20:58 ` Nicola Corna
1 sibling, 0 replies; 5+ messages in thread
From: Nicola Corna @ 2015-08-23 20:58 UTC (permalink / raw)
To: Jonathan Cameron, Hartmut Knaack, Lars-Peter Clausen,
Peter Meerwald
Cc: linux-iio
August 23 2015 10:12 PM, "Jonathan Cameron" <jic23@kernel.org> wrote:=0A>=
On 23/08/15 20:08, Hartmut Knaack wrote:=0A> =0A>> Jonathan Cameron schr=
ieb am 23.08.2015 um 17:48:=0A>>> On 23/08/15 13:34, Nicola Corna wrote:=
=0A>>>> The maximum possible value for the relative humidity is 55575 (10=
0%RH).=0A>>>> This value, if shifted right by 2 bits, uses 14 bits and ma=
sking it with=0A>>>> a 12 bit mask removes 2 meaningful bits.=0A>>>> The =
masking has been replaced with a range check that sets the minimum=0A>>>>=
value at 786 (0%RH) and the maximum at 13893 (99.998%RH).=0A>>>> =0A>>>>=
Signed-off-by: Nicola Corna <nicola@corna.info>=0A>>>> Reviewed-by: Hart=
mut Knaack <knaack.h@gmx.de>=0A>>> =0A>>> Applied. I have taken the view =
that previously the driver=0A>>> was 'limited' by this rather than a nast=
y bug.=0A>>> Hence I've queued it up for the next merge window.=0A>>> App=
lied to the togreg branch of iio.git=0A>> =0A>> This doesn't work, clamp_=
val() returns a result, which has to be assigned=0A>> to a variable (*val=
) in this case. I thought I pointed that out in V2.=0A> =0A> backed out..=
.=0A> =0A> (hadn't pushed it out anywhere yet anyway ;)=0A> =0A> Thanks H=
armut.=0A> =0A=0AWell, I should have paid more attention. Sorry for the i=
nconvenience.=0A=0ANicola Corna=0A=0A>>> Thanks,=0A>>> =0A>>> Jonathan=0A=
>>>> ---=0A>>>> drivers/iio/humidity/si7020.c | 6 +++++-=0A>>>> 1 file ch=
anged, 5 insertions(+), 1 deletion(-)=0A>>>> =0A>>>> diff --git a/drivers=
/iio/humidity/si7020.c b/drivers/iio/humidity/si7020.c=0A>>>> index fa3b8=
09..06e6659 100644=0A>>>> --- a/drivers/iio/humidity/si7020.c=0A>>>> +++ =
b/drivers/iio/humidity/si7020.c=0A>>>> @@ -57,8 +57,12 @@ static int si70=
20_read_raw(struct iio_dev *indio_dev,=0A>>>> if (ret < 0)=0A>>>> return =
ret;=0A>>>> *val =3D ret >> 2;=0A>>>> + /*=0A>>>> + * Humidity values can=
slightly exceed the 0-100%RH=0A>>>> + * range and should be corrected by=
software=0A>>>> + */=0A>>>> if (chan->type =3D=3D IIO_HUMIDITYRELATIVE)=
=0A>>>> - *val &=3D GENMASK(11, 0);=0A>>>> + clamp_val(*val, 786, 13893);=
=0A>> =0A>> This needs to be: *val =3D clamp_val(...)=0A>> =0A>>>> return=
IIO_VAL_INT;=0A>>>> case IIO_CHAN_INFO_SCALE:=0A>>>> if (chan->type =3D=
=3D IIO_TEMP)=0A>>> =0A>>> --=0A>>> To unsubscribe from this list: send t=
he line "unsubscribe linux-iio" in=0A>>> the body of a message to majordo=
mo@vger.kernel.org=0A>>> More majordomo info at http://vger.kernel.org/ma=
jordomo-info.html
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2015-08-23 20:58 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-08-23 12:34 [PATCH v3 1/2] iio: humidity: si7020: replaced bitmask on humidity values with range check Nicola Corna
2015-08-23 15:48 ` Jonathan Cameron
2015-08-23 19:08 ` Hartmut Knaack
2015-08-23 20:12 ` Jonathan Cameron
2015-08-23 20:58 ` Nicola Corna
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).