Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp6705965imu; Wed, 14 Nov 2018 05:52:19 -0800 (PST) X-Google-Smtp-Source: AJdET5dNpiVsAdvaLOFYp70JJyTkMjJjsKWWm3whkcUNf/pLX9saldr+oJGW2F5J4ttRXmzOq3zf X-Received: by 2002:a63:2d46:: with SMTP id t67mr1883069pgt.140.1542203539154; Wed, 14 Nov 2018 05:52:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542203539; cv=none; d=google.com; s=arc-20160816; b=IKf664mJWaXtwhiq0tTe5eJmf26VKhx6XMRUKcVNeeoKtEDDFbT+OMjFZqGggcDu0c O0p2s/vI3//nAnudU3lqnEX1WA5Giwka/bfBAOlUTvTEwNkpt9qkQkse/w7i0iXPB7j7 CObPKVU7cJjQB/FmhaGpmTXTAcOhEtQZc7NxbVR153E4lq7kbHsEZ/SlNz6NnevZvjm+ eHurx0M4jDOwDqjKRitFhUW6C0rN7XkjVhOVIYMY0bPcFw5vTJ/D7s4qbOSee0CtU9P3 xhVOyEwncg8tYbS+YkWQOnpaH+zmuFU0iDilTTv6YJ4zvdCMsydP7WqJmleyk+lev/4C w8gw== 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; bh=ZGQny9r2UcM/DjBC4ZF0cJ0lEXbcTQ29esq7pLb6W2o=; b=rZN0nSARhUkaNVEOaT0HpO79alV3wRjI4/ZKdUbEtgoUJxKQtEmma39V5u51wQSyXr AzX9LUPFStXM3OglIy50/kbtw1RG9vBHjFEbZ45ZhpoyYVi4JcmjF0CBt1TMECqMaixY j2x501oJ5SpYViRATTyO3uQe1S/GiMfEbta55gK8CaaxPcqpGGndydzw/GVkewQ69vWC tEagNaPczZVlj2A/FAex5kVIV37+Jp46cNxr5lVBAY45NOaN13ZRJgxp2RWM+U//9rQM QW1tjnMoSkVYPQMAPLycZld8ySHBSDKWFzj1IbrbLxuekWXc+31WCvt/nuSVR5OVo7J+ juiA== 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 w19si18106129pgf.573.2018.11.14.05.52.03; Wed, 14 Nov 2018 05:52:19 -0800 (PST) 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 S1732677AbeKNXyy (ORCPT + 99 others); Wed, 14 Nov 2018 18:54:54 -0500 Received: from mail.bootlin.com ([62.4.15.54]:37363 "EHLO mail.bootlin.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726823AbeKNXyy (ORCPT ); Wed, 14 Nov 2018 18:54:54 -0500 Received: by mail.bootlin.com (Postfix, from userid 110) id 650AB20747; Wed, 14 Nov 2018 14:51:33 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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.2 Received: from bbrezillon (aaubervilliers-681-1-30-49.w90-88.abo.wanadoo.fr [90.88.15.49]) by mail.bootlin.com (Postfix) with ESMTPSA id 171E92072C; Wed, 14 Nov 2018 14:51:33 +0100 (CET) Date: Wed, 14 Nov 2018 14:51:29 +0100 From: Boris Brezillon To: Liu Xiang Cc: linux-mtd@lists.infradead.org, linux-kernel@vger.kernel.org, marek.vasut@gmail.com, dwmw2@infradead.org, computersforpeace@gmail.com, richard@nod.at, liuxiang_1999@126.com, Tudor Ambarus Subject: Re: [PATCH] mtd: spi-nor: Return error when nor->addr_width not match the device size Message-ID: <20181114145129.568e4bb3@bbrezillon> In-Reply-To: <1542200165-3073-1-git-send-email-liu.xiang6@zte.com.cn> References: <1542200165-3073-1-git-send-email-liu.xiang6@zte.com.cn> X-Mailer: Claws Mail 3.16.0 (GTK+ 2.24.32; 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 Wed, 14 Nov 2018 20:56:05 +0800 Liu Xiang wrote: > In is25lp256, the DWORD1 of JEDEC Basic Flash Parameter Header > is 0xfff920e5. So the DWORD1[18:17] Address Bytes bits are 0b00, > means that 3-Byte only addressing. According to your other patch this NOR supports 4B opcode, which means the SFDP table is wrong. > But the device size is larger > than 16MB, nor->addr_width must be 4 to access the whole address. > An error should be returned when nor->addr_width not match ^does not > the device size in spi_nor_parse_sfdp(). > > Suggested-by: Boris Brezillon > Signed-off-by: Liu Xiang > --- > drivers/mtd/spi-nor/spi-nor.c | 4 ++++ > 1 file changed, 4 insertions(+) > > diff --git a/drivers/mtd/spi-nor/spi-nor.c b/drivers/mtd/spi-nor/spi-nor.c > index 3eba13a..77eaf22 100644 > --- a/drivers/mtd/spi-nor/spi-nor.c > +++ b/drivers/mtd/spi-nor/spi-nor.c > @@ -2669,6 +2669,10 @@ static int spi_nor_parse_bfpt(struct spi_nor *nor, > } > params->size >>= 3; /* Convert to bytes. */ > > + /*if the device exceeds 16MiB, addr_width must be 4*/ Please add a white space after '/*' and before '*/': /* If the device exceeds 16MiB, ->addr_width must be 4. */ > + if ((params->size > 0x1000000) && (nor->addr_width == 3)) Parens are not needed around sub-conditions: if (params->size > 0x1000000 && nor->addr_width == 3) > + return -EINVAL; > + I'm not sure this is correct. Looks like some NORs only support 3B opcodes but have a "4-byte addressing" mode (see set_4byte() [1]). Don't know what's reported by the BFPT section in this case though (BFPT_DWORD1_ADDRESS_BYTES_3_ONLY or BFPT_DWORD1_ADDRESS_BYTES_3_OR_4). Anyway, I think this check should be moved here [2] to cover the non-SFDP case. > /* Fast Read settings. */ > for (i = 0; i < ARRAY_SIZE(sfdp_bfpt_reads); i++) { > const struct sfdp_bfpt_read *rd = &sfdp_bfpt_reads[i]; [1]https://elixir.bootlin.com/linux/v4.20-rc2/source/drivers/mtd/spi-nor/spi-nor.c#L278 [2]https://elixir.bootlin.com/linux/v4.20-rc2/source/drivers/mtd/spi-nor/spi-nor.c#L3758