Skip to content

Commit b68d405

Browse files
Hans Verkuilgregkh
authored andcommitted
media: cec: fix the Signal Free Time calculation
commit 7d867a1 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 <hans.verkuil@cisco.com> Cc: <stable@vger.kernel.org> # for v4.18 and up Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 94ec448 commit b68d405

2 files changed

Lines changed: 8 additions & 20 deletions

File tree

‎drivers/media/cec/cec-adap.c‎

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -513,9 +513,11 @@ int cec_thread_func(void *_adap)
513513
if (data->attempts) {
514514
/* should be >= 3 data bit periods for a retry */
515515
signal_free_time = CEC_SIGNAL_FREE_TIME_RETRY;
516-
} else if (data->new_initiator) {
516+
} else if (adap->last_initiator !=
517+
cec_msg_initiator(&data->msg)) {
517518
/* should be >= 5 data bit periods for new initiator */
518519
signal_free_time = CEC_SIGNAL_FREE_TIME_NEW_INITIATOR;
520+
adap->last_initiator = cec_msg_initiator(&data->msg);
519521
} else {
520522
/*
521523
* should be >= 7 data bit periods for sending another
@@ -700,7 +702,6 @@ int cec_transmit_msg_fh(struct cec_adapter *adap, struct cec_msg *msg,
700702
struct cec_fh *fh, bool block)
701703
{
702704
struct cec_data *data;
703-
u8 last_initiator = 0xff;
704705

705706
msg->rx_ts = 0;
706707
msg->tx_ts = 0;
@@ -810,23 +811,6 @@ int cec_transmit_msg_fh(struct cec_adapter *adap, struct cec_msg *msg,
810811
data->adap = adap;
811812
data->blocking = block;
812813

813-
/*
814-
* Determine if this message follows a message from the same
815-
* initiator. Needed to determine the free signal time later on.
816-
*/
817-
if (msg->len > 1) {
818-
if (!(list_empty(&adap->transmit_queue))) {
819-
const struct cec_data *last;
820-
821-
last = list_last_entry(&adap->transmit_queue,
822-
const struct cec_data, list);
823-
last_initiator = cec_msg_initiator(&last->msg);
824-
} else if (adap->transmitting) {
825-
last_initiator =
826-
cec_msg_initiator(&adap->transmitting->msg);
827-
}
828-
}
829-
data->new_initiator = last_initiator != cec_msg_initiator(msg);
830814
init_completion(&data->c);
831815
INIT_DELAYED_WORK(&data->work, cec_wait_timeout);
832816

@@ -1014,6 +998,8 @@ void cec_received_msg_ts(struct cec_adapter *adap,
1014998
mutex_lock(&adap->lock);
1015999
dprintk(2, "%s: %*ph\n", __func__, msg->len, msg->msg);
10161000

1001+
adap->last_initiator = 0xff;
1002+
10171003
/* Check if this message was for us (directed or broadcast). */
10181004
if (!cec_msg_is_broadcast(msg))
10191005
valid_la = cec_has_log_addr(adap, msg_dest);
@@ -1476,6 +1462,8 @@ void __cec_s_phys_addr(struct cec_adapter *adap, u16 phys_addr, bool block)
14761462
}
14771463

14781464
mutex_lock(&adap->devnode.lock);
1465+
adap->last_initiator = 0xff;
1466+
14791467
if ((adap->needs_hpd || list_empty(&adap->devnode.fhs)) &&
14801468
adap->ops->adap_enable(adap, true)) {
14811469
mutex_unlock(&adap->devnode.lock);

‎include/media/cec.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ struct cec_data {
6363
struct delayed_work work;
6464
struct completion c;
6565
u8 attempts;
66-
bool new_initiator;
6766
bool blocking;
6867
bool completed;
6968
};
@@ -174,6 +173,7 @@ struct cec_adapter {
174173
bool is_configuring;
175174
bool is_configured;
176175
bool cec_pin_is_high;
176+
u8 last_initiator;
177177
u32 monitor_all_cnt;
178178
u32 monitor_pin_cnt;
179179
u32 follower_cnt;

0 commit comments

Comments
 (0)