Received: by 10.192.165.148 with SMTP id m20csp2492129imm; Sun, 22 Apr 2018 08:08:26 -0700 (PDT) X-Google-Smtp-Source: AIpwx4+VKV+fVe+s96PyvDrdx9k5KuPgcD5fAJTVnZ9xDvQZje3+eOSZrodnWxVhhO+3pKnI+g/S X-Received: by 2002:a17:902:7c86:: with SMTP id y6-v6mr17456472pll.378.1524409706409; Sun, 22 Apr 2018 08:08:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524409706; cv=none; d=google.com; s=arc-20160816; b=PGOwfhGvDW31O/UKe+Bndp21nr1mfjcIyoyp0fY7adUWNdKVpS5bA5rGU9oUrAvdyh 92V1wh9E5kXiPeKZ/ZByd+eDHeM2nmTr2qQ3DZDwGvCr6g3GJk65VWOSJ5XP466SfehP XHE+l9oCf+FNB3M/K4VFvzIkArmXS4DGV+BDnakKhoHowA+S+Gpxs2WLtdd8r1dyIUmt QV52i+6ZmLbwUGGby1jwFQ2m4BIfs/Et0P1bTYILSMv86erQokU6ocYLxEbwSdY1M/my wtuXmv2My6tEiuG6D/R9Q92vvk5hRqIILW4hgrHqycizfkSuwRXrrP2pQaXN8+xkZqrc uCxw== 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=my4zcBbOpg0uKROexVc7tfCFsxN9Ayk0eAv0jIcAtgU=; b=aD3YNof5ZL/EMFtIjESppyLgo7g8yCRwlAvGY3y0kWo5BPSF16ustMwoTtvA9Bs3qJ 4/H+2fJ6sOrRxaHFpcrw9yhpgr9F2+B7e2aSjAlUFWS9Ie3fV+i4EJimiqwjYUwJqcgG 7EbhVO9IV7oZehYKkNsPyRV4VbvLN0aSoy0/EQISzqPYiKDwYFRiRCUHpmrNrCXIiv3E OCA0kSiSDdR1DEZMYHThnLh9N9xN25B3fi8hH73xe3Ybs4y63l+Fn/BCbHf9FbfjyNll 8wGhf512t8dwlABcLjNAMayHlBq0ur5wrrWtzPszaF3OmhfsFVpZf+tFv5ixJC++4GcI gApw== 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 p14-v6si4157618pli.250.2018.04.22.08.08.11; Sun, 22 Apr 2018 08:08:26 -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 S1756269AbeDVOLd (ORCPT + 99 others); Sun, 22 Apr 2018 10:11:33 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:54332 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756484AbeDVOLY (ORCPT ); Sun, 22 Apr 2018 10:11:24 -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 870B6CB0; Sun, 22 Apr 2018 14:11:23 +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.9 15/95] spi: Fix scatterlist elements size in spi_map_buf Date: Sun, 22 Apr 2018 15:52:44 +0200 Message-Id: <20180422135211.060960284@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180422135210.432103639@linuxfoundation.org> References: <20180422135210.432103639@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.9-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 @@ -743,8 +743,14 @@ static int spi_map_buf(struct spi_master 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