Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp824401imu; Tue, 11 Dec 2018 08:08:21 -0800 (PST) X-Google-Smtp-Source: AFSGD/VSL5YPV979058nY74y5h5ZUhKMZ8MPHos7MncFMyLOehW+DC7HQcczGuGXsUqjF1OfeLt7 X-Received: by 2002:a63:b105:: with SMTP id r5mr15186231pgf.442.1544544501586; Tue, 11 Dec 2018 08:08:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544544501; cv=none; d=google.com; s=arc-20160816; b=LY1whhXiE8EW8z4k3kuQnsNo+BO/Pp1+zZ9pYoPfvrwot70f124oMg4NUQp2fLM0+D mlgLHHCOHTuRxhGx8raIErnC7MEc6tXsnD8hEnzyt/Wr08HT7sBbum5uighFibDdbMmo GdW6IxPUHDqudeZ++xvn1sAwNSfn3/KsJs29zOErgPoFSHi1b3YUj+G8r4JxoE7LoX8J Ke0+JlzzuVr9qrfLAk2h+oevskqo2UiY4NB4OP996XQLBfMLkxQ+kR+bxxYG9c53ze8B lcFI3xzxpprr7l5FmHnrb0sIksZXoQYh8PtRixkaWGW9jPVK7wAVRapCCgOrlmEM7BsK 4m2w== 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=DwLwPbtM3ELgxdhyjw39loWxv2FQP22CF8wVl/MZVs0=; b=nih7qHQXafW10XIyJuSuUUSxIUt5nw2UYGX5MIUl7SimVPG+TprqZej+AaX0DmzDei KHUWfcel/YY9KyUB6SGI2WyYOZmyQTHO6UCYKqVeItscQX34124joSDimSpuSNmfoxof diMk8dK92cv2TmnD/DYKJKpbLGcjqOCP+CeVWPCcLw498pbZ1HhjM0BDvmcO4HwdzSm/ XmGGl5y6z6j2tjIh7Bj+8VtfQrmRCy9qR/SM2Tom1tegh781wjZxqEoxYVm5GETxOtAo LfeU56j7h6yislCVYBZR7rKCZqp720uCHwZ1u1WPkjtV9QJyv0ZHtlnuRoWzKv9zDl3C l8Rg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=VqWKGYlr; 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 e3si13244275pfe.203.2018.12.11.08.08.06; Tue, 11 Dec 2018 08:08:21 -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=VqWKGYlr; 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 S1730209AbeLKPyi (ORCPT + 99 others); Tue, 11 Dec 2018 10:54:38 -0500 Received: from mail.kernel.org ([198.145.29.99]:43176 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730145AbeLKPye (ORCPT ); Tue, 11 Dec 2018 10:54:34 -0500 Received: from localhost (5356596B.cm-6-7b.dynamic.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 B86032146D; Tue, 11 Dec 2018 15:54:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1544543673; bh=cUuPPYPy2K6QBZr5pyg54aD0xwbXKhmFpY3WWYhaZB4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=VqWKGYlrCLNNbepnf2CaMDwzXXLu0lxUc9XN61pGDSo+XDfI9YRhEcD+PqnZhkwyO 20k4AHS2rXsj+SdcIme3owbXOCEZ+eiNaXRGNplbh8lH/763D25Ela4eCwIidTX3rR VBlKnRrWTsz19hyU+hYdsEjNJVrjwisiaYui37AY= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Hans Verkuil , Hans Verkuil , Mauro Carvalho Chehab , Sasha Levin Subject: [PATCH 4.19 002/118] media: cec: check for non-OK/NACK conditions while claiming a LA Date: Tue, 11 Dec 2018 16:40:21 +0100 Message-Id: <20181211151644.313948188@linuxfoundation.org> X-Mailer: git-send-email 2.20.0 In-Reply-To: <20181211151644.216668863@linuxfoundation.org> References: <20181211151644.216668863@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore 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 4.19-stable review patch. If anyone has any objections, please let me know. ------------------ [ Upstream commit 55623b4169056d7bb493d1c6f715991f8db67302 ] During the configuration phase of a CEC adapter it is trying to claim a free logical address by polling. However, the code doesn't check if there were errors other than OK or NACK, those are just treated as if the poll was NACKed. Instead check for such errors and retry the poll. And if the problem persists then don't claim this LA since there is something weird going on. Signed-off-by: Hans Verkuil Signed-off-by: Hans Verkuil Signed-off-by: Mauro Carvalho Chehab Signed-off-by: Sasha Levin --- drivers/media/cec/cec-adap.c | 47 ++++++++++++++++++++++++++++-------- 1 file changed, 37 insertions(+), 10 deletions(-) diff --git a/drivers/media/cec/cec-adap.c b/drivers/media/cec/cec-adap.c index dd8bad74a1f0..a537e518384b 100644 --- a/drivers/media/cec/cec-adap.c +++ b/drivers/media/cec/cec-adap.c @@ -1167,6 +1167,8 @@ static int cec_config_log_addr(struct cec_adapter *adap, { struct cec_log_addrs *las = &adap->log_addrs; struct cec_msg msg = { }; + const unsigned int max_retries = 2; + unsigned int i; int err; if (cec_has_log_addr(adap, log_addr)) @@ -1175,19 +1177,44 @@ static int cec_config_log_addr(struct cec_adapter *adap, /* Send poll message */ msg.len = 1; msg.msg[0] = (log_addr << 4) | log_addr; - err = cec_transmit_msg_fh(adap, &msg, NULL, true); - /* - * While trying to poll the physical address was reset - * and the adapter was unconfigured, so bail out. - */ - if (!adap->is_configuring) - return -EINTR; + for (i = 0; i < max_retries; i++) { + err = cec_transmit_msg_fh(adap, &msg, NULL, true); - if (err) - return err; + /* + * While trying to poll the physical address was reset + * and the adapter was unconfigured, so bail out. + */ + if (!adap->is_configuring) + return -EINTR; + + if (err) + return err; - if (msg.tx_status & CEC_TX_STATUS_OK) + /* + * The message was aborted due to a disconnect or + * unconfigure, just bail out. + */ + if (msg.tx_status & CEC_TX_STATUS_ABORTED) + return -EINTR; + if (msg.tx_status & CEC_TX_STATUS_OK) + return 0; + if (msg.tx_status & CEC_TX_STATUS_NACK) + break; + /* + * Retry up to max_retries times if the message was neither + * OKed or NACKed. This can happen due to e.g. a Lost + * Arbitration condition. + */ + } + + /* + * If we are unable to get an OK or a NACK after max_retries attempts + * (and note that each attempt already consists of four polls), then + * then we assume that something is really weird and that it is not a + * good idea to try and claim this logical address. + */ + if (i == max_retries) return 0; /* -- 2.19.1