Re: [PATCH] iio: remove unnecessary condition judgment in am2315_trigger_handler
From: David Frey
Date: Mon Sep 10 2018 - 11:58:00 EST
On 9/8/2018 7:17 AM, Jonathan Cameron wrote:
> On Sat, 8 Sep 2018 17:59:13 +0530
> Himanshu Jha <himanshujha199640@xxxxxxxxx> wrote:
>
>> On Sat, Sep 08, 2018 at 06:57:36PM +0800, zhong jiang wrote:
>>> The iterator in for_each_set_bit is never null, therefore, remove
>>> the redundant conditional judgment.
>>>
>>> Signed-off-by: zhong jiang <zhongjiang@xxxxxxxxxx>
>>> ---
>>> drivers/iio/humidity/am2315.c | 3 +--
>>> 1 file changed, 1 insertion(+), 2 deletions(-)
>>>
>>> diff --git a/drivers/iio/humidity/am2315.c b/drivers/iio/humidity/am2315.c
>>> index 7d8669d..dc12e37 100644
>>> --- a/drivers/iio/humidity/am2315.c
>>> +++ b/drivers/iio/humidity/am2315.c
>>> @@ -176,8 +176,7 @@ static irqreturn_t am2315_trigger_handler(int irq, void *p)
>>> i = 0;
>>> for_each_set_bit(bit, indio_dev->active_scan_mask,
>>> indio_dev->masklength) {
>>> - data->buffer[i] = (bit ? sensor_data.temp_data :
>>> - sensor_data.hum_data);
>>> + data->buffer[i] = sensor_data.temp_data;
>>
>> No, this seems wrong!
>>
>> We have buffer support to either take both readings(temp & humid)
>> simultaneously, or only single channel using specified scan mask.
>
> Key think is that bit most definitely can be 0 if the 0th bit is set.
> This isn't a null check at all.
>
> I'm curious, was this a by inspection case or did some script throw
> this one up?
Firstly, +1 on the patch in this thread being an incorrect change.
While inspecting the surrounding code, I noticed that there's a bit of
questionable code in this area. I believe this whole chunk:
if (*(indio_dev->active_scan_mask) == AM2315_ALL_CHANNEL_MASK) {
data->buffer[0] = sensor_data.hum_data;
data->buffer[1] = sensor_data.temp_data;
} else {
i = 0;
for_each_set_bit(bit, indio_dev->active_scan_mask,
indio_dev->masklength) {
data->buffer[i] = (bit ? sensor_data.temp_data :
sensor_data.hum_data);
i++;
}
}
could be reduced to this:
for_each_set_bit(bit, indio_dev->active_scan_mask,
indio_dev->masklength)
data->buffer[bit] = (bit ? sensor_data.temp_data :
sensor_data.hum_data);
The if/else structure seems like an unnecessary optimization.
Thoughts?