Received: by 10.192.165.148 with SMTP id m20csp2544532imm; Sun, 22 Apr 2018 09:14:43 -0700 (PDT) X-Google-Smtp-Source: AIpwx49+TH32uSmLYqPGOtC7OO4Fo1RHiYPWGUbhk87olAgszhJs2orp73SNOj4lVfVBI/Y4Vi+i X-Received: by 2002:a17:902:9686:: with SMTP id n6-v6mr17393878plp.136.1524413683903; Sun, 22 Apr 2018 09:14:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524413683; cv=none; d=google.com; s=arc-20160816; b=ZjB0AKJxKKJ+dQnZTHLTKy88f7UFJ6r58IMCrpJr2uTnnGbiZecLf1gpK5b4gsrR2c EykLLJZri0jylYS8SviNBit2e4PXWubg7myG/W8e0U/rLcy7rmcvP9/SotP3wkh8dje1 w0z5c30jFLnjiZg+FsIDABlz8AgTZn/XujADZ1vmTuASpxcssSTQaeT9jZB558unpvp2 ibwd/wO2o1C2dk/vxrKuieYcT81OGP4XDqeEfjfz//tdNHB5xgOddh8f4xuOW1VeJv55 jsNc+pRJc8NGhGljQC5bxFMPVJh1Nqdf0RJAI8DBiLvapSN1W9z9ViyHkhRGml7VoCkc Li1g== 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=A5YpgiGzMFTrcHNQ07lOFbSk8oB5LNOHs2swNqlmlNI=; b=mdJnJBKDLDUTTcuEaJqdFauc7Is7MGc4rtKWce60TLVZyAZH1YKaJf6bgQI0e3ifX9 SE6GZ8HcLSWO/P/weycQz67WvBCE4d1e5Nx34vUzFBGJXsEanJxZEu68WVaNWhFQKuc/ rL+8T44gx1itS/79v4Bu+TW9ZnMC2CBWeBvNhaxrhXb0jCn9KqPOYFTSMLPHk8KCEUNd HjUTPONe/g4s8Un8gcKtF0BbMym6B/XeykWP69V+AqBuBswXfXox3flTQRzXnXOSNd7X YAJY0TuMNCVWzKF6N8p+jtZ54E0NN/EzhCxUT9llH4YUpY3t92HA+2lkG9NgyFf4J9ei 4Z2A== 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 a9si8168000pgf.259.2018.04.22.09.14.29; Sun, 22 Apr 2018 09:14:43 -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 S1753664AbeDVQNW (ORCPT + 99 others); Sun, 22 Apr 2018 12:13:22 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:44696 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753533AbeDVNze (ORCPT ); Sun, 22 Apr 2018 09:55:34 -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 3254C8FF; Sun, 22 Apr 2018 13:55:34 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Maxime Chevallier , Mark Brown Subject: [PATCH 4.16 028/196] spi: Fix scatterlist elements size in spi_map_buf Date: Sun, 22 Apr 2018 15:50:48 +0200 Message-Id: <20180422135105.580069686@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180422135104.278511750@linuxfoundation.org> References: <20180422135104.278511750@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.16-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: 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 @@ -779,8 +779,14 @@ static int spi_map_buf(struct spi_contro for (i = 0; i < sgs; i++) { if (vmalloced_buf || kmap_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))); if (vmalloced_buf) vm_page = vmalloc_to_page(buf); else