From patchwork Tue Sep 22 09:21:35 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Thomson X-Patchwork-Id: 1368860 X-Patchwork-Delegate: vigneshr@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2001:8b0:10b:1231::1; helo=merlin.infradead.org; envelope-from=linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=johnthomson.fastmail.com.au Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=merlin.20170209 header.b=b7UcfVn7; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=fastmail.com.au header.i=@fastmail.com.au header.a=rsa-sha256 header.s=fm1 header.b=VSew1aLs; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=messagingengine.com header.i=@messagingengine.com header.a=rsa-sha256 header.s=fm3 header.b=aIR6i0m7; dkim-atps=neutral Received: from merlin.infradead.org (merlin.infradead.org [IPv6:2001:8b0:10b:1231::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4BwbTM4PTRz9sPB for ; Tue, 22 Sep 2020 19:23:35 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:Message-Id:Date:Subject:To:From: Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender :Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Owner; bh=lSSaTcaooRO71e93+tbzl6fBUGR0bv9jAGHN5YIfHAk=; b=b7UcfVn7BTr99md1ToSAGRh6Iy GANFXUdd+FNmOTsBUI40hJ5b8vX12Mr6gmPdAVUWhsj/VvtLLj9jKjBzF5TN3YvQnHOnMN8iO4a4K ZPQbMGzDKylSanjQ+D4AB5PueadS5EAb0pGgmW1KbYaK5V2RaPm1p5GEV36CUDno+UhHSWacHSI4G kKvJPNKzgoOnt/rz9u+wXkRTzULrIrXzsvCcQEClWnkmPwr+Vw91M+LpadgpDWsto+Gjhx4rM6sg/ gBfSgtynhN69hbOkDIQclx5CiSVKY/bwAZWD4RLpeGiE5iLoEXaQ8JrNk9pu4an7phXEOVQBBXiaO qbHIRi0w==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kKeVN-0007Zf-Oo; Tue, 22 Sep 2020 09:22:33 +0000 Received: from wout2-smtp.messagingengine.com ([64.147.123.25]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kKeVL-0007ZG-D9 for linux-mtd@lists.infradead.org; Tue, 22 Sep 2020 09:22:32 +0000 Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailout.west.internal (Postfix) with ESMTP id 5764EBDC; Tue, 22 Sep 2020 05:22:26 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute3.internal (MEProxy); Tue, 22 Sep 2020 05:22:26 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fastmail.com.au; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; s=fm1; bh=Dpo8fd7WQF/7KvGkxkvN2Kqn7G q/lyc78grZPan3hZ8=; b=VSew1aLsv8vLzXj7gsg8xMiBUn72zudA/nyYk9MDV9 StGozM1sW586JGGbgpaFb9lHIbRhUqSefG2CIj4HaoHEah+iRJ/6162o3nsEGB86 DsayiXYUu6NqdzuCivfwUQjPz7+kIDmAkCdGej0dnY7qFfuNCkChtAXOoyLTzPMl ocu596yf3uCkSybxLTGQePPFpc1ca5xh8QiLOX6XlmTRv5yafBXnQGUmwmzbSIRk m47VGJQUi4wvXYqSzPj+uGf2pEQynsFZ3h4VDv9TE8UDiwKawYDj7K62f3Xog6TZ B+bREdJmoeSpLmlzVn47ggpI531zCrJuk6fRCSMV68dw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:date:from :message-id:mime-version:subject:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm3; bh=Dpo8fd7WQF/7KvGkx kvN2Kqn7Gq/lyc78grZPan3hZ8=; b=aIR6i0m7aMacR2sMs0LYK6rWKET8IXbtQ MSiUoxiyxo1Vtl77+qx4HbRnGfXrxMcl0tyOFbRPKWRRJ7INpcOx/ria7mKTNNp/ OzDJLYDnf1+BQlCmCJx991+5oCP62/BDTnwJpRDVQ6jiiINP/uSHy3Qvj7Fcs80M m6bb/ehWHG7mV6GvEWpbOcta1m6M4Pp1y9BsbtW28YymD2CMIs8bwd4SqzCawWxA fXrHk9sigS1qD4jB+pdHllQDzzMumHRmU0r4M/3LL8NdYlOoUeXAPgBoKDThBCJU PZ5nCuPw4vsz+pq/WkE/fMQfbjt0ASmJmXn0imMI2gqd89G3RZVwA== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedujedrudeggdduiecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpefhvffufffkofgggfestdekredtredttdenucfhrhhomheplfhohhhnucfvhhho mhhsohhnuceoghhithesjhhohhhnthhhohhmshhonhdrfhgrshhtmhgrihhlrdgtohhmrd gruheqnecuggftrfgrthhtvghrnhepffefiefhudektdeuudefteeiueduhfehhfekhfet gfdtueffkeffleelteevudeinecukfhppeehkedrudeihedrjedvrddujeehnecuvehluh hsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepghhithesjhhohhhn thhhohhmshhonhdrfhgrshhtmhgrihhlrdgtohhmrdgruh X-ME-Proxy: Received: from john.thome.spur.red (unknown [58.165.72.175]) by mail.messagingengine.com (Postfix) with ESMTPA id B31E43280068; Tue, 22 Sep 2020 05:22:22 -0400 (EDT) From: John Thomson To: Tudor Ambarus , Miquel Raynal , Richard Weinberger , Vignesh Raghavendra , linux-mtd@lists.infradead.org Subject: [PATCH RFC] mtd: spi nor: fix erase_map.regions after memcpy for uniform eraseregion Date: Tue, 22 Sep 2020 19:21:35 +1000 Message-Id: <20200922092135.167951-1-git@johnthomson.fastmail.com.au> X-Mailer: git-send-email 2.28.0 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200922_052231_844787_2AB2F22E X-CRM114-Status: GOOD ( 12.92 ) X-Spam-Score: -0.8 (/) X-Spam-Report: SpamAssassin version 3.4.4 on merlin.infradead.org summary: Content analysis details: (-0.8 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at https://www.dnswl.org/, low trust [64.147.123.25 listed in list.dnswl.org] -0.0 SPF_HELO_PASS SPF: HELO matches SPF record -0.0 SPF_PASS SPF: sender matches SPF record 0.0 RCVD_IN_MSPIKE_H3 RBL: Good reputation (+3) [64.147.123.25 listed in wl.mailspike.net] -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid 0.0 RCVD_IN_MSPIKE_WL Mailspike good senders X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: John Thomson Sender: "linux-mtd" Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org For a uniform erase regions device, erase_map.regions points to the address of erase_map.uniform_region. There is a memcpy of nor->params, which includes erase_map.regions, and erase_map.uniform_region. The memcpy destination erase_map.regions pointer needs to be updated to the new address of uniform_region. Without this change, when a uniform erase region spi-nor device used the multiple erase regions code path, e.g. spi_nor_has_uniform_erase forced to return false, erase operations failed in find_erase_region. This code path is not currently used for uniform eraseregion devices, but is useful to allow use of minor (4K) erase while otherwise using 64K erase. Signed-off-by: John Thomson --- Only build tested on master, what devices or approach is used to test master MTD SPI NOR? Found and tested in kernel 5.4 on Openwrt on a MIPS access point, while testing changes to mtdpart.c to allow writes for partitions on 4K (minor) erase boundaries. with: - CONFIG_MTD_SPI_NOR_USE_4K_SECTORS is not set - spi_nor_has_uniform_erase forced to return false, so that a request for a 4K erase could use the multiple erase sectors code path on a uniform erase regions SPI NOR device. --- drivers/mtd/spi-nor/core.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/drivers/mtd/spi-nor/core.c b/drivers/mtd/spi-nor/core.c index 65eff4ce6ab..30f5db65781 100644 --- a/drivers/mtd/spi-nor/core.c +++ b/drivers/mtd/spi-nor/core.c @@ -2716,12 +2716,20 @@ static void spi_nor_sfdp_init_params(struct spi_nor *nor) struct spi_nor_flash_parameter sfdp_params; memcpy(&sfdp_params, nor->params, sizeof(sfdp_params)); + if (nor->params->erase_map.regions == + &nor->params->erase_map.uniform_region) + sfdp_params.erase_map.regions = ( + &sfdp_params.erase_map.uniform_region); if (spi_nor_parse_sfdp(nor, &sfdp_params)) { nor->addr_width = 0; nor->flags &= ~SNOR_F_4B_OPCODES; } else { memcpy(nor->params, &sfdp_params, sizeof(*nor->params)); + if (sfdp_params.erase_map.regions == + &sfdp_params.erase_map.uniform_region) + nor->params->erase_map.regions = ( + &nor->params->erase_map.uniform_region); } }