Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3470915imu; Sun, 11 Nov 2018 15:51:56 -0800 (PST) X-Google-Smtp-Source: AJdET5ex7BPSRfXFf+h+8S5s6oJfRDc/3uTzssFfh0+ViFGCKKxU7kN9MhJleDlVYRnqUYB9p9fZ X-Received: by 2002:a62:14d1:: with SMTP id 200mr40349pfu.103.1541980316414; Sun, 11 Nov 2018 15:51:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541980316; cv=none; d=google.com; s=arc-20160816; b=JxSJ5QzNKErL2T0og82JflavIzSqyqJ1KdAXS53Pm2TDQTuVSDFFi9PaIqO2y/g16b QFsHHF9pJ++fjlazWHUZXG1oDDTkC5/mRosXIZLcrbOOyl/LmL0vhSyNuMaUy6WZpLRV XUmDywDdFQbsacboHzfmwVYoferc9NKTItKIxk7Mpi+TLLgC5iPcKdAzwuOrENLJfvJ7 IjmDktLvdvKjhA9nIQmoQrZovZpbgN4oxvjnxEWgdU83xKLojZIalDJJaGIXARbAf5hn RTOZbuNkGiu0X/ZdMQyYY6XzzpUFm+yYbW8P5yCx+imhJZ0trHa0v/deDfYMb0UxctPD i1lw== 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=71NeWEKi1pszt6idtTINdkLQVOOvKIUV7SrZS7ai/8A=; b=w0jrFSFOxoKxvLevb7Rr47MJKWWKTyzjdWw99Q7IXDOVyfRVVDf9Ez1lV9FMXHbwvw YdzD9lmzfAx/ykyiHurzXTe6hUNGBLBDHzuN5EvASfz+kgltO24DCgDNkwjPT7VKc2i/ rW8UcQ9mCF4SMNJ4GRrnK2fc29BBFa8IoZo+nrexOZ5UoNWOWrYshA+9xc7Y0LtQVhjX qaFsz2a+70CeQ8xfjCDWL8sXSuZJ+K8gd5GHO/DC6a03lQBvnx2TgFFvS8GHwdQ6loF5 TwOoj2rWnBKSleBRfIBSPLtV6CCVPLs770HpftlFkIcLqXYCXQYQ6weeLbH4pGdvLHzp BGPw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=azt0ILVY; 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 l11-v6si15828115plt.5.2018.11.11.15.51.41; Sun, 11 Nov 2018 15:51:56 -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=azt0ILVY; 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 S1732912AbeKLISd (ORCPT + 99 others); Mon, 12 Nov 2018 03:18:33 -0500 Received: from mail.kernel.org ([198.145.29.99]:38154 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732860AbeKLISb (ORCPT ); Mon, 12 Nov 2018 03:18:31 -0500 Received: from localhost (unknown [206.108.79.134]) (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 94D042241B; Sun, 11 Nov 2018 22:28:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1541975315; bh=DwpjEVLcEHCD0l5nf1fC23ksVd8HPL3APqAlRfIq4fY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=azt0ILVY67/odkcIPOkYSSGGYD7BlR7juyjRROQNvNm77239nuB6P8ruyTNi/IJPL xqhs48YMoo9tsI/bDvMZBKprH8p/TPeYVFTNXGLMAiDXYxzGq96rPKIsR8fF6ULyzE y9fWTx/khkXQ4iA0IyqHXd50OziYXFRdHfC+I0tM= 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 4.19 303/361] media: cec: fix the Signal Free Time calculation Date: Sun, 11 Nov 2018 14:20:50 -0800 Message-Id: <20181111221657.655086036@linuxfoundation.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181111221619.915519183@linuxfoundation.org> References: <20181111221619.915519183@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review 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. ------------------ From: Hans Verkuil commit 7d867a1b765e2b70815fec4964d7822a976ed349 upstream. The calculation of the Signal Free Time in the framework was not correct. If a message was received, then the next transmit should be considered a New Initiator and use a shorter SFT value. This was not done with the result that if both sides where continually sending messages, they both could use the same SFT value and one side could deny the other side access to the bus. Note that this fix does not take the corner case into account where a receive is in progress when you call adap_transmit. Signed-off-by: Hans Verkuil Cc: # for v4.18 and up Signed-off-by: Mauro Carvalho Chehab Signed-off-by: Greg Kroah-Hartman --- drivers/media/cec/cec-adap.c | 26 +++++++------------------- include/media/cec.h | 2 +- 2 files changed, 8 insertions(+), 20 deletions(-) --- a/drivers/media/cec/cec-adap.c +++ b/drivers/media/cec/cec-adap.c @@ -513,9 +513,11 @@ int cec_thread_func(void *_adap) if (data->attempts) { /* should be >= 3 data bit periods for a retry */ signal_free_time = CEC_SIGNAL_FREE_TIME_RETRY; - } else if (data->new_initiator) { + } else if (adap->last_initiator != + cec_msg_initiator(&data->msg)) { /* should be >= 5 data bit periods for new initiator */ signal_free_time = CEC_SIGNAL_FREE_TIME_NEW_INITIATOR; + adap->last_initiator = cec_msg_initiator(&data->msg); } else { /* * should be >= 7 data bit periods for sending another @@ -700,7 +702,6 @@ int cec_transmit_msg_fh(struct cec_adapt struct cec_fh *fh, bool block) { struct cec_data *data; - u8 last_initiator = 0xff; msg->rx_ts = 0; msg->tx_ts = 0; @@ -810,23 +811,6 @@ int cec_transmit_msg_fh(struct cec_adapt data->adap = adap; data->blocking = block; - /* - * Determine if this message follows a message from the same - * initiator. Needed to determine the free signal time later on. - */ - if (msg->len > 1) { - if (!(list_empty(&adap->transmit_queue))) { - const struct cec_data *last; - - last = list_last_entry(&adap->transmit_queue, - const struct cec_data, list); - last_initiator = cec_msg_initiator(&last->msg); - } else if (adap->transmitting) { - last_initiator = - cec_msg_initiator(&adap->transmitting->msg); - } - } - data->new_initiator = last_initiator != cec_msg_initiator(msg); init_completion(&data->c); INIT_DELAYED_WORK(&data->work, cec_wait_timeout); @@ -1014,6 +998,8 @@ void cec_received_msg_ts(struct cec_adap mutex_lock(&adap->lock); dprintk(2, "%s: %*ph\n", __func__, msg->len, msg->msg); + adap->last_initiator = 0xff; + /* Check if this message was for us (directed or broadcast). */ if (!cec_msg_is_broadcast(msg)) valid_la = cec_has_log_addr(adap, msg_dest); @@ -1476,6 +1462,8 @@ void __cec_s_phys_addr(struct cec_adapte } mutex_lock(&adap->devnode.lock); + adap->last_initiator = 0xff; + if ((adap->needs_hpd || list_empty(&adap->devnode.fhs)) && adap->ops->adap_enable(adap, true)) { mutex_unlock(&adap->devnode.lock); --- a/include/media/cec.h +++ b/include/media/cec.h @@ -63,7 +63,6 @@ struct cec_data { struct delayed_work work; struct completion c; u8 attempts; - bool new_initiator; bool blocking; bool completed; }; @@ -174,6 +173,7 @@ struct cec_adapter { bool is_configuring; bool is_configured; bool cec_pin_is_high; + u8 last_initiator; u32 monitor_all_cnt; u32 monitor_pin_cnt; u32 follower_cnt;