Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp2822053ybi; Sun, 9 Jun 2019 22:11:18 -0700 (PDT) X-Google-Smtp-Source: APXvYqw6vX+iUknpCVsGWRvHBqI4+KrttMY/GRvuXhjK3STjvtB1Xh52EvOi2wZSjuw86HmpBJ4Y X-Received: by 2002:a62:3283:: with SMTP id y125mr22350964pfy.83.1560143478180; Sun, 09 Jun 2019 22:11:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560143478; cv=none; d=google.com; s=arc-20160816; b=Xxk0ER7PJ0XlbhodwIhIEWz1K5HJG1D/VccSC05TK04XYHOUTQxR8xCR10B2N074Ea gTPn2xoEMDLeBDT5JPa7WZIhNQUUAIyue86WxPCh/6hvpRxJVwvG/NdkP4MfnCmDtW4b VEdXLkG6goCXNOJRkxMN4zwd7ZXi23Ra9HfQgamP6+iHqKEwQWgbJo2EG09nLVGeHYTn KkP6PK24c0oVRU36v1P1J34vgfavxhxB58ZxZqBsbrBN2/unhyvoofOO3YSFVahc8hmg N51sXbbYA4/5G8uvk38TnpX1xL2xnyS5U22c3Y6VYByLHyIiDttVbFqd4iQH54hxEsMN nLnQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:dkim-signature:mime-version:references :in-reply-to:message-id:date:subject:cc:to:from; bh=0cUae7tO9JVjLYIhmSupio08w6fbxlvcuf5mqB5IMx4=; b=EtW18DESyPoi5QblbKENUu6r8b7FoZwgDRksQdHhV7TWxf2pZVIRccOvIM8YnKIm5R g8FR+aWOQF25nDXeXnuL9NcBxCh0pE8IqwE1Z5e/HrsBVGAAYttEt2QqW0yLpMbwhZqg flnP+cSlFeFuU6BMMmbfJJuTKsntEWzFvaTB5/bq7tiQ0JONZP5Nu1QTzuRPf3CBW9NI YjminRL1361zYiX5J2OzRN3GkF6/V4z2GAmgvlyw7sjHWQPtiGLluXzcgprZoHrVP3te nIp7+AtS9LYcLmtWjAX5xjV/NTEgRqVE1MzkrYz20vowIDJgBm6SUJYHOwJ5UR6WB24B kCAw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nvidia.com header.s=n1 header.b=K5SS6Lge; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=nvidia.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k1si7753923pjt.70.2019.06.09.22.11.02; Sun, 09 Jun 2019 22:11:18 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@nvidia.com header.s=n1 header.b=K5SS6Lge; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=nvidia.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387675AbfFJFJR (ORCPT + 99 others); Mon, 10 Jun 2019 01:09:17 -0400 Received: from hqemgate15.nvidia.com ([216.228.121.64]:14320 "EHLO hqemgate15.nvidia.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387452AbfFJFJQ (ORCPT ); Mon, 10 Jun 2019 01:09:16 -0400 Received: from hqpgpgate101.nvidia.com (Not Verified[216.228.121.13]) by hqemgate15.nvidia.com (using TLS: TLSv1.2, DES-CBC3-SHA) id ; Sun, 09 Jun 2019 22:09:14 -0700 Received: from hqmail.nvidia.com ([172.20.161.6]) by hqpgpgate101.nvidia.com (PGP Universal service); Sun, 09 Jun 2019 22:09:15 -0700 X-PGP-Universal: processed; by hqpgpgate101.nvidia.com on Sun, 09 Jun 2019 22:09:15 -0700 Received: from HQMAIL103.nvidia.com (172.20.187.11) by HQMAIL105.nvidia.com (172.20.187.12) with Microsoft SMTP Server (TLS) id 15.0.1473.3; Mon, 10 Jun 2019 05:09:15 +0000 Received: from hqnvemgw02.nvidia.com (172.16.227.111) by HQMAIL103.nvidia.com (172.20.187.11) with Microsoft SMTP Server (TLS) id 15.0.1473.3 via Frontend Transport; Mon, 10 Jun 2019 05:09:15 +0000 Received: from dhcp-10-19-65-14.client.nvidia.com (Not Verified[10.19.65.14]) by hqnvemgw02.nvidia.com with Trustwave SEG (v7,5,8,10121) id ; Sun, 09 Jun 2019 22:09:14 -0700 From: Bitan Biswas To: Laxman Dewangan , Thierry Reding , Jonathan Hunter , , , , Peter Rosin , Wolfram Sang , Dmitry Osipenko CC: Shardar Mohammed , Sowjanya Komatineni , Mantravadi Karthik , Bitan Biswas Subject: [PATCH V3 6/6] i2c: tegra: remove BUG, BUG_ON Date: Sun, 9 Jun 2019 22:08:44 -0700 Message-ID: <1560143324-21754-6-git-send-email-bbiswas@nvidia.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1560143324-21754-1-git-send-email-bbiswas@nvidia.com> References: <1560143324-21754-1-git-send-email-bbiswas@nvidia.com> X-NVConfidentiality: public MIME-Version: 1.0 Content-Type: text/plain DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nvidia.com; s=n1; t=1560143354; bh=0cUae7tO9JVjLYIhmSupio08w6fbxlvcuf5mqB5IMx4=; h=X-PGP-Universal:From:To:CC:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:X-NVConfidentiality:MIME-Version: Content-Type; b=K5SS6LgebxOT5F0Hua41ldzuQ0OtApByg4fJgkUHAuSY7Z/ewp8FNPOnRPLLQ58Is CZawD0wiu1UngYfYcF47m32AIhTbcBMp7xkvtUCsE/mvZc/DZRPBxfB4IrDh1RU4M3 sBpeMWBVu0oSkGruFQk51vPHUyxdGWikWMMUYHsmnNtBIVPA23oIzvzVTdfkYANGa7 ZlfBeeig5q+FYaqUBMltlMSu2cdYXa2ANkBXptGfA8EkN9dAFk4Rk1OAhOwZ4RtHYM KqxX3YXD4pU+D64BzMEZw/nSH3b5/AWy8b3AOaXGa6J+e2o7LFmV869dW4tqnTZ4bE cRT5FWF/4PiKQ== Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Remove redundant BUG_ON calls or replace with WARN_ON_ONCE as needed. Replace BUG() with error handling code. Define I2C_ERR_UNEXPECTED_STATUS for error handling. Signed-off-by: Bitan Biswas --- drivers/i2c/busses/i2c-tegra.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/drivers/i2c/busses/i2c-tegra.c b/drivers/i2c/busses/i2c-tegra.c index 4dfb4c1..d9e99b4 100644 --- a/drivers/i2c/busses/i2c-tegra.c +++ b/drivers/i2c/busses/i2c-tegra.c @@ -73,6 +73,7 @@ #define I2C_ERR_NO_ACK BIT(0) #define I2C_ERR_ARBITRATION_LOST BIT(1) #define I2C_ERR_UNKNOWN_INTERRUPT BIT(2) +#define I2C_ERR_UNEXPECTED_STATUS BIT(3) #define PACKET_HEADER0_HEADER_SIZE_SHIFT 28 #define PACKET_HEADER0_PACKET_ID_SHIFT 16 @@ -515,7 +516,6 @@ static int tegra_i2c_empty_rx_fifo(struct tegra_i2c_dev *i2c_dev) * prevent overwriting past the end of buf */ if (rx_fifo_avail > 0 && buf_remaining > 0) { - BUG_ON(buf_remaining > 3); val = i2c_readl(i2c_dev, I2C_RX_FIFO); val = cpu_to_le32(val); memcpy(buf, &val, buf_remaining); @@ -523,7 +523,6 @@ static int tegra_i2c_empty_rx_fifo(struct tegra_i2c_dev *i2c_dev) rx_fifo_avail--; } - BUG_ON(rx_fifo_avail > 0 && buf_remaining > 0); i2c_dev->msg_buf_remaining = buf_remaining; i2c_dev->msg_buf = buf; @@ -581,7 +580,6 @@ static int tegra_i2c_fill_tx_fifo(struct tegra_i2c_dev *i2c_dev) * boundary and fault. */ if (tx_fifo_avail > 0 && buf_remaining > 0) { - BUG_ON(buf_remaining > 3); memcpy(&val, buf, buf_remaining); val = le32_to_cpu(val); @@ -847,10 +845,13 @@ static irqreturn_t tegra_i2c_isr(int irq, void *dev_id) if (!i2c_dev->is_curr_dma_xfer) { if (i2c_dev->msg_read && (status & I2C_INT_RX_FIFO_DATA_REQ)) { - if (i2c_dev->msg_buf_remaining) + if (i2c_dev->msg_buf_remaining) { tegra_i2c_empty_rx_fifo(i2c_dev); - else - BUG(); + } else { + dev_err(i2c_dev->dev, "unexpected rx data request\n"); + i2c_dev->msg_err |= I2C_ERR_UNEXPECTED_STATUS; + goto err; + } } if (!i2c_dev->msg_read && (status & I2C_INT_TX_FIFO_DATA_REQ)) { @@ -876,7 +877,10 @@ static irqreturn_t tegra_i2c_isr(int irq, void *dev_id) if (status & I2C_INT_PACKET_XFER_COMPLETE) { if (i2c_dev->is_curr_dma_xfer) i2c_dev->msg_buf_remaining = 0; - BUG_ON(i2c_dev->msg_buf_remaining); + if (WARN_ON_ONCE(i2c_dev->msg_buf_remaining)) { + i2c_dev->msg_err |= I2C_ERR_UNKNOWN_INTERRUPT; + goto err; + } complete(&i2c_dev->msg_complete); } goto done; -- 2.7.4