From patchwork Fri Apr 12 13:44:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Walle X-Patchwork-Id: 1923142 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=llrViJvw; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20201202 header.b=ZmzdkDDa; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:3::133; helo=bombadil.infradead.org; envelope-from=linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=patchwork.ozlabs.org) Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4VGHqk1XfCz1yYs for ; Fri, 12 Apr 2024 23:44:50 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=ezXn1bemALGL/IxsjuHJwdXY+X6kH2tE5LjZnwaFj3c=; b=llrViJvwoosz9f KJNlO7rwrqtOesr8LF9rExqCseUpBd5LLWKUsxXLN1/8U9IsfzASe6wvKGNylDhjA8c231/DIdNpH EFCaWGEfwYzGfAaUULccgdqkkeTbPzL36RYtlvqwJNBWvVMExi++qollaNEuDQH8+OKnAtJUaAhzN kLZr9Iq4esy2Pu0qMWeX/Qah0p7fb/IrujXLBX/3fCBCZAS7nR3WMP6lQccW/oZ3dSMeEWZMporSK JQWtUF61nf92jXUTJ3Y64ki+pJ/wYjVJ7W1WPB1Gd8N3IN5a/qhKZb1SHOP3KuJbFhzEmxYqnEmt5 pMbdfmyzmK9Eby9AmlPw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rvHCc-0000000HOJn-18ui; Fri, 12 Apr 2024 13:44:26 +0000 Received: from sin.source.kernel.org ([2604:1380:40e1:4800::1]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rvHCW-0000000HOFu-1umP for linux-mtd@lists.infradead.org; Fri, 12 Apr 2024 13:44:21 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sin.source.kernel.org (Postfix) with ESMTP id C6A5ACE3914; Fri, 12 Apr 2024 13:44:18 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B3FAAC32781; Fri, 12 Apr 2024 13:44:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1712929458; bh=gKGUc/1cQbsMy5SwuoHZdZG4ZL+HCcopgsRqDXXZ9hs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ZmzdkDDascJuxzR8+nPCVHl7jYh25K94DrpS2ELa323WyinpN/GBlZSskLtax//Wk s3ApOWXuhhXGkqtOHgbpOGzG76/jpg99HGyYfTzNUDUez5VUwNNkPJQL9ITjCT4Fb0 jwO0sMyoWswWQEuYxKl8MA91tlMKrdMdlhJreZ30OMYFPZkRbsCdv3/mc2Usa5PTgK 6QdGoM+KYzLLu18GKoIZUJ8b0kkr9+VbyGosI4HSjCM4nQrqpI48ytJQln2dAsEy9i DbWp9qDQn0yWKa9emz+6CUFnH0YF2PHuMELxp8MQS6ogbFAx/suSVPxzwi8foGTom1 M7cqGMUZ/mMjQ== From: Michael Walle To: Tudor Ambarus , Pratyush Yadav , Miquel Raynal , Richard Weinberger , Vignesh Raghavendra Cc: linux-kernel@vger.kernel.org, linux-mtd@lists.infradead.org, Michael Walle Subject: [PATCH v1 2/6] mtd: spi-nor: get rid of non-power-of-2 page size handling Date: Fri, 12 Apr 2024 15:44:01 +0200 Message-Id: <20240412134405.381832-3-mwalle@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240412134405.381832-1-mwalle@kernel.org> References: <20240412134405.381832-1-mwalle@kernel.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240412_064420_718294_F6EA612F X-CRM114-Status: GOOD ( 14.53 ) X-Spam-Score: -2.3 (--) X-Spam-Report: Spam detection software, running on the system "bombadil.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: The Xilinx flashes were the only user of the page sized that were no power of 2. Support for them were dropped, thus we can also get rid of the special page size handling for it. Signed-off-by: Michael Walle --- drivers/mtd/spi-nor/core.c | 27 +++++++++++ 1 file changed, 11 insertions(+), 16 deletions(-) Content analysis details: (-2.3 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -2.3 RCVD_IN_DNSWL_MED RBL: Sender listed at https://www.dnswl.org/, medium trust [2604:1380:40e1:4800:0:0:0:1 listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain 2.3 TVD_SUBJ_WIPE_DEBT Spam advertising a way to eliminate debt -2.1 DKIMWL_WL_HIGH DKIMwl.org - High trust sender X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-mtd" Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org The Xilinx flashes were the only user of the page sized that were no power of 2. Support for them were dropped, thus we can also get rid of the special page size handling for it. Signed-off-by: Michael Walle Acked-by: Tudor Ambarus --- drivers/mtd/spi-nor/core.c | 27 +++++++++++---------------- 1 file changed, 11 insertions(+), 16 deletions(-) diff --git a/drivers/mtd/spi-nor/core.c b/drivers/mtd/spi-nor/core.c index cbe5f92eb0af..fb76e0522665 100644 --- a/drivers/mtd/spi-nor/core.c +++ b/drivers/mtd/spi-nor/core.c @@ -2098,7 +2098,7 @@ static int spi_nor_write(struct mtd_info *mtd, loff_t to, size_t len, size_t *retlen, const u_char *buf) { struct spi_nor *nor = mtd_to_spi_nor(mtd); - size_t page_offset, page_remain, i; + size_t i; ssize_t ret; u32 page_size = nor->params->page_size; @@ -2111,21 +2111,9 @@ static int spi_nor_write(struct mtd_info *mtd, loff_t to, size_t len, for (i = 0; i < len; ) { ssize_t written; loff_t addr = to + i; - - /* - * If page_size is a power of two, the offset can be quickly - * calculated with an AND operation. On the other cases we - * need to do a modulus operation (more expensive). - */ - if (is_power_of_2(page_size)) { - page_offset = addr & (page_size - 1); - } else { - u64 aux = addr; - - page_offset = do_div(aux, page_size); - } + size_t page_offset = addr & (page_size - 1); /* the size of data remaining on the first page */ - page_remain = min_t(size_t, page_size - page_offset, len - i); + size_t page_remain = min_t(size_t, page_size - page_offset, len - i); addr = spi_nor_convert_addr(nor, addr); @@ -3054,7 +3042,14 @@ static int spi_nor_init_params(struct spi_nor *nor) spi_nor_init_params_deprecated(nor); } - return spi_nor_late_init_params(nor); + ret = spi_nor_late_init_params(nor); + if (ret) + return ret; + + if (WARN_ON(!is_power_of_2(nor->params->page_size))) + return -EINVAL; + + return 0; } /** spi_nor_set_octal_dtr() - enable or disable Octal DTR I/O.