Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp173078ybi; Fri, 7 Jun 2019 06:13:21 -0700 (PDT) X-Google-Smtp-Source: APXvYqxkhi9/nGYroSdxCHy/ED2j/PZfcIRNg2BEk2tfSpqzFIcTBWYAMtQcKt4qGjYp/R095IvV X-Received: by 2002:a17:902:f087:: with SMTP id go7mr29584774plb.330.1559913201599; Fri, 07 Jun 2019 06:13:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1559913201; cv=none; d=google.com; s=arc-20160816; b=wpAObqTu8UWOt8b4/SNld9HflrnFVTKXvUkZqJr42y+sKpXvuiDqYqiMie4+3xv5Fx DVASl0AzF0hXROQpHVvJGQFVvm8VGNamprQe9VeNd2JBSKl5K8vCp0xDnaERWp3bLiCd FRoAUC7e9kwnR/KfG2PzHx3rHSKXiQQ/EY8a3uIQoxU7vGH327dl0Hfh0oI/imz/4QrP sk5rs3BGGqnV56tmxj6yZPb8JcY6F/hTziNaxprS+GsbkCTviV5M6Y07Mflz+SPpbR2R gvdpoxlj81jqunkJF/dQYnxVXdiMx+fCDXvM85C71d/+xv8+dc2btY5DuS1rL/mGyLRh SJ7w== 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=7zwU0V/rQ4ZpVODrsZiGW6vlf43mofPG/+nVbaGPJPU=; b=BCoYpZpxaMbadVhsq6/2UiPRkfjVW+ommZp0U1coKHoeS7yudxyJc8lPp7G9VEh789 OaYm13F033S3ZG5hyoAXdEcuUjzV9YM0x6adFvp4JbnuGMcqd/mmuNsTnEO+V+OT6eiJ AGRmiUuwc3O0hqlC8NFkhNfLoj6uTFVWg6jNxo+kI53FSAXy+7dqDod0SyG4EEMMATXT JqSVW2qKI6/ezlw2AuJMYVtGjwXwP1wdq1jQE2YHhpRpZF/km2QF/r0xIzpzHim+mnl3 zeMVmHqR8wCELpLlW81uk41C5Zb5881M3rokGN6ROp/FQxezT1pa1qKD6zZgZ1zkyFei W4tQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=V0cYAgmX; 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 77si1709513pgb.237.2019.06.07.06.13.04; Fri, 07 Jun 2019 06:13:21 -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=V0cYAgmX; 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 S1728718AbfFGMTE (ORCPT + 99 others); Fri, 7 Jun 2019 08:19:04 -0400 Received: from mail-it1-f195.google.com ([209.85.166.195]:55952 "EHLO mail-it1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727693AbfFGMTE (ORCPT ); Fri, 7 Jun 2019 08:19:04 -0400 Received: by mail-it1-f195.google.com with SMTP id i21so2343941ita.5; Fri, 07 Jun 2019 05:19:03 -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=7zwU0V/rQ4ZpVODrsZiGW6vlf43mofPG/+nVbaGPJPU=; b=V0cYAgmXRqFaHd3VwPwslM84k1MBpBNZO+Z3/aK4OSWw6FS83JtA04JH2FY48OfP1j M7oIkfOqitBuMZNy1YRKjRSST1cy6ywGOH5weddfg8og38ADrI87PHcAxPL/l++NZ1gY RIWnap7ZdhfA+ggFbnWjUZEZ8sO3SligX8eU4xi8zyCVVQLwbON92OpoXp2caZuAbTcy 6LFR4ucKp03g8aB0QkuV90tvgs43kryOadvUQIpasQ701QnbUFjDmgCz3aJ4TFv6gfsa xLW1/o48NrFbwjDewFdWR86GtnWU0qPTK86DLCcmg8uDpjX1sn+Ihh2lX1UiNFnMcom5 OE0A== 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=7zwU0V/rQ4ZpVODrsZiGW6vlf43mofPG/+nVbaGPJPU=; b=lZq0gW7JwMT4mGHWuN3pvsq/7EXaGlBI3ChpJ7a0rO4nOoeb919qsQtryKiIBtxUON 2m0N2V7GusgjF9fCLokmLKvDw1d/zBt/dyOnC+akFkoiru29P95jgxOYQCeR2T/T8sBn TWRv43Hil7ZmP2X3WCO06Jg6zXH1ShdqpGqf9o8XuFbm57PwvY6jMzrWx6sVtFMCrejw Ii/ndLBS6SdERv2rIa33yiP9OWiFcR+Iwl7zfoIf/U8E//Ej6uMTLRq2Aga6A8pMVIgW tjL+hp9NZ8lE3Uq9RzPFSYDSWqYlqyT1hMM4He0AzW7m6V1bcz0N1SO2In8FwSO4WQwY Rs9g== X-Gm-Message-State: APjAAAXuZ7ZnY9MPf7Jn6T6urvy12BT4DHwA5OIg7T8IPcf8mjJTWFKz wgM976kEnjHjO9O1WZY8eIGEkPDr X-Received: by 2002:a02:b817:: with SMTP id o23mr19238447jam.134.1559909942863; Fri, 07 Jun 2019 05:19:02 -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 t19sm617477iog.41.2019.06.07.05.19.00 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 07 Jun 2019 05:19:02 -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> <2281ef29-6e69-78e7-4d07-77f33c2f2d5a@gmail.com> Message-ID: <9adcde41-2450-27dc-36a0-b3b99022b43d@gmail.com> Date: Fri, 7 Jun 2019 15:18:59 +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: <2281ef29-6e69-78e7-4d07-77f33c2f2d5a@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:12, Dmitry Osipenko пишет: > 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; > Ah, that's inside the ISR, so maybe will make sense to just not complete the transfer and let it timeout: if (!WARN_ON_ONCE(i2c_dev->msg_buf_remaining)) complete(&i2c_dev->msg_complete);