Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp4822473pxb; Sat, 12 Feb 2022 21:06:40 -0800 (PST) X-Google-Smtp-Source: ABdhPJwAsc8AON6aSUiZkRaG2z8IXWGMorearw9fhk12XA9nZncalZyvsvKJnkeA2JOAJeXl7bmW X-Received: by 2002:a63:4656:: with SMTP id v22mr6868483pgk.604.1644728800430; Sat, 12 Feb 2022 21:06:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644728800; cv=none; d=google.com; s=arc-20160816; b=pQM29b83ne4MHjaYiSoIZZ1ZTNazZsnWwHZTAVBbQ7dKC4URuNisq6UJ59H/TG7NHj lPRg5nJbbcpN6R9sGY6sO4ahJYt0eTJ3Z5x11AbJCDky7/Ar+8P2KShsGi7RE6UfcmBY KXOcbhhzZRhL5p/zCKor16Bu9tXuCOsSdSpKeR6BGjPTTACSufVUQBF+NGfyAZwl1O86 tQmiUXNbZFLf2aC/3yqB3Bqm6P3JNTtBLQmEhPo8++zhsQvPhvqQsogOmEbk4VUQKLuY XI4gcmaz3GiIgdvkl9sBBkAdVSJJcAX4F0SNnrLLXsuE96B38khbe+c1niZHW5L69URJ 4IsA== 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; bh=uBkXWyPJe9qC/PtE1Zgx0CM2bZwSm9Hw3WNDrTwyFtY=; b=IRiAvlT3J6LGY2j5kLBbEyf2v1TJ+kt4FAwXX2YzY5arGKl7HLsvcMwXJ9UhedTR4a oauefMKL3Yo0FxG/FYF0ZCsVb3hXQ2x++x/8TdHE/6e0zjVTBuP0PZNryhwyo1ldCkN0 cZfquQ9TvW6wUAIXRwqkwla6eLBH7gZd03GjiJ6YBM6Fn8l/PAv9Py1Y83YHUQvOgybF MevBTAapfS9aVvH8gzTvWR+dBUVB4FJL3uhHRrZX/SIh4uq+JjGGusv21Y/mK/YyozvD GSyhvzGaj3BMmihh6LNgAgZXe75neFNea2/4hF0SPweGCtRhKfmt0XCPxPqt5/xx/qtq XLtA== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j9si26713400pfu.84.2022.02.12.21.06.27; Sat, 12 Feb 2022 21:06:40 -0800 (PST) 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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1353722AbiBKVXR (ORCPT + 93 others); Fri, 11 Feb 2022 16:23:17 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:46110 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1353671AbiBKVXM (ORCPT ); Fri, 11 Feb 2022 16:23:12 -0500 Received: from hs01.dk-develop.de (hs01.dk-develop.de [IPv6:2a02:c207:3002:6234::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DCC7C2E7 for ; Fri, 11 Feb 2022 13:23:10 -0800 (PST) From: Danilo Krummrich To: dmitry.torokhov@gmail.com, linux-input@vger.kernel.org, linux-kernel@vger.kernel.org Cc: linus.walleij@linaro.org, Danilo Krummrich Subject: [PATCH 3/3] input: ps2-gpio: don't send rx data before the stop bit Date: Fri, 11 Feb 2022 22:22:58 +0100 Message-Id: <20220211212258.80345-4-danilokrummrich@dk-develop.de> In-Reply-To: <20220211212258.80345-1-danilokrummrich@dk-develop.de> References: <20220211212258.80345-1-danilokrummrich@dk-develop.de> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,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 Sending the data before processing the stop bit from the device already saves the data of the current xfer in case the stop bit is missed. However, when TX xfers are enabled this introduces a race condition when a peripheral driver using the bus immediately requests a TX xfer from IRQ context. Therefore the data must be send after receiving the stop bit, although it is possible the data is lost when missing the stop bit. Signed-off-by: Danilo Krummrich --- drivers/input/serio/ps2-gpio.c | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/drivers/input/serio/ps2-gpio.c b/drivers/input/serio/ps2-gpio.c index 336928a8a127..460d520ac865 100644 --- a/drivers/input/serio/ps2-gpio.c +++ b/drivers/input/serio/ps2-gpio.c @@ -217,6 +217,13 @@ static irqreturn_t ps2_gpio_irq_rx(struct ps2_gpio_data *drvdata) if (!drvdata->write_enable) goto err; } + break; + case PS2_STOP_BIT: + /* stop bit should be high */ + if (unlikely(!data)) { + dev_err(drvdata->dev, "RX: stop bit should be high\n"); + goto err; + } /* Do not send spurious ACK's and NACK's when write fn is * not provided. @@ -228,21 +235,9 @@ static irqreturn_t ps2_gpio_irq_rx(struct ps2_gpio_data *drvdata) break; } - /* Let's send the data without waiting for the stop bit to be - * sent. It may happen that we miss the stop bit. When this - * happens we have no way to recover from this, certainly - * missing the parity bit would be recognized when processing - * the stop bit. When missing both, data is lost. - */ serio_interrupt(drvdata->serio, byte, rxflags); dev_dbg(drvdata->dev, "RX: sending byte 0x%x\n", byte); - break; - case PS2_STOP_BIT: - /* stop bit should be high */ - if (unlikely(!data)) { - dev_err(drvdata->dev, "RX: stop bit should be high\n"); - goto err; - } + cnt = byte = 0; goto end; /* success */ -- 2.34.1