Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp455202imm; Tue, 14 Aug 2018 23:35:17 -0700 (PDT) X-Google-Smtp-Source: AA+uWPz3LJ+9u3DyFeVuArCjRCTlBAVdziQCzhFVYNXeockMDacl56bgz94z26NMU94xv/nmbOF8 X-Received: by 2002:a17:902:7d94:: with SMTP id a20-v6mr17165360plm.19.1534314917497; Tue, 14 Aug 2018 23:35:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1534314917; cv=none; d=google.com; s=arc-20160816; b=ykc+PZXfl8eGozBq/LNyuXTePKVUsYggpZDmq0Ix6LUss9q5dwzyCFVn06BXQI/pMi fC/VVRLj3ho0zJEbpvySkp+qPg4/0HXDtPPi3s8Xa+6vPbBLRFWwlOBLkx4Crg8gBqtj rC8X1QE2sbZ0wzNrIlBN/jgsZ4CTKldPb+KJcb0/shkMTAqsIudxMczP7NDvk6CL2Wqi FiqQSFqCH6QlS30lIgejnLamTzIuMepEa/XywPwjK1+/56gNLcQZfMSd1m9weUeBDnk6 aT+i5Mkxqwu4a+hiSukZkdubQEiaQyFsygsXXUX11lZ9U29yh0Sjf+5q4EXDJrT71mKQ xzRg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :arc-authentication-results; bh=mxOACnWSe+bigmlFN4y2x+C2drTDh5AMHcCFNYTQoXo=; b=f4hYg7Zv2cr5e0118hedT5XokYRJVPs0uFi9tpkRCodysRrPQl58PNV6s43iiwriot C2S8itcOJeNnePZfdfhw+E9EBsSTlWdgoZm7MszaU8GkSU/IEf7QryG4Gs4I0M15PxwT D/UnXOb6TnxtmqeRUesahF+uoq/D1742YF4fys+F9dxOx+su2rGD3ojgMcbv9zg8pI0q RcEEkilkZ4wK7pebbGgSJjhBbEaod2wL+YXiYs+5BD1oNHoV7w+sE9PZZEJjgocyWf2F MZCWfSmVTiBXINNlOwL5AcAv2RNKmF+poJwz8eGU+4uzHb8w5ruyo9sHaE4AJby3ihSM 0Kmg== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=nxp.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h11-v6si20658134pgf.558.2018.08.14.23.35.01; Tue, 14 Aug 2018 23:35:17 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=nxp.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728395AbeHOJZB (ORCPT + 99 others); Wed, 15 Aug 2018 05:25:01 -0400 Received: from inva020.nxp.com ([92.121.34.13]:38238 "EHLO inva020.nxp.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725898AbeHOJZB (ORCPT ); Wed, 15 Aug 2018 05:25:01 -0400 Received: from inva020.nxp.com (localhost [127.0.0.1]) by inva020.eu-rdc02.nxp.com (Postfix) with ESMTP id A94F11A01F1; Wed, 15 Aug 2018 08:34:08 +0200 (CEST) Received: from invc005.ap-rdc01.nxp.com (invc005.ap-rdc01.nxp.com [165.114.16.14]) by inva020.eu-rdc02.nxp.com (Postfix) with ESMTP id 5C3251A008E; Wed, 15 Aug 2018 08:34:03 +0200 (CEST) Received: from mega.am.freescale.net (mega.ap.freescale.net [10.192.208.232]) by invc005.ap-rdc01.nxp.com (Postfix) with ESMTP id 75317402B3; Wed, 15 Aug 2018 14:33:56 +0800 (SGT) From: Chuanhua Han To: dwmw2@infradead.org, computersforpeace@gmail.com, boris.brezillon@bootlin.com, marek.vasut@gmail.com, richard@nod.at Cc: cyrille.pitchen@wedev4u.fr, broonie@kernel.org, pp@emlix.com, Zhiqiang.Hou@nxp.com, chuanhua.han@nxp.com, linux-mtd@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH] mtd: m25p80: consider max message size in m25p80_read when use the spi_mem_xx() API Date: Wed, 15 Aug 2018 14:33:43 +0800 Message-Id: <1534314823-14048-1-git-send-email-chuanhua.han@nxp.com> X-Mailer: git-send-email 2.7.4 X-Virus-Scanned: ClamAV using ClamSMTP Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Consider a message size limit when calculating the maximum amount of data that can be read. Signed-off-by: Chuanhua Han --- drivers/mtd/devices/m25p80.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/drivers/mtd/devices/m25p80.c b/drivers/mtd/devices/m25p80.c index e84563d..87efa56 100644 --- a/drivers/mtd/devices/m25p80.c +++ b/drivers/mtd/devices/m25p80.c @@ -128,7 +128,12 @@ static ssize_t m25p80_read(struct spi_nor *nor, loff_t from, size_t len, op.dummy.nbytes = (nor->read_dummy * op.dummy.buswidth) / 8; while (remaining) { - op.data.nbytes = remaining < UINT_MAX ? remaining : UINT_MAX; + op.data.nbytes = min3(remaining, + spi_max_transfer_size(flash->spimem->spi), + spi_max_message_size(flash->spimem->spi) - + sizeof(op.cmd.opcode) - + op.addr.nbytes - + op.dummy.nbytes); ret = spi_mem_adjust_op_size(flash->spimem, &op); if (ret) return ret; -- 2.7.4