Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp3700322imm; Mon, 20 Aug 2018 03:17:07 -0700 (PDT) X-Google-Smtp-Source: AA+uWPxOnXUsOvSrP7juBN1Yy5ieXIuAu6zGmENmF6x0ZX5TpRb7SaCEF2F2UI6ofi3W2okMmaGb X-Received: by 2002:a17:902:70cb:: with SMTP id l11-v6mr8810007plt.91.1534760227774; Mon, 20 Aug 2018 03:17:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1534760227; cv=none; d=google.com; s=arc-20160816; b=H5LkZOhFr12i6y9oPbld4COylo1rGJqDVAVX/Q5E335/BehLCtCkz6pMHvR0qcvWMX tN9QlJ66XjGK0F5RJiLFKegzKVc1GGoMdVqP3JcPHfSLkQiIezTLElf0mi5QLZymxBaV crfcBih9bfK+nht/uGGUnOqqmylr+lOcvKwlKqKBx3PFe8XRC6ZqUJbHxlKcHTATqMRs tqN9LjsftuJHkFjV4/w5dDLb/8CEhAnt2BpX0yzmyUKKyooV3vNCyYkwmg9V5YBiKwr1 84BxsRMmDNPUdJOhVzB08lGOWA//pTLwAqxJJDs2mclkvzaSFnkWf/3UsS/A+PCCRF48 1N1w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date :arc-authentication-results; bh=9G/9KLybkdM1SQ3kRbieTLnoANyNyJUpI06/bybNK2w=; b=JPYgJyLXcDcTYqmGFCkD3wzTXNHWPJdxPMOBVGZHRo57kdaYZiWD2EadhdvS8PCsYu +ZXGhwraOTJYBFDtRQVFln4RQO3I5IwcRb6ST50npF2STZvA37q0Jx3BYj7Hw8I4BybE 1MlkoQjFqQIKrWCFUBCYNPWMPX7G6hR5md0SXfd5IegWTcVkNE/MtjbQoYf+hq84KrwV Yi9t6YdomFFgY6ZermqUOwa914bHUSsM6csOD1bysUmjUU+8NYHjy3IxdDpXfVjusry4 Pk4olmubizkYaKoIp3dkPs99LrwVSlhaHa6Ygvy1RlcaLHvKkE/XpzJ2I2Inrc/ojjSf ANrg== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q8-v6si9059911pfh.353.2018.08.20.03.16.52; Mon, 20 Aug 2018 03:17:07 -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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726346AbeHTNar (ORCPT + 99 others); Mon, 20 Aug 2018 09:30:47 -0400 Received: from mail.bootlin.com ([62.4.15.54]:35586 "EHLO mail.bootlin.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726010AbeHTNar (ORCPT ); Mon, 20 Aug 2018 09:30:47 -0400 Received: by mail.bootlin.com (Postfix, from userid 110) id C57CB20DEC; Mon, 20 Aug 2018 12:15:44 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on mail.bootlin.com X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=ALL_TRUSTED,SHORTCIRCUIT, URIBL_BLOCKED shortcircuit=ham autolearn=disabled version=3.4.0 Received: from bbrezillon (91-160-177-164.subs.proxad.net [91.160.177.164]) by mail.bootlin.com (Postfix) with ESMTPSA id 86FA820703; Mon, 20 Aug 2018 12:15:44 +0200 (CEST) Date: Mon, 20 Aug 2018 12:15:44 +0200 From: Boris Brezillon To: Chuanhua Han Cc: broonie@kernel.org, linux-spi@vger.kernel.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org, jiafei.pan@nxp.com, zhiqiang.hou@nxp.com Subject: Re: [PATCH] mtd: m25p80: consider max message size when use the spi_mem_xx() API Message-ID: <20180820121544.5dfaf802@bbrezillon> In-Reply-To: <1534758206-24555-1-git-send-email-chuanhua.han@nxp.com> References: <1534758206-24555-1-git-send-email-chuanhua.han@nxp.com> X-Mailer: Claws Mail 3.15.0-dirty (GTK+ 2.24.31; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Chuanhua, On Mon, 20 Aug 2018 17:43:26 +0800 Chuanhua Han wrote: Subject prefix should be "spi: spi-mem: " not "mtd: m25p80: ", and you need a commit message explaining what this patch does and why it's needed. > Signed-off-by: Chuanhua Han Fixes: c36ff266dc82 ("spi: Extend the core to ease integration of SPI memory controllers") Cc: > --- > 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; Not properly aligned, and you should find a better name for this variable. > > 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; This should be enclosed in the if (!ctlr->mem_ops || !ctlr->mem_ops->exec_op) block and you should check that spi_max_transfer_size(mem->spi) >= val too. > + > + 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); Regards, Boris