From patchwork Fri Oct 28 05:58:46 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heiner Kallweit X-Patchwork-Id: 9401221 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 ECA0660231 for ; Fri, 28 Oct 2016 05:59:24 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D8EB62A531 for ; Fri, 28 Oct 2016 05:59:24 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CDC0A2A567; Fri, 28 Oct 2016 05:59:24 +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=-6.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7EF092A531 for ; Fri, 28 Oct 2016 05:59:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756145AbcJ1F7I (ORCPT ); Fri, 28 Oct 2016 01:59:08 -0400 Received: from mail-wm0-f66.google.com ([74.125.82.66]:34798 "EHLO mail-wm0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S965206AbcJ1F66 (ORCPT ); Fri, 28 Oct 2016 01:58:58 -0400 Received: by mail-wm0-f66.google.com with SMTP id y138so5822034wme.1 for ; Thu, 27 Oct 2016 22:58:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=subject:to:references:cc:from:message-id:date:user-agent :mime-version:in-reply-to:content-transfer-encoding; bh=KGwosqZIrzxdUaf812fmp1l79KPfxyhG7HBSQNU/r6k=; b=jNKxgz3FIvM0T/LDOMWW/NbHUGy1nySQDCs99qIb6BhFB2vmqxKL//3KgGdFBqrc6T Y7rNDgWlIwsx2/u1JizKyvSTHBmPJXCOs54lcHrv6y0slpNLjp5syCfaDjoPBf02Wffj W077gu975rQpINl5V0Hp2s0TzdR79Mahob+pRbabxPuaLBjFu4DBRyS1OCZbadq4krAH lT9oc2RLy7SDco7XP2ojl20lTIH6rqWtFQYnEhV0yWRBiZgFmh/fKPCzyr/x80w+AieE 4qmOsWmqb7gkoPifKBhKCxsK95/geW0JOjX51KeEXllNBkG35quts48j6H5vDcvegIAz 916g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:subject:to:references:cc:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding; bh=KGwosqZIrzxdUaf812fmp1l79KPfxyhG7HBSQNU/r6k=; b=P3Y/cct+qUEUdyk8jxLEICRVK/w2o+Tjp27+3KMRqyhPTXYjEGoHZFpTGLoof0N/tZ ToScCTqWsv12YEw58EWSLwAAgzMS0hlVvpNIf9hccPKwkEIX5HBtBJauNYDLW4oMQAc3 BHfeM9CMwV7tebct5c6Bbzwp9tfpM9039EKS8ovqTcU7nB65zHpXuk4tuwuNFsmHxCLu /fQ41uDr0e0MBeo9RY3TUF/2xJlkUF+xpvkfekZQLp/UqvykAwursZeviT7Ii1mgw/l+ Eo+zLE8QuVNBGE/q7++EaRwMYHX9fciHsGUPIXpxfvHKIWEuTb+zFpVZhSKhycaAEbF6 DV4g== X-Gm-Message-State: ABUngvep8Ne75KHBgC5QC5Xtd/Xn9TK8UrA8OdYDnJwcYrhdM2Egenq4+CM8TOx1pC6HBg== X-Received: by 10.194.150.132 with SMTP id ui4mr11492027wjb.92.1477634336825; Thu, 27 Oct 2016 22:58:56 -0700 (PDT) Received: from ?IPv6:2003:62:5f6e:ba00:edc1:f638:1224:fcc7? (p200300625F6EBA00EDC1F6381224FCC7.dip0.t-ipconnect.de. [2003:62:5f6e:ba00:edc1:f638:1224:fcc7]) by smtp.googlemail.com with ESMTPSA id wn5sm12224948wjb.42.2016.10.27.22.58.55 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 27 Oct 2016 22:58:56 -0700 (PDT) Subject: [PATCH v2] mtd: m25p80: consider max message size in m25p80_read To: Cyrille Pitchen References: <6c95366c-7fcc-ef4c-033a-f9f6e152a669@gmail.com> <20160816164204.GV9347@sirena.org.uk> Cc: Brian Norris , Mark Brown , "linux-spi@vger.kernel.org" , MTD Maling List From: Heiner Kallweit Message-ID: <0e38d1ed-af5c-160f-e02a-f1433c507d23@gmail.com> Date: Fri, 28 Oct 2016 07:58:46 +0200 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.4.0 MIME-Version: 1.0 In-Reply-To: Sender: linux-spi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-spi@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Consider a message size limit when calculating the maximum amount of data that can be read. The message size limit has been introduced with 4.9, so cc it to stable. Signed-off-by: Heiner Kallweit Cc: # 4.9.x --- v2: - This patch was part of a series and the other patches of the series went into 4.9. It's needed to correctly support reads > 64k on fsl-espi as first user of spi_max_message_size. See commit 02a595d5d6e4 ("spi: fsl-espi: eliminate spi nor flash read loop"). CC it to stable. --- drivers/mtd/devices/m25p80.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/mtd/devices/m25p80.c b/drivers/mtd/devices/m25p80.c index 9cf7fcd..16a7df2 100644 --- a/drivers/mtd/devices/m25p80.c +++ b/drivers/mtd/devices/m25p80.c @@ -172,7 +172,8 @@ static ssize_t m25p80_read(struct spi_nor *nor, loff_t from, size_t len, t[1].rx_buf = buf; t[1].rx_nbits = m25p80_rx_nbits(nor); - t[1].len = min(len, spi_max_transfer_size(spi)); + t[1].len = min3(len, spi_max_transfer_size(spi), + spi_max_message_size(spi) - t[0].len); spi_message_add_tail(&t[1], &m); ret = spi_sync(spi, &m);