Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp3639226pxb; Mon, 24 Jan 2022 14:09:08 -0800 (PST) X-Google-Smtp-Source: ABdhPJwk0NB4lxkiq3E3hnuU7DuSjjwC2QZTUkhuZ5haSYh/8Z4x+UgJSUAthCyP0OUFE/o7wq2T X-Received: by 2002:a17:902:da81:b0:14b:6084:4292 with SMTP id j1-20020a170902da8100b0014b60844292mr3947280plx.99.1643062148250; Mon, 24 Jan 2022 14:09:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643062148; cv=none; d=google.com; s=arc-20160816; b=vxqv1OH8UBMULbdJ7PQPo8vnZmmcPWyfpNMDD3t8ArZuWSthDKCn2HWXeHVb7Iqujc CZ+KARi3FsOzEsSD9m9vn5fuzsgx0e1QXHYSnWf+xlO6tDkT9/tIndDKQUFPzKReF91e kkjFkvhuc7qOPyq+ttrcp98NA8d+3IAMivfG0+I8/dWQ1P/xnNQ03k6wz5/HMjsyHy7L AhTS5Mmz2OE0ZlcTv064CDo+0wVGF+jmoW3nbsC4WcAungPG2VpxITKwiYYmTZAmOzXM lFkt8ZiwHhiagLzfh3VOR8lAWY5sfnSMSL7RxHdQoV+tFXzNXAMG95w2IKP/6ywC1dq/ QW9w== 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=Fk2jkIh2YOX0/04J7kE7SySQG7CvMFi+BgxJKEINJT14dG41eOPgNz5N+qQ+dwHifr 3CkUOoE1DXAK5QdGOvOTRji4NGzf62LE0QkJAHWOWFdkS1Hb2gbVMReQdNv3f6OzCTUN hc2WEcijLascPUSuPsbgFScBNZskuvZEDb4x230H1pLosb72jJkAeOUqP4Fd8mDxy/3p v9ltJUP/tMD8zQJqLilbYFfOBUoGZqA+/CkaKpuwMCWqho9jgiWHgJzPLBtReov5jHyd YAiEb6JWP5CFd8E5jxezrtVHNcNy+6Zm9v04KuMPKkN/Fx5MtcCxNHw9CBZjMzY3xw6N CvFg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=zmihZBRg; 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 14si4255631pga.682.2022.01.24.14.08.56; Mon, 24 Jan 2022 14:09:08 -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=zmihZBRg; 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 S1577094AbiAXV5S (ORCPT + 99 others); Mon, 24 Jan 2022 16:57:18 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49440 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1449778AbiAXVQ7 (ORCPT ); Mon, 24 Jan 2022 16:16:59 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 269C6C067A44; Mon, 24 Jan 2022 12:12:14 -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 ams.source.kernel.org (Postfix) with ESMTPS id C1B84B8122C; Mon, 24 Jan 2022 20:12:13 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id EEC4EC340E5; Mon, 24 Jan 2022 20:12:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1643055132; bh=bd/N2cLIIyZKGPaNuTPqhxCMHdyWjib1d+RJWqvsz/s=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=zmihZBRgcW7Tb/Y854jNKwCMqVkaEcZ6t9FLXpTNbt9HYhWYH0Ep24E75jMEttPer MUpWPIQHozcB/cpqHnRiBwjR2lVbZcrKrufXH17CPw5lh5+UxcPXJXz+61539u1ZD3 Y/pbEAFSBKBQisjOTm+1AkFlvP1nmhAUZTH+f3t4= 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.15 052/846] media: cec-pin: fix interrupt en/disable handling Date: Mon, 24 Jan 2022 19:32:49 +0100 Message-Id: <20220124184102.754469521@linuxfoundation.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220124184100.867127425@linuxfoundation.org> References: <20220124184100.867127425@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,