Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp118457ybi; Fri, 7 Jun 2019 05:14:40 -0700 (PDT) X-Google-Smtp-Source: APXvYqzBBtfxD2jEswF6vg84R9abbykinSKMBQHiHm0zhpo0VZm1ay8sfXGengZl1KN2u+5PDgo4 X-Received: by 2002:a17:902:bb95:: with SMTP id m21mr56022687pls.154.1559909680496; Fri, 07 Jun 2019 05:14:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1559909680; cv=none; d=google.com; s=arc-20160816; b=VUV9TaYx+4pmQhZXJpX5/pY59s31tm3OQLkuIge5sp1QWyokb/bXUgT5YT595vaa+F LTsNjddlwmSZ7Ec7K3TXGnoXc+T3XFe6BYHNx4f4TNVLlmud6BoKaWnX4fXDxYG9Teis x6TQezRBrI/sS6ylrqTtQMKbruaYXLvMXS0qtJF1PsGdamFgSVcoXBAxWclwKgtAcH2w Hli3WGWAa8yPoT6OnDMWMWiY1cqOKZHRZGiJpn+dlRoCjQYuMAiBI7DR+UhlNic1BI3L SSo+Tc01lTw6cSqPSoe3goEAmoWkSoYW72eQf3rf99i29mBHYEojLkV9cqSnbSnUZja4 ggNQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:references:cc:to:from:subject:dkim-signature; bh=t/Yzpyhe0lIY0ZvNZIHH9Qq5sh9pCp4H8G9Hd8cxDhI=; b=rp7X9bl7muM6bZo8XannzJMS5+1geQT6pginlmc2GlytDYG8ePe/ctRbWEs7dccLUX uorkYEsxVL5ZCaiKBzMLiBr1JqrV2yMgco8WouMV1aFu95snSLTpmIGZXBaqIIK+JTTH +coqzXvsQv6LJWzFqsM1Fu1c3qJon6v7n43bzHn1ll6NitgBknOVhJcNtipIIuD9jvFu gJxIVfjVkZjeceHqoKOsZG8xTQwomAvVAxXdE4u0mD8WgGjPufYCLfGTSjzBm0q3pyWg M8XIXv521IW3paJjAeNRjIpkiKG77z951W1vHbl+W8XcjHELRCwqgCy1iYyRwcFv9T+9 S+iw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=nW5jAgWB; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w129si1543309pfw.149.2019.06.07.05.14.23; Fri, 07 Jun 2019 05:14:40 -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=@gmail.com header.s=20161025 header.b=nW5jAgWB; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728508AbfFGMMo (ORCPT + 99 others); Fri, 7 Jun 2019 08:12:44 -0400 Received: from mail-it1-f196.google.com ([209.85.166.196]:54318 "EHLO mail-it1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727386AbfFGMMo (ORCPT ); Fri, 7 Jun 2019 08:12:44 -0400 Received: by mail-it1-f196.google.com with SMTP id m138so684624ita.4; Fri, 07 Jun 2019 05:12:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:from:to:cc:references:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=t/Yzpyhe0lIY0ZvNZIHH9Qq5sh9pCp4H8G9Hd8cxDhI=; b=nW5jAgWB1sx1YZmfU0tsCeWJgIEQJMqOjIlZhqV2rQnjWjahJrQqKqBSmScAtogxUi XComFFssBR2dJ2kVOLPLxT/EycLlMos1PFNqs9/cJrUJwpXbpIHEsPjLEVcRvztKFsQi G0JjI+CAvPCa6PYDv9y9sCqFp5K+tmor5BynFEz5TFGNd72hS8WVGxzrohe0MWrLwKTM FIe968RzW+iWDgRKb6Vpoitrw3GWqq44bU4VHArurJOyWEQKJz2xzxRlJNVjrQFigSmR 8Iss5qbJ+L83LIkjkRLESHg4zCjtfiAsqlZbEizP4/RDiI7E8W6oPBQdGXAYBqQ5dAoy 5E4A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:from:to:cc:references:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=t/Yzpyhe0lIY0ZvNZIHH9Qq5sh9pCp4H8G9Hd8cxDhI=; b=K4xYPpbX67sAprwAZUiSALQ4Dd9cm06gm4pJmPzrcSDhK64Vt6WKPkaJ7d5gKBzIgT p5ow3lbGvwCauCJNuOScEW3lZGErnxUh51/Iypa3wbA5mZ7A1t7FQwnKPAHiQ6m4X/YY gxys4L18RmSP1NhfcE8DLJx2MZNNPbTtO31z2dPu8XJIO+4nCgrPLgYHA/qurRhXsHxk /iNKNprciaP4UJoFCndivWinNzTKu7jqLBrYCPOF/bZIKs3NvR8KrJbvuKitO++cTpS4 ffhG+KuHTpkGJ4azeHcLlnX0BXNVzyWt9x8nZn3OylD7AAzO4ACJSHGofcykVk0sHA1C nY6w== X-Gm-Message-State: APjAAAVFfPI1IlscGbrRO1jdy7n8PDmIbBMD+QTQjjImD58jkWYeO4NK layxiZMefxLe8pomHY5iJt4= X-Received: by 2002:a02:9a0f:: with SMTP id b15mr1686288jal.32.1559909563311; Fri, 07 Jun 2019 05:12:43 -0700 (PDT) Received: from [192.168.2.145] (ppp91-76-170-54.pppoe.mtu-net.ru. [91.76.170.54]) by smtp.googlemail.com with ESMTPSA id j185sm4707394itj.3.2019.06.07.05.12.40 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 07 Jun 2019 05:12:42 -0700 (PDT) Subject: Re: [PATCH V1 6/6] i2c: tegra: remove BUG, BUG_ON From: Dmitry Osipenko To: Bitan Biswas , Laxman Dewangan , Thierry Reding , Jonathan Hunter , linux-i2c@vger.kernel.org, linux-tegra@vger.kernel.org, linux-kernel@vger.kernel.org, Peter Rosin , Wolfram Sang Cc: Shardar Mohammed , Sowjanya Komatineni , Mantravadi Karthik References: <1559908507-31192-1-git-send-email-bbiswas@nvidia.com> <1559908507-31192-6-git-send-email-bbiswas@nvidia.com> <4aec6d7a-0dea-18c9-efde-96cc1a54b945@gmail.com> Message-ID: <2281ef29-6e69-78e7-4d07-77f33c2f2d5a@gmail.com> Date: Fri, 7 Jun 2019 15:12:39 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.6.1 MIME-Version: 1.0 In-Reply-To: <4aec6d7a-0dea-18c9-efde-96cc1a54b945@gmail.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 07.06.2019 15:08, Dmitry Osipenko пишет: > 07.06.2019 14:55, Bitan Biswas пишет: >> 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 | 15 ++++++++------- >> 1 file changed, 8 insertions(+), 7 deletions(-) >> >> diff --git a/drivers/i2c/busses/i2c-tegra.c b/drivers/i2c/busses/i2c-tegra.c >> index 4dfb4c1..c407bd7 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,7 @@ 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); >> + WARN_ON_ONCE(i2c_dev->msg_buf_remaining); >> complete(&i2c_dev->msg_complete); >> } >> goto done; >> > > Very nice, thank you very much! BTW, I think it may worth to add another > patch that will reset hardware state in a case of the warning since we > know that something gone wrong. > > Reviewed-by: Dmitry Osipenko > Something like that: complete(&i2c_dev->msg_complete); if (WARN_ON_ONCE(i2c_dev->msg_buf_remaining)) goto err;