From patchwork Tue Feb 14 20:06:31 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heiner Kallweit X-Patchwork-Id: 9572735 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 931C5601E7 for ; Tue, 14 Feb 2017 20:08:23 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8F79326E4D for ; Tue, 14 Feb 2017 20:08:23 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 832D72840E; Tue, 14 Feb 2017 20:08:23 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,DKIM_VALID,FREEMAIL_FROM autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 400C726E4D for ; Tue, 14 Feb 2017 20:08:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:Date: Message-ID:References:To:Subject:From:Reply-To:Content-ID:Content-Description :Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=rqEIGowXO2vWFD5KsLQxUQKlk9Bam5eCD5iFBfvgphM=; b=Q3UST6Vx46bStE ztEZW+SP8neAgf5HYrOsgMMW7CF1dZg95mUvS7718zbOeJopAHVvRw+FPSTg/SMvE0L4PHYUA4Ihe vs6igCvsZCeskwKrBjj7E8VfAgVp7eXStkcGqhN3KneYT/2NltYAks5vtAvFA0KpmAIh8Mjik3F5K uFhPi9VP5ACV6isHQdC78U4GFcaB+V+UejLJuhMMsNdEi0Jpfn1yGoKN0uhmwN4atit2DffifNRn1 J34uxwUoW7DYoNhQdkoAGFZBzv8TSWumxlnePKOlkrtUI2ux67y7Bz4dBeBqkut0KCYDpCQurALaU /G6uYkeDiLioaGPAGcdA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1cdjOV-00025v-QT; Tue, 14 Feb 2017 20:08:11 +0000 Received: from mail-wr0-x243.google.com ([2a00:1450:400c:c0c::243]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1cdjOK-0001lB-6M for linux-amlogic@lists.infradead.org; Tue, 14 Feb 2017 20:08:03 +0000 Received: by mail-wr0-x243.google.com with SMTP id k90so28775355wrc.3 for ; Tue, 14 Feb 2017 12:07:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:subject:to:references:cc:message-id:date:user-agent :mime-version:in-reply-to:content-transfer-encoding; bh=f1owCGZ6tDQcVdQIq/rl7xa7JyWLiJfJU7wC5f8sSZQ=; b=PpvlQNlp+yTZubIN48MWRMDBOvk2P9KPZFv4WKolaauFxluCbQrDl11wNsWIXsTx/T 7YWfLDoHO/duTW2oiKsLphQTYyiyV2sHWRLyhjsdQ+NE+OtKJRYLz2Yv7iPRMMbJ5IOk VNzuz2+AEOQsPmV0JzjwAAy0Ms1MwSUzrhLJnD2gOFRxklvI9wHhzt96hZ3jD8qh5Tun wWiKciAO6iWfWNhe2hCOxzA6vYpXVOvVaKrxf82H//9Sn5eofErvSfoFOg6zT8Z3vJPt GrINVorpdWjxATBeRm135XiehzDxpjbC44tD+cbAAMfkXgLZ0hJq0v4t2inZYvaIx3rP MlpQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:subject:to:references:cc:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding; bh=f1owCGZ6tDQcVdQIq/rl7xa7JyWLiJfJU7wC5f8sSZQ=; b=rBKIBbSKVC/YjC1g1tBISXTnrBIEaV9LBKrEvW/bCmJ6mPztM8o7GmsxI5CmlXc0q8 XHlR57fHRkqgldqH4tZ0B/EHmI6eKyCdSZBbmP90OeSmehj+L0IC0E6hgzo9DBzHXVHf Fz7WM6TBjmZQ3510vy3c8NTJLg+bO/EGeOqKqKSnp6l9EGopw/hDY2S/4ht5auo6cA0C F5MA6sTJMManIdwDeLwFnl7HTmvTaq3kpabhyeENkubkhI4PlGNC5iE2kRZwj2Xia4qM 39Demq6EZmZocldouMpWX1hvnWZdGG3Bn6esjt1rSJEGPlddNSl5TqtjfJontCee21+B aCTA== X-Gm-Message-State: AMke39kIGqJ3rtxwX7RQhbjfiVvPoUl+LokDG62RFql4ZMFWLzbDw4LyCWQw5nGZVm73wg== X-Received: by 10.223.164.151 with SMTP id g23mr27262542wrb.86.1487102858498; Tue, 14 Feb 2017 12:07:38 -0800 (PST) Received: from ?IPv6:2003:c6:ebdc:4000:9533:a20:55f1:fb4b? (p200300C6EBDC400095330A2055F1FB4B.dip0.t-ipconnect.de. [2003:c6:ebdc:4000:9533:a20:55f1:fb4b]) by smtp.googlemail.com with ESMTPSA id d29sm2545824wmi.19.2017.02.14.12.07.37 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 14 Feb 2017 12:07:38 -0800 (PST) From: Heiner Kallweit Subject: [PATCH 07/18] mmc: meson-gx: check return value of sg_copy_[from,to]_buffer To: Ulf Hansson , Kevin Hilman References: <420b75a9-b8c2-b3d7-ae60-3ed8a5a18ead@gmail.com> Message-ID: <5c7ff200-258a-f573-b552-63ba0d8a029b@gmail.com> Date: Tue, 14 Feb 2017 21:06:31 +0100 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.7.1 MIME-Version: 1.0 In-Reply-To: <420b75a9-b8c2-b3d7-ae60-3ed8a5a18ead@gmail.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170214_120800_672633_8D349D35 X-CRM114-Status: UNSURE ( 8.33 ) X-CRM114-Notice: Please train this message. X-BeenThere: linux-amlogic@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Carlo Caione , linux-amlogic@lists.infradead.org, "linux-mmc@vger.kernel.org" Sender: "linux-amlogic" Errors-To: linux-amlogic-bounces+patchwork-linux-amlogic=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP So far it's only checked whether the requested transfer length exceeds the bounce buffer size. Instead let's check that sg_copy_[from,to]_buffer transferred exactly the number of requested bytes. Signed-off-by: Heiner Kallweit Acked-by: Kevin Hilman --- drivers/mmc/host/meson-gx-mmc.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/drivers/mmc/host/meson-gx-mmc.c b/drivers/mmc/host/meson-gx-mmc.c index 423b4b17..f3963538 100644 --- a/drivers/mmc/host/meson-gx-mmc.c +++ b/drivers/mmc/host/meson-gx-mmc.c @@ -495,14 +495,14 @@ static void meson_mmc_start_cmd(struct mmc_host *mmc, struct mmc_command *cmd) cmd->data->bytes_xfered = 0; xfer_bytes = cmd->data->blksz * cmd->data->blocks; if (cmd->data->flags & MMC_DATA_WRITE) { - cmd_cfg |= CMD_CFG_DATA_WR; - WARN_ON(xfer_bytes > host->bounce_buf_size); - sg_copy_to_buffer(cmd->data->sg, cmd->data->sg_len, - host->bounce_buf, xfer_bytes); + size_t len = sg_copy_to_buffer(cmd->data->sg, + cmd->data->sg_len, + host->bounce_buf, + host->bounce_buf_size); + WARN_ON(len != xfer_bytes); cmd->data->bytes_xfered = xfer_bytes; + cmd_cfg |= CMD_CFG_DATA_WR; dma_wmb(); - } else { - cmd_cfg &= ~CMD_CFG_DATA_WR; } cmd_data = host->bounce_dma_addr & CMD_DATA_MASK; @@ -657,10 +657,11 @@ static irqreturn_t meson_mmc_irq_thread(int irq, void *dev_id) data = cmd->data; if (data && data->flags & MMC_DATA_READ) { + size_t len = sg_copy_from_buffer(data->sg, data->sg_len, + host->bounce_buf, + host->bounce_buf_size); xfer_bytes = data->blksz * data->blocks; - WARN_ON(xfer_bytes > host->bounce_buf_size); - sg_copy_from_buffer(data->sg, data->sg_len, - host->bounce_buf, xfer_bytes); + WARN_ON(len != xfer_bytes); data->bytes_xfered = xfer_bytes; }