Received: by 2002:a05:6a10:7420:0:0:0:0 with SMTP id hk32csp596083pxb; Tue, 15 Feb 2022 23:14:46 -0800 (PST) X-Google-Smtp-Source: ABdhPJx8E2jSHAb6bMbktnEYuol90qF85rv2JUOLTOs3NE1WcMsz2RlS+NtoRLtW8gZkBkLf4HG4 X-Received: by 2002:a17:902:8e88:b0:14d:66f3:8d71 with SMTP id bg8-20020a1709028e8800b0014d66f38d71mr1069055plb.105.1644995686458; Tue, 15 Feb 2022 23:14:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644995686; cv=none; d=google.com; s=arc-20160816; b=EZrkiiV3cRsRrf48dzXAtMeT4BEd0OFd1rDGcls/upYrgsMZFR9j4fk/+tscjXwq1F M8JxDtabYquSii65XxXH6CWFz43Cqd3AL8aolF0WO4baHSDkuqqdGpmyeevBT/FPAN/7 dKNr5IMAVkD+yVMIRo6Bfi7roMsS/RINQkx8Pv0iT2VbleLK3vxyR6G7COXDN57jDmQL PSwyj8LzuoU5XoBtsB3Cj0CHGhALgsDJRY5oSp3bI9+F8QyzU4+n+er4LxJj4SqZ9LK7 z/6Y65+4dGDlZh3IcaAMiKtCXP4e+6nO6KAELCOcFYK4PJhbF9rdxNFww2rwrxX1vw0z ATgA== 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=vxc40c8+qFTelEOWLtU3Z729xrKZ29GF/czYX3bZY4Y=; b=UMIxB1du+QjIvEvbx2Ky5GAzJXkjcJoh1xzrTu64Tna8rwo7+5R+116W+qWu4h0yMr stUbA36/VzF7PveDXOaPknLnVEC687uf9y4XXC8HS7WqbgLF+a+pt7ipcMycT0JPbmUF 7baY3Mu7JLhJX1TS4PSBYZfNNCGhPFJ78yUU+LpJpeiWJA4r5sqIwSz0djJFQZspuWvR Dhr790tOeSYYWBZ020WqW3GYOatApDPeuHs9NvkRqpjd4FbndHdjjJiH0zJogBvYpEiS lcgn2rUFMRd9tTgwtzNyZd2ZhzTrbfe5/LuSBRqM0t9QLFBT763GPlFDScaFmMrvxjeb hRTg== ARC-Authentication-Results: i=1; mx.google.com; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id b9si27336649pfl.10.2022.02.15.23.14.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Feb 2022 23:14:46 -0800 (PST) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id CA74B1EDA82; Tue, 15 Feb 2022 22:46:59 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236764AbiBOQCn (ORCPT + 99 others); Tue, 15 Feb 2022 11:02:43 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:59276 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241205AbiBOQCg (ORCPT ); Tue, 15 Feb 2022 11:02:36 -0500 Received: from hs01.dk-develop.de (hs01.dk-develop.de [173.249.23.66]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B8E412BD; Tue, 15 Feb 2022 08:02:25 -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 4/4] input: ps2-gpio: don't send rx data before the stop bit Date: Tue, 15 Feb 2022 17:02:08 +0100 Message-Id: <20220215160208.34826-5-danilokrummrich@dk-develop.de> In-Reply-To: <20220215160208.34826-1-danilokrummrich@dk-develop.de> References: <20220215160208.34826-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, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RDNS_NONE, SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no 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 f47a967f7521..17091b137744 100644 --- a/drivers/input/serio/ps2-gpio.c +++ b/drivers/input/serio/ps2-gpio.c @@ -231,6 +231,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. @@ -242,21 +249,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.35.1