Linux-mtd Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Michael Walle" <mwalle@kernel.org>,
	"Pratyush Yadav" <pratyush@kernel.org>,
	"Takahiro Kuwano" <takahiro.kuwano@infineon.com>,
	"Miquel Raynal" <miquel.raynal@bootlin.com>,
	"Richard Weinberger" <richard@nod.at>,
	"Vignesh Raghavendra" <vigneshr@ti.com>,
	"Arnd Bergmann" <arnd@arndb.de>,
	"David Laight" <david.laight.linux@gmail.com>
Cc: linux-mtd@lists.infradead.org
Subject: Re: [PATCH] mtd: spi-nor: sfdp: reduce stack usage in spi_nor_parse_sfdp()
Date: Thu, 15 Oct 2026 09:18:26 +0000	[thread overview]
Message-ID: <sashiko-outbox-172559@kernel.org> (raw)
In-Reply-To: <20261015090516.924703-1-mwalle@kernel.org>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] cleanup: mixing goto-based cleanup and __free() in spi_nor_parse_sfdp()
--

commit 487c324880f913694192ab54591472cbb5bb22c0
Author: Michael Walle <mwalle@kernel.org>

mtd: spi-nor: sfdp: reduce stack usage in spi_nor_parse_sfdp()

This commit allocates the rollback copies of spi_nor_flash_parameter
structures on the heap to reduce stack usage in spi_nor_parse_sfdp().

> diff --git a/drivers/mtd/spi-nor/sfdp.c b/drivers/mtd/spi-nor/sfdp.c
> index beb0f5c66212c..e30cdb5b18ede 100644
> --- a/drivers/mtd/spi-nor/sfdp.c
> +++ b/drivers/mtd/spi-nor/sfdp.c
> @@ -1535,9 +1535,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;

[ ... ]

> @@ -1724,7 +1726,7 @@ int spi_nor_parse_sfdp(struct spi_nor *nor)
>  free_param_headers:
>  	kfree(param_headers);
>  	if (err)
> -		memcpy(nor->params, &params, sizeof(*nor->params));
> +		*nor->params = save_params[0];
>  
>  	return err;
>  }

[Severity: Medium]
Is it safe to mix scope-based cleanup with goto labels in this function?

The patch introduces a scope-based cleanup helper __free(kfree) for
save_params, but leaves multiple existing goto error labels (such as
free_param_headers, free_sfdp, and free_dwords) untouched in
spi_nor_parse_sfdp().

The cleanup subsystem guidelines state that the expectation is that usage of
goto and cleanup helpers is never mixed in the same function. 

Could this lead to confusing ownership semantics, and should all resources in
this routine be converted to scope-based cleanup (or none of them)?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261015090516.924703-1-mwalle@kernel.org?part=1

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

  reply	other threads:[~2026-10-15  9:18 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-15  9:01 [PATCH] mtd: spi-nor: sfdp: reduce stack usage in spi_nor_parse_sfdp() Michael Walle
2026-10-15  9:18 ` sashiko-bot [this message]
2026-10-15 10:04 ` Miquel Raynal

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=sashiko-outbox-172559@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=arnd@arndb.de \
    --cc=david.laight.linux@gmail.com \
    --cc=linux-mtd@lists.infradead.org \
    --cc=miquel.raynal@bootlin.com \
    --cc=mwalle@kernel.org \
    --cc=pratyush@kernel.org \
    --cc=richard@nod.at \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=takahiro.kuwano@infineon.com \
    --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