From patchwork Fri Dec 4 16:06:55 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eugen Hristev X-Patchwork-Id: 1411157 X-Patchwork-Delegate: hs@denx.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=quarantine dis=none) header.from=microchip.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=microchip.com header.i=@microchip.com header.a=rsa-sha256 header.s=mchp header.b=Q0pLW0tA; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4Cnczt1wqNz9sWw for ; Sat, 5 Dec 2020 03:07:27 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 7A1C3825C6; Fri, 4 Dec 2020 17:07:15 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=fail (p=quarantine dis=none) header.from=microchip.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=microchip.com header.i=@microchip.com header.b="Q0pLW0tA"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id CAD95825D4; Fri, 4 Dec 2020 17:07:14 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,RCVD_IN_DNSWL_LOW,RCVD_IN_MSPIKE_H2, SPF_HELO_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from esa6.microchip.iphmx.com (esa6.microchip.iphmx.com [216.71.154.253]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 19D12825C3 for ; Fri, 4 Dec 2020 17:07:09 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=quarantine dis=none) header.from=microchip.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=Eugen.Hristev@microchip.com DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=microchip.com; i=@microchip.com; q=dns/txt; s=mchp; t=1607098030; x=1638634030; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=czcDXbh7FcMQfNf/YIUVOnYlETK+tV72X/SEJAC5mnM=; b=Q0pLW0tAY8jhVVDb9Ff51iF+7cl8Rzx2k/Hgetqc1066pOf1YWrKcX60 fQCSVUjdufCcPtycHE7ZtklQzZl6v6NZ9OnQ7QyHpxbZloe/HiSJmAxiG 74IAZN+J1etwTwQdYqx/uYLCSr6/kQyq/C/ChYJK338QclTGZNM/nQneN KT/eLzIIELeaXBTDeHXD9qoogNqfzeL45uBnXwwvkTD/Mv6Mh72WnywGM qfBETeHf+jTojAbb+w/EkEzG+U+PVeCC0e3x7D/15Tt6JIqNC9DZSEGih cQEeqhDCOkMfijw/9ZIP41z0rlrusDCPAn4BJ/wrr4pCKRHNeLE3qYDAI w==; IronPort-SDR: IZts4gRmMIvzhH02Y9LCt5h6ygfQJPTPd+aglGEP4GUf2P+JePeG+bjzH9DsKyqVAB6yQmG3DG 46brhNmJSevrlkzk1pnygL9JUy5GzsR+WcGYq9JD0RwDOif6YoFmCPTRUtKaGPUb0KfacI0fk1 27Q0DoDRQHpq3xnErHtkD7stPaH7cWH2hjeEZacfkp8LPn11RMmSFO2/ar/zyK5T0o9gk5BxPG ZOqczKCw0Gg2MeueZZO+KQEuiuZ1p4O/n7l59R922+sCoVLOLI2N7zWtGhUJZq3rHhjgKbIrp4 GPs= X-IronPort-AV: E=Sophos;i="5.78,393,1599548400"; d="scan'208";a="36138330" Received: from smtpout.microchip.com (HELO email.microchip.com) ([198.175.253.82]) by esa6.microchip.iphmx.com with ESMTP/TLS/AES256-SHA256; 04 Dec 2020 09:07:07 -0700 Received: from chn-vm-ex01.mchp-main.com (10.10.85.143) by chn-vm-ex04.mchp-main.com (10.10.85.152) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1979.3; Fri, 4 Dec 2020 09:07:07 -0700 Received: from ROB-ULT-M18282.microchip.com (10.10.115.15) by chn-vm-ex01.mchp-main.com (10.10.85.143) with Microsoft SMTP Server id 15.1.1979.3 via Frontend Transport; Fri, 4 Dec 2020 09:07:05 -0700 From: Eugen Hristev To: , CC: Eugen Hristev Subject: [PATCH] i2c: at91: fix crash when using 'i2c probe' Date: Fri, 4 Dec 2020 18:06:55 +0200 Message-ID: <20201204160655.85766-1-eugen.hristev@microchip.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.102.3 at phobos.denx.de X-Virus-Status: Clean When issuing 'i2c probe', the driver was crashing, because at probe there is a request with zero length buffer to write to i2c bus. The xfer_msg function assumes the buffer is always there, and never checks for the buffer length. => i2c dev 0 Setting bus to 0 => i2c probe Valid chip addresses: data abort pc : [<7ffa97dc>] lr : [<7ffa96f8>] reloc pc : [<66f277dc>] lr : [<66f276f8>] sp : 7fb7c110 ip : 7ff87a28 fp : 7ff99938 r10: 00000002 r9 : 7fb7dec0 r8 : 00000000 r7 : e181c600 r6 : 7fb88c20 r5 : 00000000 r4 : 7fb7c128 r3 : 00000000 r2 : 00000001 r1 : 00000000 r0 : 00000009 Flags: nZCv IRQs off FIQs off Mode SVC_32 Code: eb0092f4 e1a00005 e8bd81f0 e594300c (e5d33000) Resetting CPU ... Fixes: 8800e0fa20 ("i2c: atmel: add i2c driver") Signed-off-by: Eugen Hristev --- drivers/i2c/at91_i2c.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/i2c/at91_i2c.c b/drivers/i2c/at91_i2c.c index 9d6c6d80e2..dfd649cd57 100644 --- a/drivers/i2c/at91_i2c.c +++ b/drivers/i2c/at91_i2c.c @@ -50,6 +50,10 @@ static int at91_i2c_xfer_msg(struct at91_i2c_bus *bus, struct i2c_msg *msg) u32 i; int ret = 0; + /* if there is no message to send/receive, just exit quietly */ + if (msg->len == 0) + return ret; + readl(®->sr); if (is_read) { writel(TWI_CR_START, ®->cr);