From: sashiko-bot@kernel.org
To: "Michael Walle" <mwalle@kernel.org>,
"Arnd Bergmann" <arnd@kernel.org>,
"Vignesh Raghavendra" <vigneshr@ti.com>,
"Richard Weinberger" <richard@nod.at>,
"Pratyush Yadav" <pratyush@kernel.org>,
"Miquel Raynal" <miquel.raynal@bootlin.com>
Cc: "HyeongJun An" <sammiee5311@gmail.com>,
"Arnd Bergmann" <arnd@arndb.de>,
"Tudor Ambarus" <tudor.ambarus@linaro.org>,
linux-mtd@lists.infradead.org, linux-kernel@vger.kernel.org,
"Takahiro Kuwano" <takahiro.kuwano@infineon.com>
Subject: Re: [PATCH] mtd: spi-nor: reduce stack usage in spi_nor_parse_sfdp()
Date: Tue, 15 Sep 2026 19:48:32 +0000 [thread overview]
Message-ID: <20260915194833.245E51F000FF@smtp.kernel.org> (raw)
In-Reply-To: <20260915194203.3511147-1-arnd@kernel.org>
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [Medium] mtd: spi-nor: mixing goto and scope-based cleanup in spi_nor_parse_sfdp()
- [Low] mtd: spi-nor: split definition and initialization of __free() variable
--
commit 1f040dc109ef8aa4b9fc1c81bcaa8f6e6a5a27c0
Author: Arnd Bergmann <arnd@arndb.de>
mtd: spi-nor: reduce stack usage in spi_nor_parse_sfdp()
This commit reduces stack usage in spi_nor_parse_sfdp() by replacing an
on-stack struct spi_nor_flash_parameter variable with a dynamically allocated
one. It utilizes the __free(kfree) scope-based cleanup helper to manage the
allocated memory.
> diff --git a/drivers/mtd/spi-nor/sfdp.c b/drivers/mtd/spi-nor/sfdp.c
> index 641f17ad51a09..466558ea528d8 100644
> --- a/drivers/mtd/spi-nor/sfdp.c
> +++ b/drivers/mtd/spi-nor/sfdp.c
> @@ -1521,7 +1521,7 @@ int spi_nor_parse_sfdp(struct spi_nor *nor)
> {
> const struct sfdp_parameter_header *param_header, *bfpt_header;
> struct sfdp_parameter_header *param_headers = NULL;
> - struct spi_nor_flash_parameter params, params2;
> + struct spi_nor_flash_parameter __free(kfree) *params = NULL;
[Severity: Low]
Does this split definition and initialization of the params pointer violate
the cleanup subsystem guidelines?
The guidelines recommend defining and initializing scope-based cleanup
variables in a single statement (such as at the kmemdup call below) rather
than initializing to NULL at the top with assignment later. While this
specific case might not trigger a LIFO ordering bug since there are no
guard() locks present, it does bypass the subsystem recommendation designed
to prevent those ordering mistakes.
> 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));
> + params = kmemdup(nor->params, sizeof(*params), GFP_KERNEL);
> + if (!params)
> + return -ENOMEM;
>
> /* Get the SFDP header. */
[ ... ]
> @@ -1712,7 +1716,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));
> + memcpy(nor->params, params, sizeof(*nor->params));
>
> return err;
> }
[Severity: Medium]
Is it safe to mix goto-based error handling with scope-based cleanup in
this function?
The kernel cleanup subsystem guidelines dictate that goto-based error
handling and scope-based cleanups should never be mixed in the same
function. Retaining the free_param_headers goto label and other manual
cleanups in spi_nor_parse_sfdp() while introducing __free(kfree) for params
violates the 'all-or-nothing' conversion rule and can create confusing
ownership semantics.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260915194203.3511147-1-arnd@kernel.org?part=1
next prev parent reply other threads:[~2026-09-15 19:48 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-15 19:40 Arnd Bergmann
2026-09-15 19:48 ` sashiko-bot [this message]
2026-09-16 10:05 ` David Laight
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=20260915194833.245E51F000FF@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--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=sashiko-reviews@lists.linux.dev \
--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®