diff mbox series

[3/7] cec-adap.c: don't unconfigure if already unconfigured

Message ID 20220510150022.1787112-4-hverkuil-cisco@xs4all.nl
State Accepted
Commit 498946cf6b85b5eafb142132a11351814f578535
Headers show
Series CEC framework fixes | expand

Commit Message

Hans Verkuil May 10, 2022, 3 p.m. UTC
The __cec_s_log_addrs() function can configure or unconfigure the
adapter. The ioctl handler in cec-api.c will prevent it from being
called to configure the adapter if it was already configured (or in
the process of configuring). But it can still be called to unconfigure
an already unconfigured adapter, and it didn't check for that.

This can cause cec_activate_cnt_dec() to be called too often, causing
a WARN_ON.

Instead first check if adap->log_addrs.num_log_addrs == 0 and return
since in that case the adapter is already unconfigured.

Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
---
 drivers/media/cec/core/cec-adap.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/drivers/media/cec/core/cec-adap.c b/drivers/media/cec/core/cec-adap.c
index e789aec7455c..b47280fa3b87 100644
--- a/drivers/media/cec/core/cec-adap.c
+++ b/drivers/media/cec/core/cec-adap.c
@@ -1709,9 +1709,10 @@  int __cec_s_log_addrs(struct cec_adapter *adap,
 		return -ENODEV;
 
 	if (!log_addrs || log_addrs->num_log_addrs == 0) {
-		if (!adap->is_configuring && !adap->is_configured)
+		if (!adap->log_addrs.num_log_addrs)
 			return 0;
-		cec_adap_unconfigure(adap);
+		if (adap->is_configuring || adap->is_configured)
+			cec_adap_unconfigure(adap);
 		adap->log_addrs.num_log_addrs = 0;
 		for (i = 0; i < CEC_MAX_LOG_ADDRS; i++)
 			adap->log_addrs.log_addr[i] = CEC_LOG_ADDR_INVALID;