Received: by 2002:ab2:7041:0:b0:1f4:bcc8:f211 with SMTP id x1csp155863lql; Fri, 12 Apr 2024 06:44:40 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWkOu7LjiAiKVS1JcjAawyejPWtA5RtJYnvA0S/qPm35o27oEWAb9b4Z7nDkxcPjTwECahYfyQs3uvHxB3/b2oXtXMPw6vEm5yCX25dQA== X-Google-Smtp-Source: AGHT+IFNMBrJkHSZdyVdjnFiMz0mLOl5IlaJgFeDZIydtQpPm4sYappLp2o55HuD6RiAaQIBRRQ/ X-Received: by 2002:a05:620a:124e:b0:78e:cb92:9010 with SMTP id a14-20020a05620a124e00b0078ecb929010mr2084168qkl.30.1712929479833; Fri, 12 Apr 2024 06:44:39 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712929479; cv=pass; d=google.com; s=arc-20160816; b=uY0jMy3q+gXhvpHg/RF3MDcr0fjWVuTMEkJwqQ8EpjA/MxqNcuvliZjBnWRMEFOIkR dGS+YRLlMnYdIV1gR5jUUEbHLuq/T0O6nyuu14+i+uUojwyRbMBiivDS+D3oCGoJWoW7 t4CHlOzJusRJQ6E6NtnyckbyFDq7TjOfM5O04oNX0qE7qZG6JC1GJUNEtDnDxl50Vsw8 Q9qU/ISp7Ysk1BLmK4O63m9zvDDcVr6AgK84kZRCCuGNFxSv1z5hRfJJRnJVRdm3bnVS 9+Q/BYJvBchV8tLm4g2x4ufUMRcXmXxRFNL9MchBiu9ymCOPEnkZ34+waHzC3JUxX+c9 xqVQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=Zjxp4zQRWwCOqtYMjuBw87eD43K1qCODHwLBeEnFvhI=; fh=LuNSX3JVG+htsysoJ/xF51pAKitwHo02H/zRZAOLqDw=; b=N6Bgb/pANAMsVMq0YTyhhbChTF19F1J09p3dSiw1xF5Mu8A1iHANnRrgXzMB3Qg0SC tiy0IGA7h3WR4zdJ3s5qmalQ2bdUepBFnMgC1Kb3w4eFm0GhdOeIXIffPTBef98N1s8D udKaBCd307PhQhFZfBYPxeO06/xQqWyXoGG7/BR7XDF/QHU9hIgLgG20+amy/rl8kA8r roiLqhnn4SvCndtgYI7I0h/+MnwKCpW+dloidXvjcmsTns5nk1prhA4qAXsBRDBcU9hC 6w59JSS6pkKbsb0kz4NmbHS4BJ33rLzFGDj3QSxYoi/2uiZzTLG9fzIvnU+7tnYk2nbm WQkQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=ZmzdkDDa; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-142750-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-142750-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id y30-20020a05620a0e1e00b0078d3ac4bd54si3566819qkm.694.2024.04.12.06.44.39 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Apr 2024 06:44:39 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-142750-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=ZmzdkDDa; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-142750-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-142750-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 8C2201C23BE9 for ; Fri, 12 Apr 2024 13:44:39 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A216284E0E; Fri, 12 Apr 2024 13:44:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="ZmzdkDDa" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CE07F84E01 for ; Fri, 12 Apr 2024 13:44:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712929458; cv=none; b=GxmkbOhxSG3aD1VMkV/G6fGjmrR4QPx/5SFx+JF79boCBPIlVqnVlOTMH5IXnkVnk6U/hvJZbbmZvr2fPKGPCU57Bz6zf3dc1EhcwVvTJioBr70DLT7Zg73VASLSUBUIQCNW8o53qYxg4jH97l2FisW4wbi2eKrMQQmoeV52bGY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712929458; c=relaxed/simple; bh=gKGUc/1cQbsMy5SwuoHZdZG4ZL+HCcopgsRqDXXZ9hs=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=eqL+wR82kTTsGNjus9DJcYKuOlDIVn7tzVmjNgkll93hoKE+f+6Of/4AwffihQnalAQyaxKTqCZKV0E0sqbU+BAPssQfN48DvMBlO/qA/twu4ykukj2hbhJzpVLxZDEa/sge3gpHLRONigSBGGX89rgcxiDKhuL4UdU1xa8U4oc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ZmzdkDDa; arc=none smtp.client-ip=10.30.226.201 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> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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(-) 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. -- 2.39.2