Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp587475ybi; Fri, 7 Jun 2019 13:10:16 -0700 (PDT) X-Google-Smtp-Source: APXvYqwoR4TumQby3nX4TJbVA33fkuM0DaxIULOQ0Wy4KdPXIZn/osIm5Y/fo2dlWGorYucE72N0 X-Received: by 2002:a63:2248:: with SMTP id t8mr4692549pgm.358.1559938216305; Fri, 07 Jun 2019 13:10:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1559938216; cv=none; d=google.com; s=arc-20160816; b=tyBZw/x1TBS5GbyIZleB+EkQWr7AA4ONfHBJhCeiO/dSnuH1Gv/fMsB32SftciJxGX 2igcGRlC1KQZTqUt99Reo9xw7fxE7N1J00c7QVezKfBZ17FRFSAMZS04xge0pR4uqbex vr7yEbdRwzDgzUjZGJh2Ac/sI6noxQE00G5/CAVv+u5m/8924347Wc15mtNzH+nIR5sT KtDTVzK7BWhIRpO8xJUS3vqJ88H+xBvlZEybpORBh5vHkXT3B98kL21PkUxZRodHgOwe TKUBIrlyoEwcPAruh7POPAk0JAupTJ6EMkhahmcsTBkH6varcj2vLchXC1dO68Z06jNo TAyw== 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=icHCoVWWAk65FIBfKx11X1SnYaaUc2ZAhGg31YXnuZM=; b=V9yxzsqDvsIHfiyc8gjK8uJ5fJXUni26luqC1ZvLJNDvsfnL4SuunwBXWzm14CA1MT 89Wwxk0ROGtxirVh6waf8t8AlMf3YIxICFKfOXoAYUqA1GaCkNAaPhu/VPSLPZ5M3rRw ddLcQSm8qx/e5OAvl+ssWGbuyU91CpdhE3fLlLHYK+5KUeHlQQdcNY13lp3P2vdHK7rt 7hdE6rWIrsVgOsuBpJQUChIMwiaVTtdKsL/cu1SrQUWAstESHlXXH4DRHjnmEaOLT1WU cUzFHmbsxCzWjkpcLwxOrsg2RpJLGXjAx6+dFMZnMnpgS60DIKnqhmJL61wH3JmDvwQm QrEw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nvidia.com header.s=n1 header.b=IZV3Lkdq; 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 23si3229380pjx.87.2019.06.07.13.09.59; Fri, 07 Jun 2019 13:10:16 -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=IZV3Lkdq; 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 S1730559AbfFGTaz (ORCPT + 99 others); Fri, 7 Jun 2019 15:30:55 -0400 Received: from hqemgate16.nvidia.com ([216.228.121.65]:19969 "EHLO hqemgate16.nvidia.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729172AbfFGTaw (ORCPT ); Fri, 7 Jun 2019 15:30:52 -0400 Received: from hqpgpgate101.nvidia.com (Not Verified[216.228.121.13]) by hqemgate16.nvidia.com (using TLS: TLSv1.2, DES-CBC3-SHA) id ; Fri, 07 Jun 2019 12:30:51 -0700 Received: from hqmail.nvidia.com ([172.20.161.6]) by hqpgpgate101.nvidia.com (PGP Universal service); Fri, 07 Jun 2019 12:30:51 -0700 X-PGP-Universal: processed; by hqpgpgate101.nvidia.com on Fri, 07 Jun 2019 12:30:51 -0700 Received: from HQMAIL103.nvidia.com (172.20.187.11) by HQMAIL101.nvidia.com (172.20.187.10) with Microsoft SMTP Server (TLS) id 15.0.1473.3; Fri, 7 Jun 2019 19:30:51 +0000 Received: from hqnvemgw01.nvidia.com (172.20.150.20) by HQMAIL103.nvidia.com (172.20.187.11) with Microsoft SMTP Server (TLS) id 15.0.1473.3 via Frontend Transport; Fri, 7 Jun 2019 19:30:51 +0000 Received: from dhcp-10-19-65-14.client.nvidia.com (Not Verified[10.19.65.14]) by hqnvemgw01.nvidia.com with Trustwave SEG (v7,5,8,10121) id ; Fri, 07 Jun 2019 12:30:50 -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 V2 6/6] i2c: tegra: remove BUG, BUG_ON Date: Fri, 7 Jun 2019 12:30:26 -0700 Message-ID: <1559935826-25812-6-git-send-email-bbiswas@nvidia.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1559935826-25812-1-git-send-email-bbiswas@nvidia.com> References: <1559935826-25812-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=1559935851; bh=icHCoVWWAk65FIBfKx11X1SnYaaUc2ZAhGg31YXnuZM=; h=X-PGP-Universal:From:To:CC:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:X-NVConfidentiality:MIME-Version: Content-Type; b=IZV3LkdqNpg9wHsuEOSIFgR/Y8kHEGmld40SV5422CUPsnEEq3NyaE8L+tbkjirva UMP/RZWdQ7XfU2BaafCAM9a7CDFVs3M1T1bINvtkgTJNVIvBWniV4qT9QxqS+wtOD9 6Bea4aGhol+RwEhKVaSf/CyUSGQCE2sd0/Ad0zo12C3gdREttguKyO72fNMisB8dO0 EEuopYPyG6iTVUCcwM77uEP8FNKII1ISt07R/KR2EsvnuILdai5sJTbpLpPvwGbeaY lvQ1OwFyts4zX8CaCe4/iAwutiQ6FTW0VJJR7sAXE9oLH1MelaxYxWhlHCYJDUw1lq Gm8ctNJKb6Q1Q== 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 | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/drivers/i2c/busses/i2c-tegra.c b/drivers/i2c/busses/i2c-tegra.c index 4dfb4c1..c89d0ee 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,8 @@ 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)) + goto err; complete(&i2c_dev->msg_complete); } goto done; -- 2.7.4