All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: han.xu@oss.nxp.com
Cc: "Michael Walle" <mwalle@kernel.org>,
	"Takahiro Kuwano" <takahiro.kuwano@infineon.com>,
	"Miquel Raynal" <miquel.raynal@bootlin.com>,
	Frank.Li@kernel.org, imx@lists.linux.dev,
	"Vignesh Raghavendra" <vigneshr@ti.com>,
	"Pratyush Yadav" <pratyush@kernel.org>,
	"Richard Weinberger" <richard@nod.at>
Subject: Re: [PATCH] mtd: rawnand: gpmi: add debugfs entry for BCH geometry
Date: Mon, 27 Jul 2026 21:25:44 +0000	[thread overview]
Message-ID: <20260727212544.CA63A1F00A3A@smtp.kernel.org> (raw)
In-Reply-To: <20260727-nand_debugfs-v1-1-7cba1ceab5ee@nxp.com>

Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [High] Missing cleanup of debugfs entries leads to a Use-After-Free on device unbind or module unload.
- [Medium] The use of a static global variable for the debugfs blob wrapper and a hardcoded directory name breaks support for multiple device instances.
- [Medium] The `raw_mode` debugfs file is created with NULL file operations, making it completely non-functional.
--

--- Patch [1]: [PATCH] mtd: rawnand: gpmi: add debugfs entry for BCH geometry ---
commit 687d6ba8c3ad7f3c6c8dbd852caa00f732194bfb
Author: Han Xu <han.xu@nxp.com>

mtd: rawnand: gpmi: add debugfs entry for BCH geometry

Export the BCH geometry parameters via debugfs to aid debugging and
provide the necessary information for legacy kobs-ng tool. The debugfs
directory "gpmi-nand" is created under the root debugfs tree, exposing
the bch_geometry and raw_mode. The implementation is guarded with
#ifdef CONFIG_DEBUG_FS to avoid build failures.

> diff --git a/drivers/mtd/nand/raw/gpmi-nand/gpmi-nand.c b/drivers/mtd/nand/raw/gpmi-nand/gpmi-nand.c
> index c1f766cb225aa..3ceb8df7f8f93 100644
> --- a/drivers/mtd/nand/raw/gpmi-nand/gpmi-nand.c
> +++ b/drivers/mtd/nand/raw/gpmi-nand/gpmi-nand.c

[ ... ]

> @@ -732,6 +733,26 @@ static int common_nfc_set_geometry(struct gpmi_nand_data *this)
>  	return err;
>  }
>  
> +#ifdef CONFIG_DEBUG_FS
> +static struct debugfs_blob_wrapper dbg_bch_geo;

[Severity: Medium]
Since this blob wrapper is declared as a static global variable, what happens
if there are multiple instances of the GPMI NAND controller probed?

It looks like the second instance will overwrite the global .data pointer
with its own geometry pointer, causing all reads from the debugfs file to
return the geometry of the most recently probed device.

> +static void bch_create_debugfs(struct gpmi_nand_data *this)
> +{
> +	struct bch_geometry *bch_geo = &this->bch_geometry;
> +	struct dentry *dbg_root;
> +
> +	dbg_root = debugfs_create_dir("gpmi-nand", NULL);

[Severity: High]
Does this code leak the debugfs directory and files when the driver is
unbound or the module is unloaded?

It appears that gpmi_nand_remove() lacks a corresponding call to
debugfs_remove() or debugfs_remove_recursive() to tear down this tree.
Since bch_geo points to memory within gpmi_nand_data which is managed
by devres, can this lead to a use-after-free if userspace reads the
debugfs file after the device is unbound?

Additionally, hardcoding the debugfs directory name to "gpmi-nand" might
cause creation conflicts if multiple controller instances are present.

> +	dbg_bch_geo.data = (void *)bch_geo;
> +	dbg_bch_geo.size = sizeof(struct bch_geometry);
> +	debugfs_create_blob("bch_geometry", 0444, dbg_root, &dbg_bch_geo);
> +	/* create raw mode flag */
> +	debugfs_create_file_full("raw_mode", 0444, dbg_root, NULL, NULL, NULL);

[Severity: Medium]
Are we passing NULL for the file operations here?

If the fops parameter is NULL, the debugfs core assigns
debugfs_noop_file_operations, which simply returns EOF (0 bytes) when
read. Does this make the raw_mode debugfs file completely non-functional
instead of exposing the intended boolean flag?

> +}

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260727-nand_debugfs-v1-1-7cba1ceab5ee@nxp.com?part=1

  reply	other threads:[~2026-07-27 21:25 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-27 21:09 [PATCH] mtd: rawnand: gpmi: add debugfs entry for BCH geometry han.xu
2026-07-27 21:09 ` han.xu
2026-07-27 21:25 ` sashiko-bot [this message]
2026-07-29  8:05 ` Miquel Raynal
2026-07-29  8:05   ` 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=20260727212544.CA63A1F00A3A@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=Frank.Li@kernel.org \
    --cc=han.xu@oss.nxp.com \
    --cc=imx@lists.linux.dev \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.