Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp2970555imm; Sun, 1 Jul 2018 09:24:45 -0700 (PDT) X-Google-Smtp-Source: ADUXVKLRC7mjw0ZSwhnr8Ar0UIi9jUZyD0dDfkICMRYVa6FJyY9nap560cbDMiZth7XEcRnBfVoB X-Received: by 2002:a63:920c:: with SMTP id o12-v6mr19013237pgd.233.1530462285350; Sun, 01 Jul 2018 09:24:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530462285; cv=none; d=google.com; s=arc-20160816; b=Jxo6bMmndYLkCNAiNcwlsCuAo8+HeqvC/5gNuvoWmwpUPaUaYuPkoBOQ7zmdcZP7fN dfPgyM7TnaH4USLGsUGj9ObB0dxqKyY0DiilaD3g5tJ0ii34XsGosGkhCDF5AmNde6gn 5WbJmHf8U/3eXgDDHpIAWQs2W036QW2AyUrKr7k0XKOTh8bb8c4WqK+jY2sFo8v/LbVL JHtifQrrONPsG7TxWezPULDGxwBdofLPtUy0+4ICd5XJ9y7cRAhEZNz22IGEQ4bgTGhr wXJ5rMyiaexSeaqpsgbhSvvdAF5K1c+qFzOEJBLR7TnQPVUr26go5S/pYJg0nEm3cVMW Hw6Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=fLkdMARtdQhf9EHRTS5INFry3Ir7KopEqbOuF2IWt/0=; b=SVTcTD/MsaoMLHWeoRM4o8H4ftFEe5mGLRpIsBCnSzeqgN34BAoPchTRxqM4xTB1IS /grnJBMchrfZ5mNhlcDs2e27rtpdEa+KnU+qxw20a6++6K5xujV3jCR6GcCDT2eqdorU FJqtWBi5sWo0BDd85qvX1NKpdOdl++mQ3XeRdADJpMZX0t+QzIYzUMNuuYJk4hPV5hPf 6FL5YLUePWXnXnEfbPs4twRgHkMY+cCmZWiCUKyUsoGQjfTIb7TGeryYmDQu0vM7ZnhB 05IaHOg+tK4lALio2HszdCe7QOODoRKWsnlWTygr/alfamHTzjQUyNdNlmKhQQ7iDPmJ 8jUw== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n5-v6si14390873plk.352.2018.07.01.09.24.30; Sun, 01 Jul 2018 09:24:45 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S964967AbeGAQWT (ORCPT + 99 others); Sun, 1 Jul 2018 12:22:19 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:33238 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S964961AbeGAQTg (ORCPT ); Sun, 1 Jul 2018 12:19:36 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 3765849B; Sun, 1 Jul 2018 16:19:35 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Maxime Chevallier , Mark Brown , Sudip Mukherjee Subject: [PATCH 4.4 101/105] spi: Fix scatterlist elements size in spi_map_buf Date: Sun, 1 Jul 2018 18:02:51 +0200 Message-Id: <20180701153156.693937436@linuxfoundation.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180701153149.382300170@linuxfoundation.org> References: <20180701153149.382300170@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.4-stable review patch. If anyone has any objections, please let me know. ------------------ From: Maxime Chevallier commit ce99319a182fe766be67f96338386f3ec73e321c upstream. When SPI transfers can be offloaded using DMA, the SPI core need to build a scatterlist to make sure that the buffer to be transferred is dma-able. This patch fixes the scatterlist entry size computation in the case where the maximum acceptable scatterlist entry supported by the DMA controller is less than PAGE_SIZE, when the buffer is vmalloced. For each entry, the actual size is given by the minimum between the desc_len (which is the max buffer size supported by the DMA controller) and the remaining buffer length until we cross a page boundary. Fixes: 65598c13fd66 ("spi: Fix per-page mapping of unaligned vmalloc-ed buffer") Signed-off-by: Maxime Chevallier Signed-off-by: Mark Brown Cc: stable@vger.kernel.org Signed-off-by: Sudip Mukherjee Signed-off-by: Greg Kroah-Hartman --- drivers/spi/spi.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) --- a/drivers/spi/spi.c +++ b/drivers/spi/spi.c @@ -707,8 +707,14 @@ static int spi_map_buf(struct spi_master for (i = 0; i < sgs; i++) { if (vmalloced_buf) { - min = min_t(size_t, - len, desc_len - offset_in_page(buf)); + /* + * Next scatterlist entry size is the minimum between + * the desc_len and the remaining buffer length that + * fits in a page. + */ + min = min_t(size_t, desc_len, + min_t(size_t, len, + PAGE_SIZE - offset_in_page(buf))); vm_page = vmalloc_to_page(buf); if (!vm_page) { sg_free_table(sgt);