Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp5702424rwl; Tue, 11 Apr 2023 08:52:55 -0700 (PDT) X-Google-Smtp-Source: AKy350atgHbRHtwkjM/elEQrOKJ8DVzOkX80KOJC378S00cCToQjooKLvVH8FpB7it+rkTcvqB/0 X-Received: by 2002:a17:903:120a:b0:1a0:76d1:545c with SMTP id l10-20020a170903120a00b001a076d1545cmr25945930plh.10.1681228374970; Tue, 11 Apr 2023 08:52:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681228374; cv=none; d=google.com; s=arc-20160816; b=0VR3aJxqmDKUgzy64KP6mRboVSUM4HpU0ZCH57+ju9LNpiLA5pdc8M5aiXsKZoP0wp BBroIMKYXsdO/OJiABMk00i+YeQ0v1JV1ms+vih3s75P4464c0k7TwZk18L7xe0JiXTj 5bNlkW6KgY1RN9QYsIMzhGyOambSrKzQ4Uj3SeoRCrykODSDXJHLOBo5XgZE+jdsz20s Y3IVghdVBIz4wEBl+51Fkznmp+EICsN3yZ6TGkmkqrvytxFz7tEd2EcnocEd5Q6nkZFf KURK0gdq53sUfgm+hmT1x5C8TWLR/z+xbhckIuW2BOo0Zueb5I+PREAuHnjaTwlwWO/Z YbzQ== 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=7DQjB9jjSniX8WUn0hxZzli/VJttza7GiVrQjQV9IoA=; b=xP/vphNPzB98bzP/nC1bMRiOruMwJYC5aOFxoETmOJhY9O6UbPTofoH71U0KCY9qKg IQE6zv2ZcwG3A0+fnBZI+SGxLsS91IExdl+9JYentinupkFY90M+KvonCEeOEx+vZIVv +ggUyzmpWVUevsren36V016ZjcQQyKFCxxsfaSp5pw1FnBxr87RGNdwc3Z7B05xCxAOp BEN/i2e//QgLleYOQG2pIW9BddPaS2A/cMCt1geh2E85SKNBaw+BYaeM4dTbA3/q4Uie jSxQXawt7kDHLdtfRLkUCz+0cG9Ix6WzjjXsP7AcLxm4cAwfrmuRUgJHgCyaOgaPOnkC XUAA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=dpyrf0if; 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 d17-20020a170902b71100b001a500cb53bbsi12829396pls.426.2023.04.11.08.52.42; Tue, 11 Apr 2023 08:52:54 -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=dpyrf0if; 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 S230166AbjDKPwf (ORCPT + 99 others); Tue, 11 Apr 2023 11:52:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39994 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229533AbjDKPwe (ORCPT ); Tue, 11 Apr 2023 11:52:34 -0400 Received: from mail-yb1-xb34.google.com (mail-yb1-xb34.google.com [IPv6:2607:f8b0:4864:20::b34]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2991646B3 for ; Tue, 11 Apr 2023 08:52:33 -0700 (PDT) Received: by mail-yb1-xb34.google.com with SMTP id i20so12334232ybg.10 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=1681228352; x=1683820352; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=7DQjB9jjSniX8WUn0hxZzli/VJttza7GiVrQjQV9IoA=; b=dpyrf0ifpUMeAEvu8Wf578r8CUr/1v6SAD7UgK0B3YcGvaSKQ3g2wlO2F7wbE09ACW +80MxGqHgY9PUMgzKrtA96in292vvDoNetsu6pJHqDaTXVDcvi3MtnqLQvRbFfrpNlAv tPzlU1PvUacXf3sd3OYkdq8l3tlDRsxDMoZKBNZx/SAzrJU1TGZjUnflNmA0x6Y0OIic d2ucXIikHJeU5BYCm6xr1EQNtKZ1uW+nyqt+OCFJ/qE8LtMyQLupVNMTfdiEOgFkyd1T cp3Ih6v/GvBGoKcgEQfJaAUiglhOk/x/Z8zMh/bvqd2VJlzkCgzAX+FN3WJWEsHM5PX/ hW4A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1681228352; x=1683820352; 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=7DQjB9jjSniX8WUn0hxZzli/VJttza7GiVrQjQV9IoA=; b=FSsBACFOimnFrKPF9y4sgpthWUOOfSMB+yw0yKDxaOm7GcDPYNdTWsFr/dy1DdDKSg yYdSEYLsd+uG3j1J8+2THIJvAIAmcdUTylyXfrn0viKpkzH9ilXH3cpvBbQXpcx2k6Rr HqEJiA+f4ePzCv+57h1iADSwDoQV4m9UvPYsfamLc66qPuHNOkicnOmxh6Z9yf8Vswgg yUkX5jDBh6Kca/sGclJnwWAo89eYBZRBpqweOu3No809e3IDI9ustTl5pwLHqYbc98li dOoEiKGDu+WgaeehnnGLhPx9iBD7QG1YM66cZXqqWSLxTf4NrKcWcNblMuC+yOVn4AuS TPmg== X-Gm-Message-State: AAQBX9eCjZsm9h4mlR0KWwVQ37wJ8M+LBIM3/HxiBgPcKITi1JUr4ODv sTc5sYWuF4PPy0BqqwkJByi3mw== X-Received: by 2002:a25:e78e:0:b0:b8e:e4be:923a with SMTP id e136-20020a25e78e000000b00b8ee4be923amr6238760ybh.4.1681228352348; Tue, 11 Apr 2023 08:52:32 -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.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Apr 2023 08:52:31 -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.14 v3 1/5] iio: counter: 104-quad-8: Fix race condition between FLAG and CNTR reads Date: Tue, 11 Apr 2023 11:52:16 -0400 Message-Id: <20230411155220.9754-1-william.gray@linaro.org> X-Mailer: git-send-email 2.39.2 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.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 181585ae6..bdb07694e 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: f03c8bbaf6d9cbebee390e8353c5df75293aff7c -- 2.39.2