From patchwork Wed Dec 30 16:46:29 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heiner Kallweit X-Patchwork-Id: 7934281 Return-Path: X-Original-To: patchwork-linux-media@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 0493F9F387 for ; Wed, 30 Dec 2015 16:47:13 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 20D71202FE for ; Wed, 30 Dec 2015 16:47:12 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 30EB0202EB for ; Wed, 30 Dec 2015 16:47:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755039AbbL3QrG (ORCPT ); Wed, 30 Dec 2015 11:47:06 -0500 Received: from mail-wm0-f44.google.com ([74.125.82.44]:34535 "EHLO mail-wm0-f44.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754879AbbL3QrB (ORCPT ); Wed, 30 Dec 2015 11:47:01 -0500 Received: by mail-wm0-f44.google.com with SMTP id u188so44572938wmu.1 for ; Wed, 30 Dec 2015 08:47:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:subject:to:cc:message-id:date:user-agent:mime-version :content-type:content-transfer-encoding; bh=4sj5bqiQaAluHnatYyT6nroX/aFAtq5V/dnKfKB+3uA=; b=jXN+WmPwfbWpB5/HVfvuSmAcC6l9gdkf5EO4oec7b8KN8iHjD3enSANpxpHuABvhGe cdbCWnV8M/SulYMV2T7sCSO5u0DDFT64OvXfXsccz6Ih9ldFKwK83pZlLZqHzsCtwy0v 36nbwjRyT0JG5/sJWWdiqeaCnlPUBxrWO60Kf/BF1ACbYzLIwiC9iNjR80Tf+EqMsMlL 3H1/A/MYVMWS+w5H72cGzNSeh/hSgVjA90TUokf9oDTT998R0+3wDQUaKfGCc9KWRZH3 DBkGuD1eSf4NJIlw9ApKW3XbkNYZBoi93eTi1uTkBsBNE44kMw5zvQFkf+2kFu7zimLx sIhw== X-Received: by 10.194.87.201 with SMTP id ba9mr72238997wjb.125.1451494020035; Wed, 30 Dec 2015 08:47:00 -0800 (PST) Received: from ?IPv6:2003:62:5f55:ba00:84bb:b7f:fe67:66b9? (p200300625F55BA0084BB0B7FFE6766B9.dip0.t-ipconnect.de. [2003:62:5f55:ba00:84bb:b7f:fe67:66b9]) by smtp.googlemail.com with ESMTPSA id w73sm44528263wmw.21.2015.12.30.08.46.59 (version=TLSv1/SSLv3 cipher=OTHER); Wed, 30 Dec 2015 08:46:59 -0800 (PST) From: Heiner Kallweit Subject: [PATCH 16/16] media: rc: nuvoton-cir: improve locking in both interrupt handlers To: Mauro Carvalho Chehab Cc: linux-media@vger.kernel.org Message-ID: <56840A65.5060100@gmail.com> Date: Wed, 30 Dec 2015 17:46:29 +0100 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:38.0) Gecko/20100101 Thunderbird/38.5.0 MIME-Version: 1.0 Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Extend the locking to protect more critical actions like register accesses in the interrupt handlers. Signed-off-by: Heiner Kallweit --- drivers/media/rc/nuvoton-cir.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/drivers/media/rc/nuvoton-cir.c b/drivers/media/rc/nuvoton-cir.c index c0bee1e..b6acc84 100644 --- a/drivers/media/rc/nuvoton-cir.c +++ b/drivers/media/rc/nuvoton-cir.c @@ -727,7 +727,6 @@ static void nvt_handle_rx_fifo_overrun(struct nvt_dev *nvt) /* copy data from hardware rx fifo into driver buffer */ static void nvt_get_rx_ir_data(struct nvt_dev *nvt) { - unsigned long flags; u8 fifocount, val; unsigned int b_idx; bool overrun = false; @@ -746,8 +745,6 @@ static void nvt_get_rx_ir_data(struct nvt_dev *nvt) nvt_dbg("attempting to fetch %u bytes from hw rx fifo", fifocount); - spin_lock_irqsave(&nvt->nvt_lock, flags); - b_idx = nvt->pkts; /* This should never happen, but lets check anyway... */ @@ -769,8 +766,6 @@ static void nvt_get_rx_ir_data(struct nvt_dev *nvt) if (overrun) nvt_handle_rx_fifo_overrun(nvt); - - spin_unlock_irqrestore(&nvt->nvt_lock, flags); } static void nvt_cir_log_irqs(u8 status, u8 iren) @@ -811,6 +806,8 @@ static irqreturn_t nvt_cir_isr(int irq, void *data) nvt_dbg_verbose("%s firing", __func__); + spin_lock_irqsave(&nvt->nvt_lock, flags); + /* * Get IR Status register contents. Write 1 to ack/clear * @@ -831,6 +828,7 @@ static irqreturn_t nvt_cir_isr(int irq, void *data) * status bit whether the related interrupt source is enabled */ if (!(status & iren)) { + spin_unlock_irqrestore(&nvt->nvt_lock, flags); nvt_dbg_verbose("%s exiting, IRSTS 0x0", __func__); return IRQ_NONE; } @@ -852,16 +850,14 @@ static irqreturn_t nvt_cir_isr(int irq, void *data) if (nvt_cir_tx_inactive(nvt)) nvt_get_rx_ir_data(nvt); - spin_lock_irqsave(&nvt->nvt_lock, flags); - cur_state = nvt->study_state; - spin_unlock_irqrestore(&nvt->nvt_lock, flags); - if (cur_state == ST_STUDY_NONE) nvt_clear_cir_fifo(nvt); } + spin_unlock_irqrestore(&nvt->nvt_lock, flags); + if (status & CIR_IRSTS_TE) nvt_clear_tx_fifo(nvt); @@ -910,14 +906,18 @@ static irqreturn_t nvt_cir_wake_isr(int irq, void *data) nvt_dbg_wake("%s firing", __func__); + spin_lock_irqsave(&nvt->nvt_lock, flags); + status = nvt_cir_wake_reg_read(nvt, CIR_WAKE_IRSTS); iren = nvt_cir_wake_reg_read(nvt, CIR_WAKE_IREN); /* IRQ may be shared with CIR, therefore check for each * status bit whether the related interrupt source is enabled */ - if (!(status & iren)) + if (!(status & iren)) { + spin_unlock_irqrestore(&nvt->nvt_lock, flags); return IRQ_NONE; + } if (status & CIR_WAKE_IRSTS_IR_PENDING) nvt_clear_cir_wake_fifo(nvt); @@ -933,11 +933,11 @@ static irqreturn_t nvt_cir_wake_isr(int irq, void *data) } nvt_cir_wake_reg_write(nvt, 0, CIR_WAKE_IREN); - spin_lock_irqsave(&nvt->nvt_lock, flags); nvt->wake_state = ST_WAKE_FINISH; - spin_unlock_irqrestore(&nvt->nvt_lock, flags); } + spin_unlock_irqrestore(&nvt->nvt_lock, flags); + nvt_dbg_wake("%s done", __func__); return IRQ_HANDLED; }