Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp307570imm; Fri, 21 Sep 2018 00:07:58 -0700 (PDT) X-Google-Smtp-Source: ANB0Vda/lclPySBEn2rgPt++JkH6hVWlnAzWQVKpk5/LD/+wb80QAzfnXNXTnlEA0wy0J3+WoA0K X-Received: by 2002:a63:2e09:: with SMTP id u9-v6mr40808874pgu.294.1537513678755; Fri, 21 Sep 2018 00:07:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537513678; cv=none; d=google.com; s=arc-20160816; b=KMM/6UWuTqLfj1Kb/oGikkHq+zNQW0iPShw3v+VTAGHNWYgazhSwdmXWK6IplvbWo+ 7AZYcmznj66m8oMMhQDqaLjGzEwmNzU6UaLXgdKUzoFaf552jKl0iKR91b1joBrhVa8l LW1u0wOyQPVhxvUv+fEHAg/rgWk17EN1PXfVL/uDLf5VC0HoqH9+AzLkrKYBzQHKNjgO d23ABZ2KiGX8QP6D0MFtcADpcKKZT1kLWLI3PY1KHm4iQMIPCsZnOMbPviInE2cnQkKn EtVBX1tCktzeRYWgGLEtV98IXjXMr/JZnGuf4zHuNoo7CJY2It01RNHfLvTXokQVEtqT MyOQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from; bh=W2lnSyMqUwPsG6K98rsf2OkBv0O4Zl04gsxHuWeY+oM=; b=XqqspSf0SWK5P1CUj9VkO/9jNv5Kktg4Z5hRb6C95mSbJaurAa1wAEDviMmYYUXuLY 1+OHcFKBUTPcddWBcytrKjpJfCy/+BqclN4cH9qnkPdCj/UgeagTOi/D6ju6jcnZjn4h wo8zi8HeBZVqoXx7WSiGtlNB8aMUKnpTkogMTb6s80BNThHzyejzKVrWNnkS0Dw83HML x6mOuZ61ITaYij0yxQeQAAQ6AgljV3wUKVYrILTy01lDYfoV7Z2l9rMubVbCcSy42GAL jDdG0KQ/YE7DydvUoCNW1Rk9FRWOiWGiW18bib2lbxgKop1RlyhDMFGqZopXyY1HBU3s /pBQ== 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 u1-v6si6317924pgq.1.2018.09.21.00.07.42; Fri, 21 Sep 2018 00:07:58 -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 S2389382AbeIUMxt (ORCPT + 99 others); Fri, 21 Sep 2018 08:53:49 -0400 Received: from inva021.nxp.com ([92.121.34.21]:33176 "EHLO inva021.nxp.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388909AbeIUMxr (ORCPT ); Fri, 21 Sep 2018 08:53:47 -0400 Received: from inva021.nxp.com (localhost [127.0.0.1]) by inva021.eu-rdc02.nxp.com (Postfix) with ESMTP id ACB66200254; Fri, 21 Sep 2018 09:06:15 +0200 (CEST) Received: from invc005.ap-rdc01.nxp.com (invc005.ap-rdc01.nxp.com [165.114.16.14]) by inva021.eu-rdc02.nxp.com (Postfix) with ESMTP id 34A17200240; Fri, 21 Sep 2018 09:06:12 +0200 (CEST) Received: from mega.ap.freescale.net (mega.ap.freescale.net [10.192.208.232]) by invc005.ap-rdc01.nxp.com (Postfix) with ESMTP id 7D1A7402A9; Fri, 21 Sep 2018 15:06:07 +0800 (SGT) From: Chuanhua Han To: broonie@kernel.org Cc: linux-spi@vger.kernel.org, linux-kernel@vger.kernel.org, eha@deif.com, boris.brezillon@bootlin.com, Chuanhua Han , stable@vger.kernel.org Subject: [PATCH] spi: spi-mem: Adjust op len based on message/transfer size limitations Date: Fri, 21 Sep 2018 15:06:28 +0800 Message-Id: <20180921070628.35153-3-chuanhua.han@nxp.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180921070628.35153-1-chuanhua.han@nxp.com> References: <20180921070628.35153-1-chuanhua.han@nxp.com> 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 We need that to adjust the len of the 2nd transfer (called data in spi-mem) if it's too long to fit in a SPI message or SPI transfer. Fixes: c36ff266dc82 ("spi: Extend the core to ease integration of SPI memory controllers") Cc: Signed-off-by: Chuanhua Han Reviewed-by: Boris Brezillon Signed-off-by: Mark Brown --- drivers/spi/spi-mem.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/drivers/spi/spi-mem.c b/drivers/spi/spi-mem.c index 990770dfa5cf..ec0c24e873cd 100644 --- a/drivers/spi/spi-mem.c +++ b/drivers/spi/spi-mem.c @@ -328,10 +328,25 @@ 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; + size_t len; + + len = 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 (!ctlr->mem_ops || !ctlr->mem_ops->exec_op) { + if (len > spi_max_transfer_size(mem->spi)) + return -EINVAL; + + op->data.nbytes = min3((size_t)op->data.nbytes, + spi_max_transfer_size(mem->spi), + spi_max_message_size(mem->spi) - + len); + if (!op->data.nbytes) + return -EINVAL; + } + return 0; } EXPORT_SYMBOL_GPL(spi_mem_adjust_op_size); -- 2.17.1