From: David Laight <david.laight.linux@gmail.com>
To: "Michael Walle" <mwalle@kernel.org>
Cc: "Arnd Bergmann" <arnd@kernel.org>,
"Pratyush Yadav" <pratyush@kernel.org>,
"Miquel Raynal" <miquel.raynal@bootlin.com>,
"Richard Weinberger" <richard@nod.at>,
"Vignesh Raghavendra" <vigneshr@ti.com>,
"Arnd Bergmann" <arnd@arndb.de>,
"Takahiro Kuwano" <takahiro.kuwano@infineon.com>,
"Tudor Ambarus" <tudor.ambarus@linaro.org>,
"HyeongJun An" <sammiee5311@gmail.com>,
<linux-mtd@lists.infradead.org>, <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] mtd: spi-nor: reduce stack usage in spi_nor_parse_sfdp()
Date: Mon, 21 Sep 2026 11:41:11 +0100 [thread overview]
Message-ID: <20260921114111.525a2257@pumpkin> (raw)
In-Reply-To: <20260921095924.2f845215@pumpkin>
On Mon, 21 Sep 2026 09:59:24 +0100
David Laight <david.laight.linux@gmail.com> wrote:
> On Mon, 21 Sep 2026 09:55:37 +0200
> "Michael Walle" <mwalle@kernel.org> wrote:
>
> > Hi Arnd,
> >
> > On Tue Sep 15, 2026 at 9:40 PM CEST, Arnd Bergmann wrote:
> > > From: Arnd Bergmann <arnd@arndb.de>
> > >
> > > Two large spi_nor_flash_parameter structures on a function stack
> > > is really too much, and this can exceed an otherwise reasonable
> > > frame limit:
> > >
> > > drivers/mtd/spi-nor/sfdp.c: In function 'spi_nor_parse_sfdp':
> > > drivers/mtd/spi-nor/sfdp.c:1717:1: error: the frame size of 1600 bytes is larger than 1536 bytes [-Werror=frame-larger-than=]
> > >
> > > Change one of them to a dynamic allocation to make this more reasonable.
> >
> > Thanks for taking care of that. Will you respin the patch with what
> > David suggested?
>
> This compiles...
It didn't - I thought I had compiled it :-(
Try:
diff --git a/drivers/mtd/spi-nor/sfdp.c b/drivers/mtd/spi-nor/sfdp.c
index 641f17ad51a0..cec699b52f27 100644
--- a/drivers/mtd/spi-nor/sfdp.c
+++ b/drivers/mtd/spi-nor/sfdp.c
@@ -1519,9 +1519,9 @@ int spi_nor_check_sfdp_signature(struct spi_nor *nor)
*/
int spi_nor_parse_sfdp(struct spi_nor *nor)
{
+ struct spi_nor_flash_parameter *save_params __free(kfree) = kmalloc_objs(*save_params, 2);
const struct sfdp_parameter_header *param_header, *bfpt_header;
struct sfdp_parameter_header *param_headers = NULL;
- struct spi_nor_flash_parameter params, params2;
struct sfdp_header header;
struct device *dev = nor->dev;
struct sfdp *sfdp;
@@ -1533,7 +1533,9 @@ int spi_nor_parse_sfdp(struct spi_nor *nor)
* Get a backup of all the parameter to roll back to in case of an
* error.
*/
- memcpy(¶ms, nor->params, sizeof(params));
+ if (!save_params)
+ return -ENOMEM;
+ save_params[0] = *nor->params;
/* Get the SFDP header. */
err = spi_nor_read_sfdp_dma_unsafe(nor, 0, sizeof(header), &header);
@@ -1653,7 +1655,7 @@ int spi_nor_parse_sfdp(struct spi_nor *nor)
/* Parse optional parameter tables. */
for (i = 0; i < header.nph; i++) {
- memcpy(¶ms2, nor->params, sizeof(params2));
+ save_params[1] = *nor->params;
param_header = ¶m_headers[i];
switch (SFDP_PARAM_HEADER_ID(param_header)) {
@@ -1691,7 +1693,7 @@ int spi_nor_parse_sfdp(struct spi_nor *nor)
* spi_nor_flash_parameter data.
*/
err = 0;
- memcpy(nor->params, ¶ms2, sizeof(*nor->params));
+ *nor->params = save_params[1];
}
}
@@ -1712,7 +1714,7 @@ int spi_nor_parse_sfdp(struct spi_nor *nor)
free_param_headers:
kfree(param_headers);
if (err)
- memcpy(nor->params, ¶ms, sizeof(*nor->params));
+ *nor->params = save_params[0];
return err;
}
--
David
...
> >
> > -michael
> >
> > > Fixes: d20029474a76 ("mtd: spi-nor: push the rollback mechanism into the sfdp module")
> > > Signed-off-by: Arnd Bergmann <arnd@arndb.de>
> > > ---
> > > drivers/mtd/spi-nor/sfdp.c | 10 +++++++---
> > > 1 file changed, 7 insertions(+), 3 deletions(-)
>
prev parent reply other threads:[~2026-09-21 10:41 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-15 19:40 Arnd Bergmann
2026-09-15 19:48 ` sashiko-bot
2026-09-16 10:05 ` David Laight
2026-09-21 7:55 ` Michael Walle
2026-09-21 8:59 ` David Laight
2026-09-21 9:24 ` Michael Walle
2026-09-21 10:41 ` David Laight [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260921114111.525a2257@pumpkin \
--to=david.laight.linux@gmail.com \
--cc=arnd@arndb.de \
--cc=arnd@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mtd@lists.infradead.org \
--cc=miquel.raynal@bootlin.com \
--cc=mwalle@kernel.org \
--cc=pratyush@kernel.org \
--cc=richard@nod.at \
--cc=sammiee5311@gmail.com \
--cc=takahiro.kuwano@infineon.com \
--cc=tudor.ambarus@linaro.org \
--cc=vigneshr@ti.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®