Received: by 2002:a05:7412:b10a:b0:f3:1519:9f41 with SMTP id az10csp2717734rdb; Mon, 4 Dec 2023 05:52:56 -0800 (PST) X-Google-Smtp-Source: AGHT+IGrluikewxjXfUN4yU21R7+eJO7UccR1tpVC96RQ1CP2f/mC3TwatNbKj3jGsIgC1WDiuoQ X-Received: by 2002:a05:6358:720f:b0:170:21b6:627f with SMTP id h15-20020a056358720f00b0017021b6627fmr4288847rwa.14.1701697976621; Mon, 04 Dec 2023 05:52:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701697976; cv=none; d=google.com; s=arc-20160816; b=AeNCnlOwwrPcp7FpYyVnRuqzWtmVn18abXHrI21k0gYDwQxbrEJTbh7R3cvgqW1EP9 3PT8G/V3954kiyE5S5T3Dw4LDBhT3Lxqa+xIbfvYw+00aFKJveeaxBuvKxGPiSvpYi5G mc7NTgxVcIKAgwHeaoNdls7iUclovjXUyNfqvl7PHZWwMz2Zr6WiqWxuts+qb/zTxcJ6 9lEQ8GtzpkOgwIQ87ocGSHnpTgs7DRd42CCwY8VMxpDJeIwLACwQOJpKplmWHSKVLtZe QS4dcOtsdtLG+2J683oZdFfojwskcuYgQUgoq7317qlnofnBEzo4JIkza2gfle5ZJr3D iefQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=teeMQkSEiFrZPVgPqAYZ1oKhbwSOoIjlL0GaoVV+lio=; fh=bJge34iZpItgkk5BicpT5sJ9zUKRHx9q2nMCrqrMurc=; b=rjZya0bgo4XHtjq9d/FLkbNs4Bp2da1X188MMXOhXJBCiS93swt20vgfL3HeMPPalR w4fl9RytFfr/vBSmHVP6OsOI+oaNlcU+iVqiYJJie4Isb7fTUbz1du7EqZKfpSxdXaek uiozbcWbaSeE0nLfPP5jl+nZGjKzyfD6jSHzfxAciOewULY2FDWXce7IQrAG0WEftIYP XV9RR3SDDznbyzL+LJo6r8nggmr8+8CNbaxg6Nur/QvGB/zkPS2I88+8VQD/IPOd3Lgd a0v+AobUyMshVT21fCYPIu1GkZtm2Lk0TZ7WobFe+MPboZJn8+AwxO6klJxL6/JfPY2T FWqQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="p/2pylMW"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from lipwig.vger.email (lipwig.vger.email. [23.128.96.33]) by mx.google.com with ESMTPS id cb10-20020a056a02070a00b005c69365abbbsi1366018pgb.318.2023.12.04.05.52.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Dec 2023 05:52:56 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) client-ip=23.128.96.33; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="p/2pylMW"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id 297E3809F8BD; Mon, 4 Dec 2023 05:52:54 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233871AbjLDNwl (ORCPT + 99 others); Mon, 4 Dec 2023 08:52:41 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42706 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234310AbjLDNwb (ORCPT ); Mon, 4 Dec 2023 08:52:31 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 493351A6 for ; Mon, 4 Dec 2023 05:52:33 -0800 (PST) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B38BAC433C7; Mon, 4 Dec 2023 13:52:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1701697952; bh=SR4zmEbGPAtpyvbzmTlRN2hd0ISw5tqwBa8x9lpA8yw=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=p/2pylMW6MAuKBL+D5K5YNw4mVm4nKDY2Qq8/UmX/oMnA/fPkYicySTBWW/XPfIpe On5rcXpbFW8vjEJfjuXAaYtAsosHGlhnaWJiNdU0vL2h/LBJfn1DWwLjWcXR5U6Rg0 32w1eHkObxddfMWZ65ePxrw+O37pIaFSvt2CGASwuqet79k4UOQeV6mYojiYZ0vjQm ErS48KW0rLOS5y3ml9flY9A8UFVsYAVNLzOzZaGN5ZCrxKjczvmdGd2FYSxTwEXtwh VFUhuR6nJMsfUkEHv6HARJMBtCiO0ROnOecsehIWIEu9zwLby/FwXy4jlrF6p0IRMu BbwCQCyg7g6DQ== Date: Mon, 4 Dec 2023 13:52:25 +0000 From: Jonathan Cameron To: Cc: , , , Subject: Re: [PATCH] iio: adc: MCP3564: fix calib_bias and calib_scale range checks Message-ID: <20231204135216.051b0d93@jic23-huawei> In-Reply-To: References: <20231201-mcp3564_range_checks-v1-1-68f4436e22b0@gmail.com> X-Mailer: Claws Mail 4.1.1 (GTK 3.24.38; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-1.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Mon, 04 Dec 2023 05:52:54 -0800 (PST) On Mon, 4 Dec 2023 09:23:45 +0000 wrote: > Hi Javier Carrasco, > > Thank you for looking over the driver and spotting and reporting the bug. Your fix is OK. > > Reviewed-by: Marius Cristea > Applied to the fixes-togreg branch of iio.git and marked for stable. Thanks, Jonathan > Thanks, > Marius > > ________________________________ > From: Javier Carrasco > Sent: Friday, December 1, 2023 11:48 AM > To: Marius Cristea - M70257 ; Jonathan Cameron ; Lars-Peter Clausen > Cc: linux-iio@vger.kernel.org ; linux-kernel@vger.kernel.org ; Javier Carrasco > Subject: [PATCH] iio: adc: MCP3564: fix calib_bias and calib_scale range checks > > EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe > > The current implementation uses the AND (&&) operator to check if the > value to write for IIO_CHAN_INFO_CALIBBIAS and IIO_CHAN_INFO_CALIBSCALE > is within the valid ranges. > The evaluated values are the lower and upper limits of the ranges, > so this operation always evaluates to false. > > The OR (||) operator must be used instead. > > Signed-off-by: Javier Carrasco > --- > This bug has been found when looking for use cases of IIO_AVAIL_RANGE > and the fix could not be tested with real hardware. The issue and its > soulution are rather simple, but still some testing and confirmation > would be welcome. > --- > drivers/iio/adc/mcp3564.c | 4 ++-- > 1 file changed, 2 insertions(+), 2 deletions(-) > > diff --git a/drivers/iio/adc/mcp3564.c b/drivers/iio/adc/mcp3564.c > index e3f1de5fcc5a..d5fb1cae8aeb 100644 > --- a/drivers/iio/adc/mcp3564.c > +++ b/drivers/iio/adc/mcp3564.c > @@ -918,7 +918,7 @@ static int mcp3564_write_raw(struct iio_dev *indio_dev, > mutex_unlock(&adc->lock); > return ret; > case IIO_CHAN_INFO_CALIBBIAS: > - if (val < mcp3564_calib_bias[0] && val > mcp3564_calib_bias[2]) > + if (val < mcp3564_calib_bias[0] || val > mcp3564_calib_bias[2]) > return -EINVAL; > > mutex_lock(&adc->lock); > @@ -928,7 +928,7 @@ static int mcp3564_write_raw(struct iio_dev *indio_dev, > mutex_unlock(&adc->lock); > return ret; > case IIO_CHAN_INFO_CALIBSCALE: > - if (val < mcp3564_calib_scale[0] && val > mcp3564_calib_scale[2]) > + if (val < mcp3564_calib_scale[0] || val > mcp3564_calib_scale[2]) > return -EINVAL; > > if (adc->calib_scale == val) > > --- > base-commit: 994d5c58e50e91bb02c7be4a91d5186292a895c8 > change-id: 20231201-mcp3564_range_checks-221708838130 > > Best regards, > -- > Javier Carrasco >