Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp3603329pxb; Mon, 24 Jan 2022 13:17:29 -0800 (PST) X-Google-Smtp-Source: ABdhPJwXXBmxoJjES0X3nrICs4VTPjYU2C6eogyqEQQBX8YfI2Zc82Xz6bbdPvYiYqB4jfX/2WLF X-Received: by 2002:a05:6a00:1247:b0:4c0:34b6:ead4 with SMTP id u7-20020a056a00124700b004c034b6ead4mr15530957pfi.68.1643059049154; Mon, 24 Jan 2022 13:17:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643059049; cv=none; d=google.com; s=arc-20160816; b=vbn8af3okMrKcTzbU9q9ZSmKdUo8oCHK2SM3i9bTq+mxBpUSkNUV8BNlRvaCenSBHd OXv/KSMBmatTqZw016Qy2xAPixsRyhw0ST2yz4fU6zePWFyqIFGgDuHK6c/aLD2u1OrI JNv36zPoG9fFcecYdSfLaGg2hf9GxgXmAAH5AOzvzKnmnUXyWbQo3QvKvriOosYc4BuY I4w6cdU6pdlT/LZ10PvxmBs+k2uskcKocyw/09JsWR4rf2OVOtxEm//W8+rspcqsxzcv fDQ7MvW1AiNJQ5f+liFWjBHGkBbJ6KZXJVJXPrKfkX2GWnWZKmiplohxi55/ex832GDa VHRA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=eChIjF7YIK6wmc6imYOYGPKQqrzPkgaZfix/QWeTf0M=; b=NvzqklOvKzF6zSW2dzs202Kl+da93hZiwqV5aupxQaX4u2Ew6+SAKghrcNzqsKtFB0 ryt9eLoejBzhwpuK83DUtL0itT5ZK9cui6GrW1XYpb6dhYYGy3Y+u83Ti45nRORd7/JA f6Fu66uYUAXh63bt2YDyMKCF4jcuOmITEx+Hhxj8/BOZQcCFOQX1pfG82fqenoTHaLWN MCS0P7j2pazJqOOXXqqSNvQ2OOAbWTWZK8LMay0tz3758tm/qAi2zegiAHaKDCtS20Jt xQVsLy5+j4gkZkyWp4qxAQqy5TEtKXrt6aI3CG7+m5Zk4J+l6NBolIVpo8mKXaEbwMOc 9gsA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="B1CnQY/4"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id l10si14454914pfu.149.2022.01.24.13.17.17; Mon, 24 Jan 2022 13:17:29 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="B1CnQY/4"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1358828AbiAXUwK (ORCPT + 99 others); Mon, 24 Jan 2022 15:52:10 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38504 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1359401AbiAXU2c (ORCPT ); Mon, 24 Jan 2022 15:28:32 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D6410C08255D; Mon, 24 Jan 2022 11:42:09 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 604BA614BB; Mon, 24 Jan 2022 19:42:09 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 32E19C340E5; Mon, 24 Jan 2022 19:42:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1643053328; bh=bd/N2cLIIyZKGPaNuTPqhxCMHdyWjib1d+RJWqvsz/s=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=B1CnQY/46BAcieSEx7V8isKRQkMmdCgTxqS9l4YXZMqqkcrwu2ioaki+zauJn34gm oAOrFdB0L+oz9qUVk+aDxUnpn71eSFAL86qzZhsMucztwg5nI4WW4X93EUm5Ybw1nJ AVMRxegdzmvAlKIgpac1zkmXhUvWsSReONsN2dV8= 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.10 029/563] media: cec-pin: fix interrupt en/disable handling Date: Mon, 24 Jan 2022 19:36:34 +0100 Message-Id: <20220124184025.434318930@linuxfoundation.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220124184024.407936072@linuxfoundation.org> References: <20220124184024.407936072@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Hans Verkuil commit 713bdfa10b5957053811470d298def9537d9ff13 upstream. The en/disable_irq() functions keep track of the 'depth': i.e. if interrupts are disabled twice, then it needs to enable_irq() calls to enable them again. The cec-pin framework didn't take this into accound and could disable irqs multiple times, and it expected that a single enable_irq() would enable them again. Move all calls to en/disable_irq() to the kthread where it is easy to keep track of the current irq state and ensure that multiple en/disable_irq calls never happen. If interrupts where disabled twice, then they would never turn on again, leaving the CEC adapter in a dead state. Signed-off-by: Hans Verkuil Fixes: 865463fc03ed (media: cec-pin: add error injection support) Cc: Signed-off-by: Mauro Carvalho Chehab Signed-off-by: Greg Kroah-Hartman --- drivers/media/cec/core/cec-pin.c | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) --- a/drivers/media/cec/core/cec-pin.c +++ b/drivers/media/cec/core/cec-pin.c @@ -1033,6 +1033,7 @@ static int cec_pin_thread_func(void *_ad { struct cec_adapter *adap = _adap; struct cec_pin *pin = adap->pin; + bool irq_enabled = false; for (;;) { wait_event_interruptible(pin->kthread_waitq, @@ -1060,6 +1061,7 @@ static int cec_pin_thread_func(void *_ad ns_to_ktime(pin->work_rx_msg.rx_ts)); msg->len = 0; } + if (pin->work_tx_status) { unsigned int tx_status = pin->work_tx_status; @@ -1083,27 +1085,39 @@ static int cec_pin_thread_func(void *_ad switch (atomic_xchg(&pin->work_irq_change, CEC_PIN_IRQ_UNCHANGED)) { case CEC_PIN_IRQ_DISABLE: - pin->ops->disable_irq(adap); + if (irq_enabled) { + pin->ops->disable_irq(adap); + irq_enabled = false; + } cec_pin_high(pin); cec_pin_to_idle(pin); hrtimer_start(&pin->timer, ns_to_ktime(0), HRTIMER_MODE_REL); break; case CEC_PIN_IRQ_ENABLE: + if (irq_enabled) + break; pin->enable_irq_failed = !pin->ops->enable_irq(adap); if (pin->enable_irq_failed) { cec_pin_to_idle(pin); hrtimer_start(&pin->timer, ns_to_ktime(0), HRTIMER_MODE_REL); + } else { + irq_enabled = true; } break; default: break; } - if (kthread_should_stop()) break; } + if (pin->ops->disable_irq && irq_enabled) + pin->ops->disable_irq(adap); + hrtimer_cancel(&pin->timer); + cec_pin_read(pin); + cec_pin_to_idle(pin); + pin->state = CEC_ST_OFF; return 0; } @@ -1130,13 +1144,7 @@ static int cec_pin_adap_enable(struct ce hrtimer_start(&pin->timer, ns_to_ktime(0), HRTIMER_MODE_REL); } else { - if (pin->ops->disable_irq) - pin->ops->disable_irq(adap); - hrtimer_cancel(&pin->timer); kthread_stop(pin->kthread); - cec_pin_read(pin); - cec_pin_to_idle(pin); - pin->state = CEC_ST_OFF; } return 0; } @@ -1157,11 +1165,8 @@ void cec_pin_start_timer(struct cec_pin if (pin->state != CEC_ST_RX_IRQ) return; - atomic_set(&pin->work_irq_change, CEC_PIN_IRQ_UNCHANGED); - pin->ops->disable_irq(pin->adap); - cec_pin_high(pin); - cec_pin_to_idle(pin); - hrtimer_start(&pin->timer, ns_to_ktime(0), HRTIMER_MODE_REL); + atomic_set(&pin->work_irq_change, CEC_PIN_IRQ_DISABLE); + wake_up_interruptible(&pin->kthread_waitq); } static int cec_pin_adap_transmit(struct cec_adapter *adap, u8 attempts,