Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp4909696rwr; Sun, 23 Apr 2023 16:32:21 -0700 (PDT) X-Google-Smtp-Source: AKy350YhqPN93XDjcF/3RoBacW1/DRs5Yvvo2g3APqMYz/rBmZX/URQfgLsUkERuHtulnv9L2oPG X-Received: by 2002:a05:6a20:9143:b0:f2:bfe1:4865 with SMTP id x3-20020a056a20914300b000f2bfe14865mr9050453pzc.22.1682292740705; Sun, 23 Apr 2023 16:32:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682292740; cv=none; d=google.com; s=arc-20160816; b=qUPUekEKXQ3maJSUOVN20fqedYm2Sxq0dzAudpZ5qIRPADXSAv/Jpxb5Mp2xgxN7pT SKaPTY/yiMkYp+rY+nBE4CoxoHo02vtVV5cyu/LvVojb/YJm/9LkShmYeDNXi3LxYWou QakDr4C3rguAvWK1OsxiGsN6SVh0ciim+1Ebj7HxBuYcW7zsIr/vP09pC+u3Sq1Ac0BM im2wFp4tlRKyas8lelwTlDqKdG7CVCYfCxfPu87qmtfBE52DTFem+GuLG2KzxhrKCctT foez6GWx3f4NJYvDL7jN66xZK58VCtJS8ENNnLi3x2yfIK8tSFLvQsLjOPxUbJij3I9r gyXg== 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=cthSXcBD9iVVm3blHORVesLHvMRZmvd8/QCQdXoEC9w=; b=Mjxxj7KPzZ0TaeUHKBNSGXv51BR0SSppSCEvF4XFxk3poar79wfOuntUXFi4pGybIm lBYIdg7o5hzUlRmBHXIbPaA2WurJzXcvu6WjOYTcsrAlRWTOeo7UDevZieaT0powktHx wv1CSKeIBlhbm4IMSg6R9kjcqxdyniK0d/mXAzMB5mwpTJDYCTyn+FoqFqtTrfJegRg5 KOnFu9Lw2qtW9t4RQQw2pXWZm/DGRr6KrojgknbM2X9JN2G8UOpVA9+4eymq46+1MPY5 sZCHX0QP4yVVMNv05mmsAnP+6I9xZGn11IugpdlMQa6ct06QMlcKOZVbHps2UVvnR0D/ iYmA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=GWjo56mO; 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 68-20020a620647000000b0063b550e6e5fsi9757535pfg.367.2023.04.23.16.32.06; Sun, 23 Apr 2023 16:32:20 -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=GWjo56mO; 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 S230270AbjDWXVK (ORCPT + 99 others); Sun, 23 Apr 2023 19:21:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41496 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230228AbjDWXVA (ORCPT ); Sun, 23 Apr 2023 19:21:00 -0400 Received: from mail-yw1-x1131.google.com (mail-yw1-x1131.google.com [IPv6:2607:f8b0:4864:20::1131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DDEFA1701 for ; Sun, 23 Apr 2023 16:20:58 -0700 (PDT) Received: by mail-yw1-x1131.google.com with SMTP id 00721157ae682-54fb6ac1e44so44171967b3.1 for ; Sun, 23 Apr 2023 16:20:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1682292058; x=1684884058; 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=cthSXcBD9iVVm3blHORVesLHvMRZmvd8/QCQdXoEC9w=; b=GWjo56mOVxMl3/ic3j4OMgChqlqhOWUjboVme/sgNAmexMKgwhq5r3VnqgqBwOG4q2 kxfQtGAfprBou0GxqWhlhL3m6SFg0pdlqdp+yQ7dj7JLoW6ewPrpYepLO2g9/MsDmOJz cVBTVaH8tPsn1xSPdZxgSgARwrwUd7GmJ83/gXesp1mMUv4EEjm+F+cH41TAkrOBmdY+ m/WXjupw6/uCBbQ/EMlT7V33mUMOpAybNRdZeOZUySmMgsi1Sh//waXvkReGkiJMB2HW dnPBZ4Uebcm8Xn89cIrrb18cBkhKcLrVwqLOAtCWZCs6YZf3seZeC3Cr7V9ncqcwVt7T PjFQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682292058; x=1684884058; 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=cthSXcBD9iVVm3blHORVesLHvMRZmvd8/QCQdXoEC9w=; b=l/ZAO9+r08DvuJwSL8PHQ8nMpJAvJ3xpM9SUGI4x2BjSuFTJx0YUrkTyjUvWHmfyIe o1AySFrhuWQyJM7IomFBTQXDajZ/cufP27CsKG75TMMjG0lL5TqeCB4SEpvq1Jy16Mwg AvRaJO+yLcxc+aZi+euNz0E3dfdFxPnTqrSmigRlGk89w1rRpkq4CzWK9Vj4aJc9+ZEK D2pahNyut248ugTJp8RgA2iRA8cnsDSO+rKnJxoZrewJXzPcFxC3SFO7bObgAAGsBi2O Pi3NbmbAA+CVwX0cRnYhmHhvHqqh1o+Gttfr2Z3o2Zkwzttd7KhrvwmDho/EHnOoFopi gYAw== X-Gm-Message-State: AAQBX9cUnGfVHV/t5N5xmRt74evksz+rn8+HwRZ2513IjbV5WIO26nc3 SKcVXz62dtyOXKYxUwqqd91egA== X-Received: by 2002:a81:838b:0:b0:54f:df51:7422 with SMTP id t133-20020a81838b000000b0054fdf517422mr6176587ywf.34.1682292058026; Sun, 23 Apr 2023 16:20:58 -0700 (PDT) Received: from fedora.. ([198.136.190.5]) by smtp.gmail.com with ESMTPSA id z205-20020a0dd7d6000000b0054f856bdc4dsm2607352ywd.38.2023.04.23.16.20.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 23 Apr 2023 16:20:57 -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 5.10 v4 4/5] counter: 104-quad-8: Fix race condition between FLAG and CNTR reads Date: Sun, 23 Apr 2023 19:20:46 -0400 Message-Id: <20230423232047.12589-4-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=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: # 5.10.x Signed-off-by: William Breathitt Gray --- drivers/counter/104-quad-8.c | 18 +++--------------- 1 file changed, 3 insertions(+), 15 deletions(-) diff --git a/drivers/counter/104-quad-8.c b/drivers/counter/104-quad-8.c index 21bb2bb767..1b4fdee9d9 100644 --- a/drivers/counter/104-quad-8.c +++ b/drivers/counter/104-quad-8.c @@ -62,10 +62,6 @@ struct quad8_iio { #define QUAD8_REG_CHAN_OP 0x11 #define QUAD8_REG_INDEX_INPUT_LEVELS 0x16 #define QUAD8_DIFF_ENCODER_CABLE_STATUS 0x17 -/* 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 */ @@ -643,17 +639,9 @@ static int quad8_count_read(struct counter_device *counter, { struct quad8_iio *const priv = counter->priv; const int base_offset = priv->base + 2 * count->id; - unsigned int flags; - unsigned int borrow; - unsigned int carry; int i; - flags = inb(base_offset + 1); - borrow = flags & QUAD8_FLAG_BT; - carry = !!(flags & QUAD8_FLAG_CT); - - /* Borrow XOR Carry effectively doubles count range */ - *val = (unsigned long)(borrow ^ carry) << 24; + *val = 0; mutex_lock(&priv->lock); @@ -1198,8 +1186,8 @@ static ssize_t quad8_count_ceiling_read(struct counter_device *counter, mutex_unlock(&priv->lock); - /* By default 0x1FFFFFF (25 bits unsigned) is maximum count */ - return sprintf(buf, "33554431\n"); + /* By default 0xFFFFFF (24 bits unsigned) is maximum count */ + return sprintf(buf, "16777215\n"); } static ssize_t quad8_count_ceiling_write(struct counter_device *counter, base-commit: 791a854ae5a5f5988f1291ae91168a149bd5ba57 -- 2.40.0