Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp3517794pxf; Mon, 15 Mar 2021 11:18:46 -0700 (PDT) X-Google-Smtp-Source: ABdhPJweY9YF27oMXJZNHYYKgtQz9imy9NRqWd16pW3fI4Hwh0qv4YEDbjN8X2UOGv2kiPhHMtuw X-Received: by 2002:a05:6402:c11:: with SMTP id co17mr32209287edb.246.1615832325991; Mon, 15 Mar 2021 11:18:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1615832325; cv=none; d=google.com; s=arc-20160816; b=koUnRL3/2fSKAdu3KZm4pcmA7r73g1B9B0nv4FVMIWVUeSrmMoqBFtjZovXZA0YutS xu9Y9GTp3NRdn6iB91sMQw/IJsFhJuX1rlueVa+NZGJ2tkDmG0MLUehRPohI1veCRT6K bY11E6lZcssNC32GRJ/RPOVcJkZIy09EaFvRdm/+fDM8nZe5mFONl9x2ri31v36WHQgA 0ouvL9xrhFHCYMD72/5MbydQvChcXcB8QlzbVxW0C/Fr3gN0YD2QgU7y0c46Ehb9bqwa 2WMT469a+xr11vhKQSHdJ+GW314Wad6oNxcQtEM9bfqVWe06GO1X7Pt95vKl7kWtxMsD +qAg== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=CggEdD7sqHxLbyUm/vNAHl0NO6Isw6HZkcwpR9QXS48=; b=ATML1Cgn4H5BPNmljOWsNM7fyeqS5mqKBe5HXrbIKSr/+6gYUSsDKL+DC51QIbR6FN nku8CSmNhBc2+u544/DfYNeLotlq1vAwY/zdV7bxQYUme6vUA37FtSGfIl+DEKDrBndJ BMS5mgZEtuNquBx6mxSyTY0mfnTGlM/itAPBw5txOok32ahaqHi6zycXzhP1lpP5+7TX ktEAhXZpqekOHZeYm6c8eBE/J80fH32m1US5krUYLlsaLZEtpwXa5iHcN0jFzqjZrGby QHaboRm1W2EQIGQbD9GbjatrM4YmzVpLpqjJ/mIeq+mOdN6+MqEOl7aD0UPZ0i0+b5Tb DOYw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=I2Qx8Btd; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id c14si12637177edn.523.2021.03.15.11.18.23; Mon, 15 Mar 2021 11:18:45 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=I2Qx8Btd; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236789AbhCOOQQ (ORCPT + 99 others); Mon, 15 Mar 2021 10:16:16 -0400 Received: from mail.kernel.org ([198.145.29.99]:36788 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232616AbhCON7R (ORCPT ); Mon, 15 Mar 2021 09:59:17 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 054E364F10; Mon, 15 Mar 2021 13:58:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1615816738; bh=469Xir/4E/U2p2kB09zd1A62Y/DTMLcGAJ15ROkZejY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=I2Qx8Btd74zJXw6Fl4RFq8mxbPxWoi7aJ5K61WAjrVDoUkMG459B/VTMsda7FomTw wamxhYBlXMQL/SlFBtqcS7meG3QRTtOZ5a0PbiIZcoTJjBBjz5cTl77AhcLBfS0S1/ dUFXeL+8mbO7fobERSE3KaoHttSqShGBarF2qHAE= From: gregkh@linuxfoundation.org To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, =?UTF-8?q?Ronald=20Tschal=C3=A4r?= , Dmitry Torokhov , Sasha Levin Subject: [PATCH 5.4 077/168] Input: applespi - dont wait for responses to commands indefinitely. Date: Mon, 15 Mar 2021 14:55:09 +0100 Message-Id: <20210315135552.922343791@linuxfoundation.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210315135550.333963635@linuxfoundation.org> References: <20210315135550.333963635@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Greg Kroah-Hartman From: Ronald Tschalär [ Upstream commit 0ce1ac23149c6da939a5926c098c270c58c317a0 ] The response to a command may never arrive or it may be corrupted (and hence dropped) for some reason. While exceedingly rare, when it did happen it blocked all further commands. One way to fix this was to do a suspend/resume. However, recovering automatically seems like a nicer option. Hence this puts a time limit (1 sec) on how long we're willing to wait for a response, after which we assume it got lost. Signed-off-by: Ronald Tschalär Link: https://lore.kernel.org/r/20210217190718.11035-1-ronald@innovation.ch Signed-off-by: Dmitry Torokhov Signed-off-by: Sasha Levin --- drivers/input/keyboard/applespi.c | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/drivers/input/keyboard/applespi.c b/drivers/input/keyboard/applespi.c index d38398526965..a4b7422de534 100644 --- a/drivers/input/keyboard/applespi.c +++ b/drivers/input/keyboard/applespi.c @@ -48,6 +48,7 @@ #include #include #include +#include #include #include #include @@ -400,7 +401,7 @@ struct applespi_data { unsigned int cmd_msg_cntr; /* lock to protect the above parameters and flags below */ spinlock_t cmd_msg_lock; - bool cmd_msg_queued; + ktime_t cmd_msg_queued; enum applespi_evt_type cmd_evt_type; struct led_classdev backlight_info; @@ -716,7 +717,7 @@ static void applespi_msg_complete(struct applespi_data *applespi, wake_up_all(&applespi->drain_complete); if (is_write_msg) { - applespi->cmd_msg_queued = false; + applespi->cmd_msg_queued = 0; applespi_send_cmd_msg(applespi); } @@ -758,8 +759,16 @@ static int applespi_send_cmd_msg(struct applespi_data *applespi) return 0; /* check whether send is in progress */ - if (applespi->cmd_msg_queued) - return 0; + if (applespi->cmd_msg_queued) { + if (ktime_ms_delta(ktime_get(), applespi->cmd_msg_queued) < 1000) + return 0; + + dev_warn(&applespi->spi->dev, "Command %d timed out\n", + applespi->cmd_evt_type); + + applespi->cmd_msg_queued = 0; + applespi->write_active = false; + } /* set up packet */ memset(packet, 0, APPLESPI_PACKET_SIZE); @@ -856,7 +865,7 @@ static int applespi_send_cmd_msg(struct applespi_data *applespi) return sts; } - applespi->cmd_msg_queued = true; + applespi->cmd_msg_queued = ktime_get_coarse(); applespi->write_active = true; return 0; @@ -1908,7 +1917,7 @@ static int __maybe_unused applespi_resume(struct device *dev) applespi->drain = false; applespi->have_cl_led_on = false; applespi->have_bl_level = 0; - applespi->cmd_msg_queued = false; + applespi->cmd_msg_queued = 0; applespi->read_active = false; applespi->write_active = false; -- 2.30.1