Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp2966678imm; Mon, 10 Sep 2018 08:59:55 -0700 (PDT) X-Google-Smtp-Source: ANB0VdaU24YcykltCPVOrKotxjyAQbFyZskeRhgk0sm4dwTKIm8G1MaSdWnv2GGbx5jPpVsgX/IO X-Received: by 2002:a17:902:28a4:: with SMTP id f33-v6mr22808465plb.297.1536595195240; Mon, 10 Sep 2018 08:59:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536595195; cv=none; d=google.com; s=arc-20160816; b=0DSWdBEB6h+7Q2snXKK6lnLOXPaP5ujlMsYAMN/GaPoZgcQTgA+5n/oGS2xv4FjXc9 3GJTrwifUg1jOByE8RfVDwp76Sscb3bSIaO/A2+HkGdXqDPdIU1X0SJepLDNBN0H5Os0 HSC6qqV2B+gkinDgZnNeGFmHwHMRVgMefaWfS9uxZ48ID3iU7JhxnTtt9TTpCYWy26hz 5bShcx0aiCcdx2Y1hX99A+f27GfOduebkz/QFzZdU3Ke6VEbm4MaF9BHlbaXrdUIXSvQ 5iu1fRp1ntOJ1nTf1sI/FhygVcxB9b6nUAmY2TNKujk1mwsrspMBuHP+WWmjWRgFYYIc TCuA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dkim-signature; bh=wPoXvIHDlj1zK5urIZp4G7FqAylzcX55B7BkWWrDRQk=; b=gQ/ZMETtnxck7rR1x+RpykZB/7h9mVA/woOkiz6ghhFCdm5cy9w4oa83OX2ULNBdpq j+EpAYDQ2ZJcG1Rlpmq3rgPsanNzeh1BkgvXL04FudL0wvP8aKBe/edeZBcLvrlALFQX yCi1fHJgBQm85etKJWgNdvxLGGRCJ2UvQudQsLlaeZOdDhoPFBPGtmbu3Q0Z/V2IIU67 cz4vY1Rbr44Z5EuTlFCLSmZCvoSHn/38xCSVrPf2U0m49+JU4PDOQY7bPkAY97HfFyOT xKAv2D+CSmhRhoDlUgCnaAW2KcOdiDz4hyTr1Emc1T0+p+m+8I62lcgWLPeXo2IrcfCG LXBA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=eYLNQz0v; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a143-v6si18169166pfd.241.2018.09.10.08.59.39; Mon, 10 Sep 2018 08:59:55 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=eYLNQz0v; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728233AbeIJUwm (ORCPT + 99 others); Mon, 10 Sep 2018 16:52:42 -0400 Received: from mail-pf1-f195.google.com ([209.85.210.195]:39425 "EHLO mail-pf1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727777AbeIJUwl (ORCPT ); Mon, 10 Sep 2018 16:52:41 -0400 Received: by mail-pf1-f195.google.com with SMTP id j8-v6so10692630pff.6; Mon, 10 Sep 2018 08:57:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=wPoXvIHDlj1zK5urIZp4G7FqAylzcX55B7BkWWrDRQk=; b=eYLNQz0vHYdOkmxNoePksSxZr0vDGabV4znaXB5GPl83CvNp3tIJ9ux5jFKUcNRJBj Fq5lvGrCZQUkPD4joUTNFOALUyfPwSToLWf5tnT+4EAnyIFyQOTKZwxCacS0AI+RWS6l rAnZVgylyiK3r53XQV36+MM4T+EQQ0DIQ5IKUYYfolTrakTb6jDP3xMjhprROZ23/p6R VOaFzr3kveAmbf91vfFRhanYLoZRXmrFtKmVVm4DnTR5MaNjFn3oDvNyA+Is18a6jlIy VwMrYHloGsHAA7SGOzSJz1xe+uJPaN96fyum379pp6K77kXX+wXHwjdGX41JxDsMAuCG GvQA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=wPoXvIHDlj1zK5urIZp4G7FqAylzcX55B7BkWWrDRQk=; b=hRAKoJnhcjkGo3PMmSgJo6fs3uFfY6+zZ5FNKWil5iEumzfajDmurZoBSxqgXBl6WG Rc60wlqE/NpeY4WNMjNuGibOI3rk0+HYA8/JSQvtFkLowN612W9v6CH/AIXFWblf6c8R gtb92IzOhPAhzKA/CZH1/dCu1f8LAo79ZDp/FsHrtV3QyMcVTtot/UClv0+XXuRkThfg GtcmbCMq+wrizBxFX/lmJ5YmEHme6x8LWzUQWEFt5sYsRne3OKENqjtU4cuDQstauZVJ jkza/ZnRrwxBMQLpKdYdSq0BRqNhMt+eTrVKlUc3HvfJqiF2gHlAkR1JX7Ttd38lzsE9 rfKg== X-Gm-Message-State: APzg51CB+PD7LaI5Icku8ScXsqVOw/4ftgmB4YQBvy6aGdUeco8ECbk6 WzSYapXfWDgxgYyJjaONiHMmVNDd X-Received: by 2002:a63:1d3:: with SMTP id 202-v6mr23536040pgb.136.1536595076245; Mon, 10 Sep 2018 08:57:56 -0700 (PDT) Received: from [10.1.70.2] (carmd-fwm01.sierrawireless.com. [208.81.120.1]) by smtp.gmail.com with ESMTPSA id 1-v6sm36434492pfm.145.2018.09.10.08.57.54 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 10 Sep 2018 08:57:55 -0700 (PDT) Subject: Re: [PATCH] iio: remove unnecessary condition judgment in am2315_trigger_handler To: Jonathan Cameron , Himanshu Jha Cc: zhong jiang , knaack.h@gmx.de, lars@metafoo.de, pmeerw@pmeerw.net, linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org References: <1536404256-25189-1-git-send-email-zhongjiang@huawei.com> <20180908122913.GA4445@himanshu-Vostro-3559> <20180908151751.20e7396f@archlinux> From: David Frey Message-ID: Date: Mon, 10 Sep 2018 08:57:54 -0700 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.0 MIME-Version: 1.0 In-Reply-To: <20180908151751.20e7396f@archlinux> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 9/8/2018 7:17 AM, Jonathan Cameron wrote: > On Sat, 8 Sep 2018 17:59:13 +0530 > Himanshu Jha 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 >>> --- >>> 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?