Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp4906138rwr; Sun, 23 Apr 2023 16:26:50 -0700 (PDT) X-Google-Smtp-Source: AKy350agyayKNDb1RoO27pdrZDb8gGgsMPeOvlArskeNzuwL5iq/40sxl8s/tt5LGjNHrIv7dSR8 X-Received: by 2002:a05:6a20:72a5:b0:f2:817c:2038 with SMTP id o37-20020a056a2072a500b000f2817c2038mr10795884pzk.18.1682292409985; Sun, 23 Apr 2023 16:26:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682292409; cv=none; d=google.com; s=arc-20160816; b=fo8wMN4sNcHFTNEUA5Sxkk5dkzDMYNFfegnNSBzq33EivAvhiAdG27xqHbMErPRWua swjC4diQwssHsy05Ligl97/lrvrxBEr1dJ74Fn5S/qDV+pwLczG9Ut5M10JZIpjHaP2+ IlMCHYazjdrCeT4szkE4ff/jSFTqbSwTziK7+U0fKmEcFk13JD6NZocU8syrxz1EsggR HU5G10013DHw1GfOVZ0OPgj05nv+AJGBjybhlXmDJc7zm8d10+2MBuq6lQfLDUpD2CFs yaKY+5ZALa5oKR0vkkeQr1e/bqBBL1SmiKt0+T2FyMAPN3v5Ui/oztVAzCM0JIQnh1Ve i62g== 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:date:subject:cc:to:from :dkim-signature; bh=YzAHMc97ie/I1BcVW78M2VJNx9wjhBXHbWDgzi0U6j8=; b=BWJ/+IP0twHsLfFwB8bu8UmKXBATu1zkv5FvRN7avFNPJIPvp9uIZ+k0vxQd5LfhFm IQ5p0fBohoGdXjFHUffbb1mUIh4/e82CI+mD8jIb0LZ7knpBhS41OE4EPnS7qjSVNvJk A3KBGTomwG9OgwN3T03kd7LSsqPUAhA0zQxev6mF9Tq6pHDpV2Oba1SJvJlJY2Hl4kfv yam6zSNFUbZvr7V4CMdSt5YG42vQfOLaJdQA6E2FvFF8ihgWB46iDixKNa/XV2QVjcEB 30QAZqCCvFVApHouUjp0lB2dhIEVA9AAmXfT9y/IG0wVLmub8nt7ZuoGZteoP0ihIq0/ H4+g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=DHVnP7nG; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id a9-20020aa794a9000000b0063b64e61649si9961842pfl.6.2023.04.23.16.26.38; Sun, 23 Apr 2023 16:26:49 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=DHVnP7nG; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230199AbjDWXVC (ORCPT + 99 others); Sun, 23 Apr 2023 19:21:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41440 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230179AbjDWXU6 (ORCPT ); Sun, 23 Apr 2023 19:20:58 -0400 Received: from mail-yb1-xb2c.google.com (mail-yb1-xb2c.google.com [IPv6:2607:f8b0:4864:20::b2c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EB89D10F3 for ; Sun, 23 Apr 2023 16:20:56 -0700 (PDT) Received: by mail-yb1-xb2c.google.com with SMTP id 3f1490d57ef6-b95c3b869dcso12048298276.1 for ; Sun, 23 Apr 2023 16:20:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1682292056; x=1684884056; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=YzAHMc97ie/I1BcVW78M2VJNx9wjhBXHbWDgzi0U6j8=; b=DHVnP7nGrg3vRnIqtPn1Q7mvsvrHjcTern73pfkIbqsV9bRZPyP+MqQ5KrjJfSLW2A ImSGBdVeLWUAHIEaqo1ptnqhYq5k8JfyfS3qnHJvTvV/tJ5j9DWNh2Rnp6PxvxvNgP/a vaxJQXbZbAfwINkpKh1fg+2Jj2yF4CKx949f2oPgiuXGaGqBgCsSPyqL7zyobXg5BKi5 LTbWdtswKpcCYv0oAh41d0mqSd3G1qzTDrCtDXlwl7Tj0a2E7bWhYQA6vFVgqU3ZRS6/ osMpsJUlObexxTVr0xxCfrEZLHcJzr40NjKXCVYbPwuK8mtGtBBy17EYDtkBE+m22ItH t0fA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682292056; x=1684884056; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=YzAHMc97ie/I1BcVW78M2VJNx9wjhBXHbWDgzi0U6j8=; b=ZKMa36oUorpkeladDBFUFLtXmmvxxac4XCWxfjsj0FpK+0aHDyTA3bLCj2A13kT5J6 dc5zB0ZmBZFiDCifFRjMjCQUT7yuRiz4OIDklDjHhjoz+Z11UejJ/GtNa1cey4N3ynjj TJGPLqY/dr1xJTuWJPURBsINLUzPg5GdVGHMPkXAGMYW+JtAZra5Zf88Mn0zOS1350rN lQ9RHnW7TjzETLh58gueXRop2n8epKDes8pJJaogXr6TvbCHuW3vc+rNT4YeFUDM+td8 7YZVbkib2b4uPkeoGoj0BMblyQCpz6E5sHQ/kZi5HVvNuq+uPewHoakuaXjM3xYJsN3x /mTw== X-Gm-Message-State: AAQBX9ffgYkwPrKQFDyTEPf6jHsi98Y27LO5F5c27OhkolEOECgKryZD 8/oID4JVT473R17Idw/J1WlnEw== X-Received: by 2002:a81:49cb:0:b0:54f:52b7:3eac with SMTP id w194-20020a8149cb000000b0054f52b73eacmr8050321ywa.9.1682292055967; Sun, 23 Apr 2023 16:20:55 -0700 (PDT) Received: from fedora.. ([198.136.190.5]) by smtp.gmail.com with ESMTPSA id z205-20020a0dd7d6000000b0054f856bdc4dsm2607352ywd.38.2023.04.23.16.20.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 23 Apr 2023 16:20:55 -0700 (PDT) From: William Breathitt Gray To: Greg Kroah-Hartman Cc: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, Jonathan Cameron , William Breathitt Gray , stable@vger.kernel.org Subject: [PATCH 4.19 v4 2/5] iio: counter: 104-quad-8: Fix race condition between FLAG and CNTR reads Date: Sun, 23 Apr 2023 19:20:44 -0400 Message-Id: <20230423232047.12589-2-william.gray@linaro.org> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230423232047.12589-1-william.gray@linaro.org> References: <20230423232047.12589-1-william.gray@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org commit 4aa3b75c74603c3374877d5fd18ad9cc3a9a62ed upstream. The Counter (CNTR) register is 24 bits wide, but we can have an effective 25-bit count value by setting bit 24 to the XOR of the Borrow flag and Carry flag. The flags can be read from the FLAG register, but a race condition exists: the Borrow flag and Carry flag are instantaneous and could change by the time the count value is read from the CNTR register. Since the race condition could result in an incorrect 25-bit count value, remove support for 25-bit count values from this driver. Fixes: 28e5d3bb0325 ("iio: 104-quad-8: Add IIO support for the ACCES 104-QUAD-8") Cc: # 4.19.x Signed-off-by: William Breathitt Gray --- drivers/iio/counter/104-quad-8.c | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/drivers/iio/counter/104-quad-8.c b/drivers/iio/counter/104-quad-8.c index 92be8d0f77..92e68cada8 100644 --- a/drivers/iio/counter/104-quad-8.c +++ b/drivers/iio/counter/104-quad-8.c @@ -61,10 +61,6 @@ struct quad8_iio { #define QUAD8_REG_CHAN_OP 0x11 #define QUAD8_REG_INDEX_INPUT_LEVELS 0x16 -/* Borrow Toggle flip-flop */ -#define QUAD8_FLAG_BT BIT(0) -/* Carry Toggle flip-flop */ -#define QUAD8_FLAG_CT BIT(1) /* Error flag */ #define QUAD8_FLAG_E BIT(4) /* Up/Down flag */ @@ -97,9 +93,6 @@ static int quad8_read_raw(struct iio_dev *indio_dev, { struct quad8_iio *const priv = iio_priv(indio_dev); const int base_offset = priv->base + 2 * chan->channel; - unsigned int flags; - unsigned int borrow; - unsigned int carry; int i; switch (mask) { @@ -110,12 +103,7 @@ static int quad8_read_raw(struct iio_dev *indio_dev, return IIO_VAL_INT; } - flags = inb(base_offset + 1); - borrow = flags & QUAD8_FLAG_BT; - carry = !!(flags & QUAD8_FLAG_CT); - - /* Borrow XOR Carry effectively doubles count range */ - *val = (borrow ^ carry) << 24; + *val = 0; /* Reset Byte Pointer; transfer Counter to Output Latch */ outb(QUAD8_CTR_RLD | QUAD8_RLD_RESET_BP | QUAD8_RLD_CNTR_OUT, base-commit: a5b79a58cfc02977cd4d5c1e20454cd98e88f749 -- 2.40.0