lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <1534758206-24555-1-git-send-email-chuanhua.han@nxp.com>
Date:   Mon, 20 Aug 2018 17:43:26 +0800
From:   Chuanhua Han <chuanhua.han@....com>
To:     broonie@...nel.org, boris.brezillon@...tlin.com
Cc:     linux-spi@...r.kernel.org, linux-kernel@...r.kernel.org,
        stable@...r.kernel.org, jiafei.pan@....com, zhiqiang.hou@....com,
        Chuanhua Han <chuanhua.han@....com>
Subject: [PATCH] mtd: m25p80: consider max message size when use the spi_mem_xx() API

Signed-off-by: Chuanhua Han <chuanhua.han@....com>
---
Changes in v2:
	- Place the adjusted transfer bytes code in spi_mem_adjust_op_size()
	and  check spi_max_message_size(mem->spi) value before subtracting 
	opcode, addr and dummy bytes.
*fixes:
	spi: Extend the core to ease integration of SPI memory controllers
---
 drivers/spi/spi-mem.c | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/drivers/spi/spi-mem.c b/drivers/spi/spi-mem.c
index 990770d..f5e75d1 100644
--- a/drivers/spi/spi-mem.c
+++ b/drivers/spi/spi-mem.c
@@ -328,10 +328,21 @@ EXPORT_SYMBOL_GPL(spi_mem_exec_op);
 int spi_mem_adjust_op_size(struct spi_mem *mem, struct spi_mem_op *op)
 {
 	struct spi_controller *ctlr = mem->spi->controller;
+	unsigned long val =	sizeof(op->cmd.opcode) +
+							  op->addr.nbytes +
+							  op->dummy.nbytes;
 
 	if (ctlr->mem_ops && ctlr->mem_ops->adjust_op_size)
 		return ctlr->mem_ops->adjust_op_size(mem, op);
 
+	if (spi_max_message_size(mem->spi) < val)
+		return -EINVAL;
+
+	if (!ctlr->mem_ops || !ctlr->mem_ops->exec_op)
+		op->data.nbytes = min3((unsigned long)op->data.nbytes,
+				spi_max_transfer_size(mem->spi),
+				spi_max_message_size(mem->spi) - val);
+
 	return 0;
 }
 EXPORT_SYMBOL_GPL(spi_mem_adjust_op_size);
-- 
2.7.4

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ