Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp27910ybl; Tue, 7 Jan 2020 13:25:35 -0800 (PST) X-Google-Smtp-Source: APXvYqzxuc9of4oitRX9GplW+NmfZi/l+RVXV8T+gu8lt5uptnIjTWnMQKqcgUheUCkhou9/9XqZ X-Received: by 2002:a05:6830:1116:: with SMTP id w22mr1765283otq.63.1578432335860; Tue, 07 Jan 2020 13:25:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1578432335; cv=none; d=google.com; s=arc-20160816; b=C2cPuCyZZvtNtMnS4RADOFhFU+W7ouLhocHPXlOx0o8UBqfRSX0p7vxPRXvZFsq1Ul 8buaw/845bhu2Qa2CnPEJqCmi45039Y6Sv466JRjA73QoXqkWCy81MJg5z8zVaiFDY4e JsnNE/0tc6M0QiIjVzx/LCf+Up/n0CyhQ9sULCNKFVwFTRsSS6cJKJdm5lEHLMnEbo2B TdXe840dL7aW+ZAUc3fLvURHp2FQUhzFPCZs5LOyNor4UoD/u02rfqKFRK5CqqUNJkc8 Lpo453V5GcSV3JSQAwQ2gtW7ko3BMwn7YGuZNQKVZofeMDR1YT9BLxhswDEaBrf+IEDy L15g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=kG8T4n9DSC3QJIlhugQrFpWiLAGA84N8Hoy0J3R2h4U=; b=Ac0CsWOwV3prEahPT/Dxhhrlr1yNAbeYYFSPWC+zNeNps7uaUoVOJ0L+vyuLB4sCkA pf0hxcH3toLJehs9gofV4tGAD+Te9L2dDHqC6kIgZkfnwwFFnmd2I71uudeNwcayvDSt Fs66op65uXpJnjVr4c8ynYWXVQFc4XG664WOlWXopDrCloeylDbKK0oGC9kOR34qt4LZ WRJ04zBS6oQJ3nVOrv18EbnHm/SNCEnptLPigfbMQ9YT2tnstm3Uy7nPyYu+nC4at/8D SNqNx9q4TFP1Dsj6Wv2yG8s0u1mdGnsO2YfN/E3dPgIe7p9ogrWJ9wL7pzIzx7lv+8nk R6ew== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=XFIGlIEx; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g126si659259oif.106.2020.01.07.13.25.23; Tue, 07 Jan 2020 13:25:35 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=XFIGlIEx; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728879AbgAGVXr (ORCPT + 99 others); Tue, 7 Jan 2020 16:23:47 -0500 Received: from mail.kernel.org ([198.145.29.99]:37782 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727267AbgAGVBI (ORCPT ); Tue, 7 Jan 2020 16:01:08 -0500 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id E2E3224656; Tue, 7 Jan 2020 21:01:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1578430867; bh=I5bT0UnOd1vvZOD2Zxl7tad9MKt1oDNX/jejXGiWtr8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XFIGlIExJm01kGZv9gcjaH2b5c/Dts/GH1prcdK1n/84c1Kq+vZrNde7TsWLzWfj9 NmU80nnpq6keK+AwIMNElKNdUgwDVu6zWyj7QJxPbj5BJjsSejRFJf9CvaN77g6IXn 5YCtpC5eI3Kz7Kndm9GvLntkcsea314pTCwQAIHQ= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Hans Verkuil , Mauro Carvalho Chehab Subject: [PATCH 5.4 082/191] media: cec: check transmit_in_progress, not transmitting Date: Tue, 7 Jan 2020 21:53:22 +0100 Message-Id: <20200107205337.370595839@linuxfoundation.org> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200107205332.984228665@linuxfoundation.org> References: <20200107205332.984228665@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Hans Verkuil commit ac479b51f3f4aaa852b5d3f00ecfb9290230cf64 upstream. Currently wait_event_interruptible_timeout is called in cec_thread_func() when adap->transmitting is set. But if the adapter is unconfigured while transmitting, then adap->transmitting is set to NULL. But the hardware is still actually transmitting the message, and that's indicated by adap->transmit_in_progress and we should wait until that is finished or times out before transmitting new messages. As the original commit says: adap->transmitting is the userspace view, adap->transmit_in_progress reflects the hardware state. However, if adap->transmitting is NULL and adap->transmit_in_progress is true, then wait_event_interruptible is called (no timeout), which can get stuck indefinitely if the CEC driver is flaky and never marks the transmit-in-progress as 'done'. So test against transmit_in_progress when deciding whether to use the timeout variant or not, instead of testing against adap->transmitting. Signed-off-by: Hans Verkuil Fixes: 32804fcb612b ("media: cec: keep track of outstanding transmits") Cc: # for v4.19 and up Signed-off-by: Mauro Carvalho Chehab Signed-off-by: Greg Kroah-Hartman --- drivers/media/cec/cec-adap.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) --- a/drivers/media/cec/cec-adap.c +++ b/drivers/media/cec/cec-adap.c @@ -463,7 +463,7 @@ int cec_thread_func(void *_adap) bool timeout = false; u8 attempts; - if (adap->transmitting) { + if (adap->transmit_in_progress) { int err; /* @@ -498,7 +498,7 @@ int cec_thread_func(void *_adap) goto unlock; } - if (adap->transmitting && timeout) { + if (adap->transmit_in_progress && timeout) { /* * If we timeout, then log that. Normally this does * not happen and it is an indication of a faulty CEC @@ -507,14 +507,18 @@ int cec_thread_func(void *_adap) * so much traffic on the bus that the adapter was * unable to transmit for CEC_XFER_TIMEOUT_MS (2.1s). */ - pr_warn("cec-%s: message %*ph timed out\n", adap->name, - adap->transmitting->msg.len, - adap->transmitting->msg.msg); + if (adap->transmitting) { + pr_warn("cec-%s: message %*ph timed out\n", adap->name, + adap->transmitting->msg.len, + adap->transmitting->msg.msg); + /* Just give up on this. */ + cec_data_cancel(adap->transmitting, + CEC_TX_STATUS_TIMEOUT); + } else { + pr_warn("cec-%s: transmit timed out\n", adap->name); + } adap->transmit_in_progress = false; adap->tx_timeouts++; - /* Just give up on this. */ - cec_data_cancel(adap->transmitting, - CEC_TX_STATUS_TIMEOUT); goto unlock; }