[PATCH] mtd: spi-nor: sfdp: Increase SFDP data size limit to 16 KiB

Takahiro Kuwano via B4 Relay posted 1 patch 1 week ago
drivers/mtd/spi-nor/sfdp.c | 14 ++++++++------
1 file changed, 8 insertions(+), 6 deletions(-)
[PATCH] mtd: spi-nor: sfdp: Increase SFDP data size limit to 16 KiB
Posted by Takahiro Kuwano via B4 Relay 1 week ago
From: Takahiro Kuwano <takahiro.kuwano@infineon.com>

The size of SFDP data read and cached is limited to avoid allocating
too much memory. The current limit is PAGE_SIZE, but the Spansion S25FS256S
has parameter tables at offsets beyond 4 KiB.

Increase the limit to 16 KiB to support such devices by introducing the
SFDP_MAX_SIZE macro.

Suggested-by: Miquel Raynal <miquel.raynal@bootlin.com>
Suggested-by: Michael Walle <mwalle@kernel.org>
Signed-off-by: Takahiro Kuwano <takahiro.kuwano@infineon.com>
---
 drivers/mtd/spi-nor/sfdp.c | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)

diff --git a/drivers/mtd/spi-nor/sfdp.c b/drivers/mtd/spi-nor/sfdp.c
index 641f17ad51a0..5d5bb6e587bf 100644
--- a/drivers/mtd/spi-nor/sfdp.c
+++ b/drivers/mtd/spi-nor/sfdp.c
@@ -115,6 +115,12 @@ struct sfdp_bfpt_erase {
 
 #define SFDP_4BAIT_DWORD_MAX	2
 
+/*
+ * Limit the total size of SFDP to a reasonable value to avoid allocating too
+ * much memory just of because the flash returned some insane values.
+ */
+#define SFDP_MAX_SIZE	SZ_16K
+
 struct sfdp_4bait {
 	/* The hardware capability. */
 	u32		hwcaps;
@@ -1594,14 +1600,10 @@ int spi_nor_parse_sfdp(struct spi_nor *nor)
 				  SFDP_PARAM_HEADER_PARAM_LEN(param_header));
 	}
 
-	/*
-	 * Limit the total size to a reasonable value to avoid allocating too
-	 * much memory just of because the flash returned some insane values.
-	 */
-	if (sfdp_size > PAGE_SIZE) {
+	if (sfdp_size > SFDP_MAX_SIZE) {
 		dev_dbg(dev, "SFDP data (%zu) too big, truncating\n",
 			sfdp_size);
-		sfdp_size = PAGE_SIZE;
+		sfdp_size = SFDP_MAX_SIZE;
 	}
 
 	sfdp = devm_kzalloc(dev, sizeof(*sfdp), GFP_KERNEL);

---
base-commit: a96edc3f0b4f036a5b6ebc9b1eca4273ef5ce2d0
change-id: 20260917-sfdp_size-f9d50cd0539d

Best regards,
--  
Takahiro Kuwano <takahiro.kuwano@infineon.com>
Re: [PATCH] mtd: spi-nor: sfdp: Increase SFDP data size limit to 16 KiB
Posted by Michael Walle 6 days, 15 hours ago
On Thu, 17 Sep 2026 14:02:15 +0900, Takahiro Kuwano wrote:
> The size of SFDP data read and cached is limited to avoid allocating
> too much memory. The current limit is PAGE_SIZE, but the Spansion S25FS256S
> has parameter tables at offsets beyond 4 KiB.
> 
> Increase the limit to 16 KiB to support such devices by introducing the
> SFDP_MAX_SIZE macro.
> 
> [...]

Applied, thanks!

[1/1] mtd: spi-nor: sfdp: Increase SFDP data size limit to 16 KiB
      commit: 935457a1ddc90921c3a3444f8bb7aaa97d2af55c

Best regards,
-- 
Michael Walle <mwalle@kernel.org>
Re: [PATCH] mtd: spi-nor: sfdp: Increase SFDP data size limit to 16 KiB
Posted by Miquel Raynal 1 week ago
On 17/09/2026 at 14:02:15 +09, Takahiro Kuwano via B4 Relay <devnull+takahiro.kuwano.infineon.com@kernel.org> wrote:

> From: Takahiro Kuwano <takahiro.kuwano@infineon.com>
>
> The size of SFDP data read and cached is limited to avoid allocating
> too much memory. The current limit is PAGE_SIZE, but the Spansion S25FS256S
> has parameter tables at offsets beyond 4 KiB.
>
> Increase the limit to 16 KiB to support such devices by introducing the
> SFDP_MAX_SIZE macro.
>
> Suggested-by: Miquel Raynal <miquel.raynal@bootlin.com>
> Suggested-by: Michael Walle <mwalle@kernel.org>
> Signed-off-by: Takahiro Kuwano <takahiro.kuwano@infineon.com>

Acked-by: Miquel Raynal <miquel.raynal@bootlin.com>