Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp3670749imm; Mon, 20 Aug 2018 02:45:06 -0700 (PDT) X-Google-Smtp-Source: AA+uWPxYg4u3IDEFNFJ/ZPnNfPNKU5BUmwtaRbXrdH9NOOIvPJ4tfGejGGBLpZyPlcEkB/+wxj9m X-Received: by 2002:a62:5302:: with SMTP id h2-v6mr47911642pfb.183.1534758306834; Mon, 20 Aug 2018 02:45:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1534758306; cv=none; d=google.com; s=arc-20160816; b=T6o2Q8U7af4+NjV4OPDYCm4SZHL9RYmlkmyMlxU7tG7P3VhScRKOkk+Rk8uHWVT9mQ xmBun0EuZ/3IViILK8t7xdUaR0BNd3NfFD5vEG/WaHRRAQQcYYpIzURkBVooc03szdjG gVUNd9GySj+JK/Y5fhtDNRW4EgDPN35fOJOmMh6lMyvNO56J+4KNJpzVRcsQVcr5Lwmc eIGK9CHjI/NuJVB8GThMC82Mo0EwQMBwCjmCYis0gvkfYWQDW+GGB8cLRSUZGeEFL9S8 A31mcvGJeDPLwCvAJvNZeTMsOuu6f7sYzjy38fwSL66UmsdeEtZSzZgZ6rXv1ByR2/qU yfRw== 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=HKJZ4MA60JySf2xNXNGkvvoPWpdKWklnVue8mt8jMi8=; b=gm5yhP3mpMwZS+/pkaMaPuvRZijvSnD3ZdiAkgScxWt8HBrrk0bVWk7YZpNzebH2U+ suoh+mwPe0AXcHFTO66BKGWIQ/wCZxkljtdHcK0SBEL2ZW0jSB7I2BZtzr/ul1ymJG/w kOlFyUJR/+GoWrIDmKv/63BVzBxc7ZJzsaSIiKMGvy/WkrzdpXCtvEDInIWfoROVOkyJ wpLTnb1LB6IkfBWEsALnATTeCvvx1j1o2fMmwiQ5Th4WcUs6RFNwpjwGtBWvojLo8urq LYAjBQGxPkqBCzYFRxZuGpV6+noPxGClwhwvVVzOGcfs8gXY9I9C77K8cFwGpX/ij9Zm qWWQ== 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 c17-v6si8966718pge.273.2018.08.20.02.44.50; Mon, 20 Aug 2018 02:45:06 -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 S1726141AbeHTM6k (ORCPT + 99 others); Mon, 20 Aug 2018 08:58:40 -0400 Received: from inva020.nxp.com ([92.121.34.13]:53602 "EHLO inva020.nxp.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726010AbeHTM6k (ORCPT ); Mon, 20 Aug 2018 08:58:40 -0400 Received: from inva020.nxp.com (localhost [127.0.0.1]) by inva020.eu-rdc02.nxp.com (Postfix) with ESMTP id AB06A1A0086; Mon, 20 Aug 2018 11:43:44 +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 ED3781A008D; Mon, 20 Aug 2018 11:43:40 +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 E9B50402A3; Mon, 20 Aug 2018 17:43:35 +0800 (SGT) From: Chuanhua Han To: broonie@kernel.org, boris.brezillon@bootlin.com Cc: linux-spi@vger.kernel.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org, jiafei.pan@nxp.com, zhiqiang.hou@nxp.com, Chuanhua Han Subject: [PATCH] mtd: m25p80: consider max message size when use the spi_mem_xx() API Date: Mon, 20 Aug 2018 17:43:26 +0800 Message-Id: <1534758206-24555-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 Signed-off-by: Chuanhua Han --- 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