From patchwork Thu Jan 17 17:06:00 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fabien Parent X-Patchwork-Id: 1026825 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=baylibre.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=baylibre-com.20150623.gappssmtp.com header.i=@baylibre-com.20150623.gappssmtp.com header.b="nrRy8OMB"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 43gVq04K3hz9sBn for ; Fri, 18 Jan 2019 04:06:36 +1100 (AEDT) Received: by lists.denx.de (Postfix, from userid 105) id 428EBC22088; Thu, 17 Jan 2019 17:06:32 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=RCVD_IN_MSPIKE_H2, T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id 14E62C21D8A; Thu, 17 Jan 2019 17:06:30 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 81966C21D8A; Thu, 17 Jan 2019 17:06:28 +0000 (UTC) Received: from mail-wr1-f66.google.com (mail-wr1-f66.google.com [209.85.221.66]) by lists.denx.de (Postfix) with ESMTPS id 4BC01C21C4A for ; Thu, 17 Jan 2019 17:06:27 +0000 (UTC) Received: by mail-wr1-f66.google.com with SMTP id v13so11864378wrw.5 for ; Thu, 17 Jan 2019 09:06:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=Q1tP1YAzZ6D0y8V6k03rUlPxOZoTpI+faGUFGVeES34=; b=nrRy8OMB+k2R/2gQXAcljYZjCEbjjlMuTDz+eCsdgZBEut9QQIkLWjPBAQfX3Nbjni wBQUAxbCaWQH8/LqqnzVk32zAOW+Iwwn9ek0M2abFeLsssY/GT3B96D/hEt6BycVfYZi ynAhslakJWoyO/Rt5L09M2mCOxAbsk+08xeGBZ262Nr7ar+XZKdVpOyv9MJzJO0Q7722 +htMCmTAxSfasaLrH9OYuDJkpp+xh5yHh2+t2+Zp+z2T/HEbpLKgPCtFSm+RJQD19phg BZAhj5OAUDd/PKvLFnXWGtSerw801GONxSiqxgelm+Gsmtv3Mly9ARGLplCDKrIaeS69 DN2Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=Q1tP1YAzZ6D0y8V6k03rUlPxOZoTpI+faGUFGVeES34=; b=DIaI4oKpJGdTPtqe3Cp2St3r28ZDZRDXk/iE1ootCMjp8EGDC6hBg/lDxjV8zKKQyY OSXbpbIbT/t79ohjzmQ8uGKnqT4wLK4UGZopnYp8Yft5lvuCqY75n9dF85B/fveAJ586 z56wD9zMZXB8mm+xP6ReiqJMlW1S4Jo7rOXKjYxQz0KSwwzYsEuR5XcIl5uVWzQZrpt+ 5BrLs0syhxPIlyMe6YE2TpNHK+Z8EtaZ5iBI2aO1jhu9Pq3JNF/0HT4s4N9dKW1HkJcJ 4Mv/eyKPd+7A3afaLFCTITTJ1jDkrgTZW+P7zUJqg5vbAkxpzOk4r3ogzl42Kjla2WiC Qqfg== X-Gm-Message-State: AJcUukddtP8J/EKrvyJhZN4iYhhqiKWUbTaN1tLDap94qwKxGLNgCux7 6ykodb6C2BLGzeu0Bu1OKhKHHypNDq1FvQ== X-Google-Smtp-Source: ALg8bN6MixKgi8P6eL3DRog1o6pSO0yj1snLI2mjpdroLr1GDB8RaMm9PvpKfVUuDY5jP2nEaXfIEQ== X-Received: by 2002:adf:8143:: with SMTP id 61mr12429837wrm.47.1547744786386; Thu, 17 Jan 2019 09:06:26 -0800 (PST) Received: from localhost.localdomain (cag06-8-78-203-165-84.fbx.proxad.net. [78.203.165.84]) by smtp.gmail.com with ESMTPSA id w6sm39316219wme.46.2019.01.17.09.06.24 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 17 Jan 2019 09:06:25 -0800 (PST) From: Fabien Parent To: u-boot@lists.denx.de, panto@antoniou-consulting.com Date: Thu, 17 Jan 2019 18:06:00 +0100 Message-Id: <20190117170601.20676-1-fparent@baylibre.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Cc: trini@konsulko.com, GSS_MTK_Uboot_upstream@mediatek.com, stephane.leprovost@mediatek.com Subject: [U-Boot] [PATCH 1/2] mmc: mtk-sd: fix possible incomplete read ops X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 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" The code is checking for incomplete read when it see the INT_XFER_COMPL flag, but it forget to first check whether there is anything left in the FIFO to copy to the RX buffer. This means that sometimes we will get errors because of erroneous incomplete read operation. This commit fixes the driver re-ordering the code so that we first check for data inside the RX fifo and only after check the status of the INT_XFER_COMPL flag. Signed-off-by: Fabien Parent --- drivers/mmc/mtk-sd.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/drivers/mmc/mtk-sd.c b/drivers/mmc/mtk-sd.c index 0741a525c0..e668df7017 100644 --- a/drivers/mmc/mtk-sd.c +++ b/drivers/mmc/mtk-sd.c @@ -554,6 +554,14 @@ static int msdc_pio_read(struct msdc_host *host, u8 *ptr, u32 size) break; } + chksz = min(size, (u32)MSDC_FIFO_SIZE); + + if (msdc_fifo_rx_bytes(host) >= chksz) { + msdc_fifo_read(host, ptr, chksz); + ptr += chksz; + size -= chksz; + } + if (status & MSDC_INT_XFER_COMPL) { if (size) { pr_err("data not fully read\n"); @@ -562,15 +570,7 @@ static int msdc_pio_read(struct msdc_host *host, u8 *ptr, u32 size) break; } - - chksz = min(size, (u32)MSDC_FIFO_SIZE); - - if (msdc_fifo_rx_bytes(host) >= chksz) { - msdc_fifo_read(host, ptr, chksz); - ptr += chksz; - size -= chksz; - } - } +} return ret; }