linux-iio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: David Frey <dpfrey@gmail.com>
To: Jonathan Cameron <jic23@kernel.org>,
	Himanshu Jha <himanshujha199640@gmail.com>
Cc: zhong jiang <zhongjiang@huawei.com>,
	knaack.h@gmx.de, lars@metafoo.de, pmeerw@pmeerw.net,
	linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] iio: remove unnecessary condition judgment in am2315_trigger_handler
Date: Mon, 10 Sep 2018 08:57:54 -0700	[thread overview]
Message-ID: <a721fd9e-b845-ee1c-0b8b-e763ab182330@gmail.com> (raw)
In-Reply-To: <20180908151751.20e7396f@archlinux>

On 9/8/2018 7:17 AM, Jonathan Cameron wrote:
> On Sat, 8 Sep 2018 17:59:13 +0530
> Himanshu Jha <himanshujha199640@gmail.com> 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@huawei.com>
>>> ---
>>>  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?

      parent reply	other threads:[~2018-09-10 20:52 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-09-08 10:57 [PATCH] iio: remove unnecessary condition judgment in am2315_trigger_handler zhong jiang
2018-09-08 12:29 ` Himanshu Jha
2018-09-08 14:17   ` Jonathan Cameron
2018-09-10 13:49     ` zhong jiang
2018-09-11  1:16       ` zhong jiang
2018-09-10 15:57     ` David Frey [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=a721fd9e-b845-ee1c-0b8b-e763ab182330@gmail.com \
    --to=dpfrey@gmail.com \
    --cc=himanshujha199640@gmail.com \
    --cc=jic23@kernel.org \
    --cc=knaack.h@gmx.de \
    --cc=lars@metafoo.de \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pmeerw@pmeerw.net \
    --cc=zhongjiang@huawei.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).