Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp3917945imm; Mon, 20 Aug 2018 06:57:15 -0700 (PDT) X-Google-Smtp-Source: AA+uWPxR7lp0TIe4/CONtD6yvFtAKbLMXgaUKTTK9LESKE0EEcJfVjX7Htse8TxuEhHAatNMTXly X-Received: by 2002:a65:41c6:: with SMTP id b6-v6mr43036273pgq.174.1534773435227; Mon, 20 Aug 2018 06:57:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1534773435; cv=none; d=google.com; s=arc-20160816; b=jBZTIL4ARuYlcin38veq9rxeBlod2pUPSojUS3Sp7VKKqENugYrPcErdvu9YbCfURx V315L5oyTq5O/QRPFNrWpsQRTFdIpkQ+cSOOgVrO7SUoshWJSjoWqD5Q113Kzq6a04Yl aifl3a7F8Hwts3nDxDqzoppglMNcESr6IUXvJrf04ddgNxpDivHVe68O6RcYi+v8qQGZ ukFrK2dK6NJ5KTUJAkFhk6HnQJMYlmPd61Fm65hLua1BVmgfp4CK1fN4hArePFLIEDg7 LoIcDzgGgqEqPu/gZjlbjMqXca7vHeYRmE4mA0C4PcYyCOizoxbtw9gFo87CrnhRqYvJ BlqA== 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=xGngfBGJ+vFv4v3pbuteWlLhsqaRwXCj+U/rqLkL3bI=; b=qOz7y0Odi1xGOOJ6keHLdNG4kIqLGKuFNLzETc5YRL4x9Ce6qkIQe0oYHBgwLczUKV spuMpWFrIYkoHgvTPw0U3TtzShqgebu4emw/86CIAGi8nKL7pvPH4swYnuP9AWMO7DDU prp1qMw1iCgT66Bm8Br70r1rtNGo5cqyl/XayxWmJSyFdN9KN0CLVBNMDNDOZxvPLCI1 XhBAmIGEhhcdUNsmuYd53PTTcdqLzt49NZ5KTJdkTE7G5mnQbu/0qCCiqIWNmbcDxftl 4yKKVXSR8n1eMGliIqLqhM1uk9SJLquhiozWn3oNYaElk38K7TkfUz0ubkAUIuym0Dlj IJ1g== 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 10-v6si10557210ple.60.2018.08.20.06.56.44; Mon, 20 Aug 2018 06:57:15 -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 S1726783AbeHTRKy (ORCPT + 99 others); Mon, 20 Aug 2018 13:10:54 -0400 Received: from mail.bootlin.com ([62.4.15.54]:41965 "EHLO mail.bootlin.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726147AbeHTRKx (ORCPT ); Mon, 20 Aug 2018 13:10:53 -0400 Received: by mail.bootlin.com (Postfix, from userid 110) id 41F4D2069C; Mon, 20 Aug 2018 15:55:06 +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 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 F200B204AE; Mon, 20 Aug 2018 15:54:55 +0200 (CEST) Date: Mon, 20 Aug 2018 15:54:51 +0200 From: Boris Brezillon To: David Laight Cc: 'Chuanhua Han' , "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: <20180820155451.03d770eb@bbrezillon> In-Reply-To: <109aeb2622924f20b29743746bb77ce2@AcuMS.aculab.com> References: <1534769013-43449-1-git-send-email-chuanhua.han@nxp.com> <109aeb2622924f20b29743746bb77ce2@AcuMS.aculab.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 On Mon, 20 Aug 2018 13:01:13 +0000 David Laight wrote: > From: Chuanhua Han > > Sent: 20 August 2018 13:44 > > Still no message here, and the subject prefix is still wrong. Fixes and Cc-stable tags should be placed here... > > Signed-off-by: Chuanhua Han > > --- > > Changes in v3: > > Rename variable name "val" to "opcode_addr_dummy_sum". > > Place the legitimacy of the transfer size(i.e., "pi_max_message_size(mem->spi)" and > > "opcode_addr_dummy_sum") into "if (! ctlr - > mem_ops | |! ctlr-> mem_ops->exec_op) {" > > structure and add "spi_max_transfer_size(mem->spi) and opcode_addr_dummy_sum". > > Adjust the formatting alignment of your code. > > "(unsigned long)op->data.nbytes" was modified to "(unsigned long)(op->data.nbytes)". > > > > Fixes: c36ff266dc82 ("spi: Extend the core to ease integration of SPI memory controllers") ... not here. The changelog should also contain a "Changes in v2" section. > > --- > > drivers/spi/spi-mem.c | 14 ++++++++++++++ > > 1 file changed, 14 insertions(+) > > > > diff --git a/drivers/spi/spi-mem.c b/drivers/spi/spi-mem.c > > index 990770d..5ec2bc9 100644 > > --- a/drivers/spi/spi-mem.c > > +++ b/drivers/spi/spi-mem.c > > @@ -328,10 +328,24 @@ 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 opcode_addr_dummy_sum = sizeof(op->cmd.opcode) + > > + op->addr.nbytes + > > + op->dummy.nbytes; > Yep, the var name is definitely too long. > I'd split that (and shorten the variable name) to avoid line wrap. Maybe: > > unsigned long 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 (spi_max_message_size(mem->spi) < opcode_addr_dummy_sum || > > + spi_max_transfer_size(mem->spi) < opcode_addr_dummy_sum) > > + return -EINVAL; > > Those comparisons are lexically backwards, you want 'value op constant'. > So: > if (len > spi_max_message_size(mem->spi) || > len > spi_max_transfer_size(mem->spi)) > return -EINVAL. > Although I'm surprised you need to do both comparisons. Indeed, spi_max_transfer_size() is enough since it already does a min() with spi_max_message_size(). > > > + > > + op->data.nbytes = min3((unsigned long)(op->data.nbytes), Hm, you should have a cast of size_t, I guess that's what kbuild robots reported. > > + spi_max_transfer_size(mem->spi), > > + spi_max_message_size(mem->spi) - > > + opcode_addr_dummy_sum); > > That looks like a strange limit... 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. > > > + } > > + > > return 0; > > } > > EXPORT_SYMBOL_GPL(spi_mem_adjust_op_size); > > -- > > 2.7.4 > > David > > - > Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK > Registration No: 1397386 (Wales) >