From patchwork Thu Apr 12 15:24:08 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mauro Carvalho Chehab X-Patchwork-Id: 10338851 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 7BCED602D8 for ; Thu, 12 Apr 2018 15:24:35 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7179127CEE for ; Thu, 12 Apr 2018 15:24:35 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6636D27EE2; Thu, 12 Apr 2018 15:24:35 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 00A7D27CEE for ; Thu, 12 Apr 2018 15:24:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753996AbeDLPYd (ORCPT ); Thu, 12 Apr 2018 11:24:33 -0400 Received: from osg.samsung.com ([64.30.133.232]:58569 "EHLO osg.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753955AbeDLPYb (ORCPT ); Thu, 12 Apr 2018 11:24:31 -0400 Received: from localhost (localhost [127.0.0.1]) by osg.samsung.com (Postfix) with ESMTP id 513741D001; Thu, 12 Apr 2018 08:24:31 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at dev.s-opensource.com X-Amavis-Alert: BAD HEADER SECTION, Duplicate header field: "References" Received: from osg.samsung.com ([127.0.0.1]) by localhost (localhost [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id HX4pK55C_wnn; Thu, 12 Apr 2018 08:24:30 -0700 (PDT) Received: from smtp.s-opensource.com (unknown [179.179.40.138]) by osg.samsung.com (Postfix) with ESMTPSA id 7ACC21CF4F; Thu, 12 Apr 2018 08:24:13 -0700 (PDT) Received: from mchehab by smtp.s-opensource.com with local (Exim 4.90_1) (envelope-from ) id 1f6e55-0005Sy-CF; Thu, 12 Apr 2018 11:24:11 -0400 From: Mauro Carvalho Chehab Cc: Mauro Carvalho Chehab , Linux Media Mailing List , Mauro Carvalho Chehab Subject: [PATCH 16/17] media: mantis: prevent staying forever in a loop at IRQ Date: Thu, 12 Apr 2018 11:24:08 -0400 Message-Id: <95f98d2a03ff97d82672f5e7d6d2e358e4dd6d17.1523546545.git.mchehab@s-opensource.com> X-Mailer: git-send-email 2.14.3 In-Reply-To: References: In-Reply-To: References: To: unlisted-recipients:; (no To-header on input) Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP As warned by smatch: drivers/media/pci/mantis/mantis_uart.c:105 mantis_uart_work() warn: this loop depends on readl() succeeding If something goes wrong at readl(), the logic will stay there inside an IRQ code forever. This is not the nicest thing to do :-) So, add a timeout there, preventing staying inside the IRQ for more than 10ms. Signed-off-by: Mauro Carvalho Chehab --- drivers/media/pci/mantis/mantis_uart.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/drivers/media/pci/mantis/mantis_uart.c b/drivers/media/pci/mantis/mantis_uart.c index 18f81c135996..b7765687e0c3 100644 --- a/drivers/media/pci/mantis/mantis_uart.c +++ b/drivers/media/pci/mantis/mantis_uart.c @@ -92,6 +92,7 @@ static void mantis_uart_work(struct work_struct *work) { struct mantis_pci *mantis = container_of(work, struct mantis_pci, uart_work); u32 stat; + unsigned long timeout; stat = mmread(MANTIS_UART_STAT); @@ -102,9 +103,15 @@ static void mantis_uart_work(struct work_struct *work) * MANTIS_UART_RXFIFO_DATA is only set if at least * config->bytes + 1 bytes are in the FIFO. */ + + /* FIXME: is 10ms good enough ? */ + timeout = jiffies + msecs_to_jiffies(10); while (stat & MANTIS_UART_RXFIFO_DATA) { mantis_uart_read(mantis); stat = mmread(MANTIS_UART_STAT); + + if (!time_is_after_jiffies(timeout)) + break; } /* re-enable UART (RX) interrupt */