Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp4904299rwr; Sun, 23 Apr 2023 16:23:47 -0700 (PDT) X-Google-Smtp-Source: AKy350blgn5gAAeQ2vSKQ5Yfjdo4Lhdz/Jp6WbWhDK+6fD6kNkzs2VpF9suKz//87XN1CY+T5UJ2 X-Received: by 2002:a17:90b:1103:b0:23f:1165:b49f with SMTP id gi3-20020a17090b110300b0023f1165b49fmr11097478pjb.38.1682292226831; Sun, 23 Apr 2023 16:23:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682292226; cv=none; d=google.com; s=arc-20160816; b=fQXFrHzbY1ohn9wObJUm3WDzbwRtP6ky37notI5tvVWPddhxiK75yNTPATNomo/ZOp 4/KKMznrkMyp4orGXW37FrTke8JUb9fogAxP5E09eBNnkV0Urz2QV0FI8kVAjxHpibDC 4kdh18g6/aypBnvKaNmIw/MIMq95sEAaR63WtVzJMTXwSBHWqN8PaP5eeJqO0gXGFsv5 tniZtV7ctDDlacaNAuxEOgzctjGh6Gj8G71VjslOZ27pn8lGDycbBbHtkSYQRrt17r1E THxNd0gijGBtVPmz90ZRbTAaShP+9GSaVvbT+d2XZ8lNvI3W3jCnvVUg6WA9qUkuZyAe HBRg== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=7P/6zoNdnIVgVCEt5mDoPuKCp+7Gdkmg7/IH03tl/hc=; b=PwabjpHqp5U5nC1iIW7NwsLLSsXiBd0pPYGsBuhdy/QiFFWEK2Mlf5YbhUOVDS8Z5c CkO4j9lSf7jlgkYWLfSrOeFyli6sPCANaV5M0i3zmWZvs7CqoJpycNYzkM7opH5YGMH+ K5p1Tm2KfLRGTka6Zh3NkpQeFCGIeNh0WpHU1E0nX02Oq+/OdEeUh2lFpaSsr2NEV7Xd ZOWyTxMBJw1C7zjQDWo1S5Gqsnluwl9BZpinSt51OZtnLu/y49Gt3NENjZC0d8jDOaym A4m6jYvQnpr/vWc37exbvHMtQ2IzzwCrD7LRIEMpFEyE0DLFlYBFm50rxHkxINuXqp7h pnOw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=wEk96wY0; 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 e2-20020a170902cf4200b0019937768786si10453000plg.290.2023.04.23.16.23.36; Sun, 23 Apr 2023 16:23:46 -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=wEk96wY0; 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 S229476AbjDWXU6 (ORCPT + 99 others); Sun, 23 Apr 2023 19:20:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41430 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229948AbjDWXU5 (ORCPT ); Sun, 23 Apr 2023 19:20:57 -0400 Received: from mail-yb1-xb30.google.com (mail-yb1-xb30.google.com [IPv6:2607:f8b0:4864:20::b30]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D147610E7 for ; Sun, 23 Apr 2023 16:20:55 -0700 (PDT) Received: by mail-yb1-xb30.google.com with SMTP id 3f1490d57ef6-b8f34bca001so5277402276.3 for ; Sun, 23 Apr 2023 16:20:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1682292055; x=1684884055; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=7P/6zoNdnIVgVCEt5mDoPuKCp+7Gdkmg7/IH03tl/hc=; b=wEk96wY0BNTq4Si5T64xauv4RLRaJkGMx6CMD4mIf694zT68AiY4H/qDevf6Fehfqc JQOOaH/f+33/21XGfmN00faEd8Ew41fsJ357jQWHVdQda35ApZF71jWp1gAqCwMVs1F+ +X8P1x4c3HO3v3jGE7q6d525dYGo+9FxUzp9Hp6ZW7kZ9rjKH0qqSEVhZluxNi+TNvj0 WQjGb5YNeAn9TbOZUszCeGDDpm4ubTNVfUPTudWLST3e6X+6NdNpLDz0DaJAq93ehLBf K6EQIaA+8fFJ++AGF12JVUf0+3blgzzEGroRU9JcExEh5R3A4rOaXoI9kATzMiZkeUGp hy2g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682292055; x=1684884055; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=7P/6zoNdnIVgVCEt5mDoPuKCp+7Gdkmg7/IH03tl/hc=; b=XwkdmEt/C+Qqd2Q2xHGPkPPt7+EiXIVwta9bJmg95ayyYeSa5GzqKw4eCh4gG8cgoF ssz8NpIJ70vIJDVONDJos1I9er6iXNomGtJozodWPDXn98App4bj0K5AxtXHslVV/h+Y 5mz6vqD+YG+5YQbtaeqYAxrDpqWj1j61YoBHDWSPBi18TX62aIboDr54c6Y5kHSAtspX VnIoJPYc8YfjTQWYyQoN5drgh65J2YaAjXOv2F3q+Vtgdd0oFmDxYrgsWVUzVpyqeBfc 6FraB7dajOI1M3Taq8JBgYGP1era6oxsWdnOje8gOtAXXLxPFsim+qfkR7ddGwPGHbxF QrSw== X-Gm-Message-State: AAQBX9cVguhHXbOPUOmCobDw9cFHnsTfOgWsnYIZPsaZvLye+rvbE63C D+QhLxX2mMXAluahNCpwbN1xWg== X-Received: by 2002:a25:cac4:0:b0:b8f:2047:181a with SMTP id a187-20020a25cac4000000b00b8f2047181amr8493235ybg.24.1682292055043; 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.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 23 Apr 2023 16:20:54 -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.14 v4 1/5] iio: counter: 104-quad-8: Fix race condition between FLAG and CNTR reads Date: Sun, 23 Apr 2023 19:20:43 -0400 Message-Id: <20230423232047.12589-1-william.gray@linaro.org> X-Mailer: git-send-email 2.40.0 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.14.x Signed-off-by: William Breathitt Gray --- drivers/iio/counter/104-quad-8.c | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/drivers/iio/counter/104-quad-8.c b/drivers/iio/counter/104-quad-8.c index 181585ae6e..bdb07694e2 100644 --- a/drivers/iio/counter/104-quad-8.c +++ b/drivers/iio/counter/104-quad-8.c @@ -64,9 +64,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) { @@ -76,12 +73,7 @@ static int quad8_read_raw(struct iio_dev *indio_dev, return IIO_VAL_INT; } - flags = inb(base_offset + 1); - borrow = flags & BIT(0); - carry = !!(flags & BIT(1)); - - /* Borrow XOR Carry effectively doubles count range */ - *val = (borrow ^ carry) << 24; + *val = 0; /* Reset Byte Pointer; transfer Counter to Output Latch */ outb(0x11, base_offset + 1); base-commit: df06e352f27a9f368ec6a3b077881c35d933e32c -- 2.40.0