Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp662203ybi; Fri, 7 Jun 2019 14:44:12 -0700 (PDT) X-Google-Smtp-Source: APXvYqwulcmjSNXJz/kVsZPQbBueE3WvCsr740daTLPB8RNf5i8oQnTiMz+0PpRCF0tco8GyY8XW X-Received: by 2002:a63:441c:: with SMTP id r28mr4943474pga.255.1559943852351; Fri, 07 Jun 2019 14:44:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1559943852; cv=none; d=google.com; s=arc-20160816; b=SazTl0DOdDRa4FrS8noeOjFrbSvBF18uXADNwPz2sZF7uFZqGYGbMpNIObcrv5KVtU nEdjSwgAjA2BZVFDT0DN6PC2UgFKaWtAozPi9aMKYaSrTxN68hU3w5qhABN3/vLsEYIr IwlF87iK8HVAPBkGISOzdNI6cxPZKauETGzoeKvZTLiq08lgVSGmBgkZlP5rjCK2L52O sDZxDJ5ahwp3j3jQCOJwMvL3TwkUyebYzly0OrE/xl+fT0sZ0qpp9EGG5avhuGHvVCf/ g/w57fV18UnjtAGNocO4M9A89aqsexkOFjtHIQ5lk709Wp8IiximpA0/R+WeXg1v/umv RbdA== 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:from:references:cc:to:subject:dkim-signature; bh=PpZq5RJ/LWjQRCgCN2YVuXvSgVVFGXCds2RhKiuW0mc=; b=sjHfQpDT5R9lTLTLQWOo7BIcuiyQtqJQWbX67f/HzvXyWu+waNiVx6OsnKvIdkqnwm XK43dJe8v8f71McPBjoljBEI7VEDaB8Z5MbKGFRJFFtMepG1lFI1XsXezy7mOF009OpY MSTU4yjkeHlBJ8h7IQ1GKNoYV+3LGpLfjMFCUqtw0a/sBiv/EX+I5U1yYeq3hKrunVZ9 FAHXObQtjHDMv8aUKsUtx69uX1OZl57WmuLfnFOBb2YM3rwVBuW4JZV6Nbh4/iHabH/1 lxBngGPxC89/y0seJ/mSTGmyuqRxKzixELG3moRtHpk2+EUojKVEOy/VFDNlR1iehnOU 0bqw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=JEl5SaP0; 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 k1si2922943pfa.25.2019.06.07.14.43.56; Fri, 07 Jun 2019 14:44:12 -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=JEl5SaP0; 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 S1730976AbfFGTsE (ORCPT + 99 others); Fri, 7 Jun 2019 15:48:04 -0400 Received: from mail-lj1-f195.google.com ([209.85.208.195]:35610 "EHLO mail-lj1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729715AbfFGTsD (ORCPT ); Fri, 7 Jun 2019 15:48:03 -0400 Received: by mail-lj1-f195.google.com with SMTP id h11so2767271ljb.2; Fri, 07 Jun 2019 12:48:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=PpZq5RJ/LWjQRCgCN2YVuXvSgVVFGXCds2RhKiuW0mc=; b=JEl5SaP0bubHCTxgJBaqOlOxwv9QyTBzupqmxosqN0HiBmOkk3gL0axQxItZgtePPT acYWEZVXOTDeEEpP3IwdQG0I9Fv66PlEXzs/BFpqlOtz49S1pVHbGjeltblHvppHoN6g 0YZ738rjj8Rl7KuvExeholTXvuwoPLWopHMO/++AADReWNkWknIhwjFng0ZYXhoWrh1F Fgq2L6qeya56OHbKfSsZVU448aU5J6jcLTXXmwQCA1YV+C6p6o/ARXA8BSFJoFDKmzM4 FZsxshtGov/rwv6LtPCfPQbqQpWEuc3JidjMjt1uMmUxUoDyOAbAkwxZwla9X9j0Gn0W e9WA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=PpZq5RJ/LWjQRCgCN2YVuXvSgVVFGXCds2RhKiuW0mc=; b=MmeJ2F2I3KZDtYkbP+WQFUuFuyLEkaAja1lIdWwzD7Voa7E7qjNAx1vNSuWHQv3T9K gWBQl1o/QvuTaXs317wqmPM5r50z5ACrOvpsP7vIZmHBP/BXcX6jqQSj8scRqtBZZiG1 EE8HxO/p3QJX/F/1MsXbG4N5F+Sar2c1IRLMBpKdqWT+MshBQluw33EFYnLheF0ooUof 2Scjm4uovqrFlm6Zj9n7nCWAGlJmeB1u0wsowjAQSuV8yhoVg9adpiwktVfG6ZctPgAy DvKVRaYCI1WExZXN7ZKY8SzXPMxsSCDb7MbFMsY/OZv719yhYjil5XXmf7cgP3vY5xBE e2UQ== X-Gm-Message-State: APjAAAW8aa9Dfq4+gba8lINEmjpMLEa7u8trySMvdG6OflTD6c+6ZXNZ DWKfjZu7JYuv5U0CdMJEnz58OJrh X-Received: by 2002:a2e:25a:: with SMTP id 87mr9285761ljc.183.1559936881229; Fri, 07 Jun 2019 12:48:01 -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 e8sm656086lfc.27.2019.06.07.12.47.59 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 07 Jun 2019 12:48:00 -0700 (PDT) Subject: Re: [PATCH V2 6/6] i2c: tegra: remove BUG, BUG_ON 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: <1559935826-25812-1-git-send-email-bbiswas@nvidia.com> <1559935826-25812-6-git-send-email-bbiswas@nvidia.com> From: Dmitry Osipenko Message-ID: Date: Fri, 7 Jun 2019 22:47: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: <1559935826-25812-6-git-send-email-bbiswas@nvidia.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 22:30, 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 | 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; > Unfortunately that's not enough because the indicator of the error is the i2c_dev->msg_err and no error is set in yours case, hence no hardware reset will be performed. It should be at least somewhat like this: if (WARN_ON_ONCE(i2c_dev->msg_buf_remaining)) { i2c_dev->msg_err |= I2C_ERR_UNKNOWN_INTERRUPT; goto err; }