Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp1823031imm; Thu, 16 Aug 2018 03:16:56 -0700 (PDT) X-Google-Smtp-Source: AA+uWPxoUmP/3Qzzr+4TCfLFgNR+pE7YYnLzSFKCp770CVxKHYpGBqB4RDZvpbt7eZRYoAUhLBax X-Received: by 2002:a62:9541:: with SMTP id p62-v6mr31306429pfd.152.1534414616819; Thu, 16 Aug 2018 03:16:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1534414616; cv=none; d=google.com; s=arc-20160816; b=iPWR2s0YhsMI31Bb3klDx2O0ZfLSFMummOY4Bayki8tjqSxtvT5Vtvq12cUN+TuCMS A6aD9uaQwjkbJ534QG31i6+zUzVHkuKiWvqSByuxpyDgINbSdYu0eSI1YZyokeOnETuV 0Z0/6wyqLIam9i0M+66XFTyaGJpUpCrWnx1Dj5qLT6XNXwHil6b7i5W3DevaQcMguWy9 eOLx6sOolEDL5vCQi/lDwPM015JCD79B8VL4OmLYKDH8QEVnDnMVGVlzE2MDR8l8pH38 Flr0kTcH9hNqbw+8K/rkqWn4r0ZWJ4+bTwv/CpU3pU6ZTIWQivr31LOAjNoZDYQ8DD4v +P8w== 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=ig0rFi9APE5+Dgd1DXgl98b/wCzFThcDFq5Qh1m46RQ=; b=s3loDi7nJy3Ci4NLveK+kOcpaDeElaotF0RVGA5ELNnR0Bel3u/0dFMdfkRYrnIED4 7yPy2+fqG6dPKi9BBTf5R6vhVmPNAccocGXDmh6+0LMa7K2JEJ5r8ReU58y0LOCdB6jo hdmrZUUYWW0YmY+LKxss7qHEH8OAwY4zIBi6HB1C7Uc+O4wJDeTtlSjHIx7Sf7qHjAV9 0+Iz3+mQG5ExHe15vK5wrueag5P2rwmT+5dfVu52+iKZl6QR0mQKwf74sl3bCuzWU9EJ eE3UpYWOH+dKF+J9A4dEc3I3VjWCaCkNMAzD0h+85r4GXnshyRTJ8JECPW7Q8/nISqr/ 5nOA== 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 o1-v6si21485941pld.223.2018.08.16.03.16.41; Thu, 16 Aug 2018 03:16:56 -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 S2388996AbeHPJ3W (ORCPT + 99 others); Thu, 16 Aug 2018 05:29:22 -0400 Received: from mail.bootlin.com ([62.4.15.54]:48442 "EHLO mail.bootlin.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726335AbeHPJ3W (ORCPT ); Thu, 16 Aug 2018 05:29:22 -0400 Received: by mail.bootlin.com (Postfix, from userid 110) id 5F896207F3; Thu, 16 Aug 2018 08:33:07 +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 (unknown [91.160.177.164]) by mail.bootlin.com (Postfix) with ESMTPSA id 11D2F20731; Thu, 16 Aug 2018 08:33:07 +0200 (CEST) Date: Thu, 16 Aug 2018 08:33:07 +0200 From: Boris Brezillon To: Chuanhua Han Cc: dwmw2@infradead.org, computersforpeace@gmail.com, marek.vasut@gmail.com, richard@nod.at, cyrille.pitchen@wedev4u.fr, broonie@kernel.org, pp@emlix.com, Zhiqiang.Hou@nxp.com, linux-mtd@lists.infradead.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] mtd: m25p80: consider max message size in m25p80_read when use the spi_mem_xx() API Message-ID: <20180816083307.684bdb72@bbrezillon> In-Reply-To: <1534314823-14048-1-git-send-email-chuanhua.han@nxp.com> References: <1534314823-14048-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 Wed, 15 Aug 2018 14:33:43 +0800 Chuanhua Han wrote: > Consider a message size limit when calculating the maximum amount > of data that can be read. > > Signed-off-by: Chuanhua Han > --- > drivers/mtd/devices/m25p80.c | 7 ++++++- > 1 file changed, 6 insertions(+), 1 deletion(-) > > diff --git a/drivers/mtd/devices/m25p80.c b/drivers/mtd/devices/m25p80.c > index e84563d..87efa56 100644 > --- a/drivers/mtd/devices/m25p80.c > +++ b/drivers/mtd/devices/m25p80.c > @@ -128,7 +128,12 @@ static ssize_t m25p80_read(struct spi_nor *nor, loff_t from, size_t len, > op.dummy.nbytes = (nor->read_dummy * op.dummy.buswidth) / 8; > > while (remaining) { > - op.data.nbytes = remaining < UINT_MAX ? remaining : UINT_MAX; > + op.data.nbytes = min3(remaining, > + spi_max_transfer_size(flash->spimem->spi), > + spi_max_message_size(flash->spimem->spi) - > + sizeof(op.cmd.opcode) - > + op.addr.nbytes - > + op.dummy.nbytes); Nope, this sort of things should go in the SPI controller driver ->adjust_op_size() hook or directly in spi_mem_adjust_op_size() if it's generic enough (which doesn't seem to be the case since your not counting the opcode, addr and dummy bytes in the message length). Regards, Boris