Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp5702836rwl; Tue, 11 Apr 2023 08:53:16 -0700 (PDT) X-Google-Smtp-Source: AKy350bXXrvTPpORCB6dLgchB9NqA1hbWmpgkfydxcyN6dG6R8cYUeaSqXaCs+GXmlK4sx1PxSNp X-Received: by 2002:a05:6a20:a91f:b0:d5:9216:9182 with SMTP id cd31-20020a056a20a91f00b000d592169182mr11425401pzb.9.1681228395953; Tue, 11 Apr 2023 08:53:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681228395; cv=none; d=google.com; s=arc-20160816; b=tBjvFiLTQZbbI2+tbm57NYnKj/rV3oE66n1CbkB1wFQ7vJJqdghi+KX6J6Lv0r96fC euLBlY2Z3QXxSmDulApT5QMCq6JgtURNIG/kcKdJapAzdnx/i2Myh5vQlvj8DhC2BeRc eBYn9Kp9uQZjO/bF0cy3jUGmxmWFUKZl4kkOBlQbcgPLDTbDXPHu8Rp+xSShXSZeyhu4 yZ0gq4vHtbD1GHtEVNQgZuDwtbU50sVFKjr7BTEK4oR2BHLE4pk418sKJhwBw75zzGSc v6hQE5fhiLi4fSEBNnou9PIlsnPJvJLQ86MeZqZAy+zdw8nboMbDKBVmu1CqvW7eCvA8 /bsg== 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=R2fQ8lpuhAnY5CWWZIXFfg7wKiEfX2djoV2eUnsPPVc=; b=I3VkdfJZzNlkK5rVsdYBZ98nzvFyuxy1tyJmqdVqQtzFHWws/B0lfhYhvkSCNErcMS 8ez2Eg83FDWxg3utywAOGGnRJ6yj+Eb5RRXFsLxrWKKrtM2gDdEznEK9CH3XjhkMXDol kNuuE3SyEbLKUuxob96xtvX4o1BFV1zO60RRMnMlnbTneBUuXZuZXTyw74OZzChU6nDq X/sgcNCkD01UD5pprVqSY+qw2eMu1Pgbt0orUuLX0KTW3RJi38NZrhsUoPvcnfhiGNCw v5q7CkxpIbbjMW+SqHWlhF6WDbZRMlHzNmRzpbxuuZtaOhf/0JTUEiWS8HVR2iqcL6xK NaJA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=QeRpnyUO; 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 s12-20020a632c0c000000b00517a9eb2729si9674715pgs.500.2023.04.11.08.53.02; Tue, 11 Apr 2023 08:53:15 -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=QeRpnyUO; 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 S230340AbjDKPwi (ORCPT + 99 others); Tue, 11 Apr 2023 11:52:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40030 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229953AbjDKPwe (ORCPT ); Tue, 11 Apr 2023 11:52:34 -0400 Received: from mail-yb1-xb2f.google.com (mail-yb1-xb2f.google.com [IPv6:2607:f8b0:4864:20::b2f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E7ED34C2C for ; Tue, 11 Apr 2023 08:52:33 -0700 (PDT) Received: by mail-yb1-xb2f.google.com with SMTP id z9so8651657ybs.9 for ; Tue, 11 Apr 2023 08:52:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1681228353; x=1683820353; 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=R2fQ8lpuhAnY5CWWZIXFfg7wKiEfX2djoV2eUnsPPVc=; b=QeRpnyUOHzGwuIeP0MNJJWJHdCioAjOAx1apI5BRCq0IYAMc/njk8B75syYr9AqXE2 tejgjgi07wNgTlMzVt7hopwjrFADlgs/D92apR5rb+ejmRJ1nEJbnEZMC4oLtN44t4DM /ZUauG7kYMGyCJXUv0YDarqKe929Ac22GVOww4nsqChyhez7viGB6+dBIDD5fe7F3Li1 56IEUCdZw0+Fuws9CIpj52fOiWM6wGDf7RSk00d8j5XtxHmb+NcXuTmq2FBUtp68BGO2 LFMnOce6hRQsYFA+/EhCW/NTi8KUgCXbqsgC4dzdfX3DUnbV/GBcjOe5RXfUea1y+7Zo Kq8Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1681228353; x=1683820353; 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=R2fQ8lpuhAnY5CWWZIXFfg7wKiEfX2djoV2eUnsPPVc=; b=uNdxHM1I4r1w+mpjVOq2VP5Qv+wBdh2x1LzK1rVCzXFOfMrSECGp7Jktst6lvKdu2H wDJM2CxtVOz3b5hMbIrg0ViPb42+kR7r0rBnMCAPt13VMgV0cdvnU9IxdAhW0J9NWQnF UY9F8QR6ZLvE6JE2PQBvwGjpkAPOHTY8xrA6sAuZTaNJ/zhsB1Rse5k41nxiDxJjk6lp zed6firQxLeT13Oz52DK4+a7dA8Y1usX5wU85ZRjA901++rkuPnaU5yVuBLxS1awhEZA trV4zUFw0ew74xmMQjJrFOzeCPHFXkbx1exn9ebwu4KIhsAb/d3bmoy9spNJrmSQZhGw RbdA== X-Gm-Message-State: AAQBX9fKoAjN52uY8Mf7dRMOlDZfZWKO8z4VJMcM2Q3irPlgs0agoMZz rjHZVrUjlexYq2kASKV8pJJxBw== X-Received: by 2002:a25:688a:0:b0:b8f:227a:b080 with SMTP id d132-20020a25688a000000b00b8f227ab080mr2237727ybc.18.1681228353118; Tue, 11 Apr 2023 08:52:33 -0700 (PDT) Received: from fedora.attlocal.net (69-109-179-158.lightspeed.dybhfl.sbcglobal.net. [69.109.179.158]) by smtp.gmail.com with ESMTPSA id i13-20020a056902068d00b00b7767ca749fsm3683390ybt.60.2023.04.11.08.52.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Apr 2023 08:52:32 -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: [RESEND PATCH 4.19 v3 2/5] iio: counter: 104-quad-8: Fix race condition between FLAG and CNTR reads Date: Tue, 11 Apr 2023 11:52:17 -0400 Message-Id: <20230411155220.9754-2-william.gray@linaro.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230411155220.9754-1-william.gray@linaro.org> References: <20230411155220.9754-1-william.gray@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.2 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=unavailable 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: 5c0966408dee90137adf2e96f949e50a2ba7e401 -- 2.39.2