All of lore.kernel.org
 help / color / mirror / Atom feed
From: Frank Li <Frank.li@oss.nxp.com>
To: han.xu@oss.nxp.com
Cc: Miquel Raynal <miquel.raynal@bootlin.com>,
	Richard Weinberger <richard@nod.at>,
	Vignesh Raghavendra <vigneshr@ti.com>,
	imx@lists.linux.dev, linux-mtd@lists.infradead.org,
	linux-kernel@vger.kernel.org, Han Xu <han.xu@nxp.com>
Subject: Re: [PATCH v2] mtd: rawnand: gpmi: add debugfs entry for BCH geometry
Date: Wed, 29 Jul 2026 15:40:44 -0500	[thread overview]
Message-ID: <amplTATeFqpGx7qe@SMW015318> (raw)
In-Reply-To: <20260729-nand_debugfs-v2-1-2631e92adcb2@nxp.com>

On Wed, Jul 29, 2026 at 02:22:20PM -0500, han.xu@oss.nxp.com wrote:
> From: Han Xu <han.xu@nxp.com>
>
> 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:
>
> bch_geometry  - blob containing the struct bch_geometry fields
> raw_mode      - flag indicating raw mode status
>
> The implementation is guarded with #ifdef CONFIG_DEBUG_FS to avoid
> build failures when debugfs is disabled.
>
> Signed-off-by: Han Xu <han.xu@nxp.com>
> ---
> Changes in v2:
> - Move dbg_root and dbg_bch_geo into struct gpmi_nand_data to fix
>   use-after-free on device unbind.
> - Replace debugfs_create_file_full() with debugfs_create_bool() to
>   expose the raw_mode flag.
> - Register a devm cleanup action to call debugfs_remove_recursive() on
>   driver removal.
>
> To: Han Xu <han.xu@nxp.com>
> To: Miquel Raynal <miquel.raynal@bootlin.com>
> To: Richard Weinberger <richard@nod.at>
> To: Vignesh Raghavendra <vigneshr@ti.com>
> Cc: imx@lists.linux.dev
> Cc: linux-mtd@lists.infradead.org
> Cc: linux-kernel@vger.kernel.org
> ---

Reviewed-by: Frank Li <Frank.Li@nxp.com>

>  drivers/mtd/nand/raw/gpmi-nand/gpmi-nand.c | 29 +++++++++++++++++++++++++++++
>  drivers/mtd/nand/raw/gpmi-nand/gpmi-nand.h |  6 ++++++
>  2 files changed, 35 insertions(+)
>
> diff --git a/drivers/mtd/nand/raw/gpmi-nand/gpmi-nand.c b/drivers/mtd/nand/raw/gpmi-nand/gpmi-nand.c
> index c1f766cb225aa..527165ccc839d 100644
> --- a/drivers/mtd/nand/raw/gpmi-nand/gpmi-nand.c
> +++ b/drivers/mtd/nand/raw/gpmi-nand/gpmi-nand.c
> @@ -7,6 +7,7 @@
>   */
>  #include <linux/cleanup.h>
>  #include <linux/clk.h>
> +#include <linux/debugfs.h>
bch_remove_debugfs>  #include <linux/delay.h>
>  #include <linux/slab.h>
>  #include <linux/sched/task_stack.h>
> @@ -732,6 +733,31 @@ static int common_nfc_set_geometry(struct gpmi_nand_data *this)
>  	return err;
>  }
>
> +#ifdef CONFIG_DEBUG_FS
> +static void bch_remove_debugfs(void *data)
> +{
> +	struct gpmi_nand_data *this = data;
> +
> +	debugfs_remove_recursive(this->dbg_root);
> +	this->dbg_root = NULL;
> +}
> +
> +static void bch_create_debugfs(struct gpmi_nand_data *this)
> +{
> +	struct bch_geometry *bch_geo = &this->bch_geometry;
> +
> +	this->dbg_root = debugfs_create_dir("gpmi-nand", NULL);
> +	this->dbg_bch_geo.data = (void *)bch_geo;
> +	this->dbg_bch_geo.size = sizeof(struct bch_geometry);
> +	this->raw_mode = true;
> +	debugfs_create_blob("bch_geometry", 0444, this->dbg_root, &this->dbg_bch_geo);
> +	debugfs_create_bool("raw_mode", 0444, this->dbg_root, &this->raw_mode);
> +	devm_add_action_or_reset(this->dev, bch_remove_debugfs, this);
> +}
> +#else
> +static void bch_create_debugfs(struct gpmi_nand_data *this) {}
> +#endif /* CONFIG_DEBUG_FS */
> +
>  /* Configures the geometry for BCH.  */
>  static int bch_set_geometry(struct gpmi_nand_data *this)
>  {
> @@ -2282,6 +2308,9 @@ static int gpmi_init_last(struct gpmi_nand_data *this)
>  	if (ret)
>  		return ret;
>
> +	/* save BCH geometry to debugfs if CONFIG_DEBUG_FS is enabled */
> +	bch_create_debugfs(this);
> +
>  	/* Init the nand_ecc_ctrl{} */
>  	ecc->read_page	= gpmi_ecc_read_page;
>  	ecc->write_page	= gpmi_ecc_write_page;
> diff --git a/drivers/mtd/nand/raw/gpmi-nand/gpmi-nand.h b/drivers/mtd/nand/raw/gpmi-nand/gpmi-nand.h
> index 3e9bc985e44a3..80c32efbaef86 100644
> --- a/drivers/mtd/nand/raw/gpmi-nand/gpmi-nand.h
> +++ b/drivers/mtd/nand/raw/gpmi-nand/gpmi-nand.h
> @@ -161,6 +161,12 @@ struct gpmi_nand_data {
>  #define DMA_CHANS		8
>  	struct dma_chan		*dma_chans[DMA_CHANS];
>  	struct completion	dma_done;
> +
> +#ifdef CONFIG_DEBUG_FS
> +	struct			dentry *dbg_root;
> +	struct			debugfs_blob_wrapper dbg_bch_geo;
> +	bool			raw_mode;
> +#endif
>  };
>
>  /* BCH : Status Block Completion Codes */
>
> ---
> base-commit: f97bdc8ec1dc7b33781a702eeba55326c206be56
> change-id: 20260727-nand_debugfs-74d6d6ba52df
>
> Best regards,
> --
> Han Xu <han.xu@nxp.com>
>
>

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

WARNING: multiple messages have this Message-ID (diff)
From: Frank Li <Frank.li@oss.nxp.com>
To: han.xu@oss.nxp.com
Cc: Miquel Raynal <miquel.raynal@bootlin.com>,
	Richard Weinberger <richard@nod.at>,
	Vignesh Raghavendra <vigneshr@ti.com>,
	imx@lists.linux.dev, linux-mtd@lists.infradead.org,
	linux-kernel@vger.kernel.org, Han Xu <han.xu@nxp.com>
Subject: Re: [PATCH v2] mtd: rawnand: gpmi: add debugfs entry for BCH geometry
Date: Wed, 29 Jul 2026 15:40:44 -0500	[thread overview]
Message-ID: <amplTATeFqpGx7qe@SMW015318> (raw)
In-Reply-To: <20260729-nand_debugfs-v2-1-2631e92adcb2@nxp.com>

On Wed, Jul 29, 2026 at 02:22:20PM -0500, han.xu@oss.nxp.com wrote:
> From: Han Xu <han.xu@nxp.com>
>
> 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:
>
> bch_geometry  - blob containing the struct bch_geometry fields
> raw_mode      - flag indicating raw mode status
>
> The implementation is guarded with #ifdef CONFIG_DEBUG_FS to avoid
> build failures when debugfs is disabled.
>
> Signed-off-by: Han Xu <han.xu@nxp.com>
> ---
> Changes in v2:
> - Move dbg_root and dbg_bch_geo into struct gpmi_nand_data to fix
>   use-after-free on device unbind.
> - Replace debugfs_create_file_full() with debugfs_create_bool() to
>   expose the raw_mode flag.
> - Register a devm cleanup action to call debugfs_remove_recursive() on
>   driver removal.
>
> To: Han Xu <han.xu@nxp.com>
> To: Miquel Raynal <miquel.raynal@bootlin.com>
> To: Richard Weinberger <richard@nod.at>
> To: Vignesh Raghavendra <vigneshr@ti.com>
> Cc: imx@lists.linux.dev
> Cc: linux-mtd@lists.infradead.org
> Cc: linux-kernel@vger.kernel.org
> ---

Reviewed-by: Frank Li <Frank.Li@nxp.com>

>  drivers/mtd/nand/raw/gpmi-nand/gpmi-nand.c | 29 +++++++++++++++++++++++++++++
>  drivers/mtd/nand/raw/gpmi-nand/gpmi-nand.h |  6 ++++++
>  2 files changed, 35 insertions(+)
>
> diff --git a/drivers/mtd/nand/raw/gpmi-nand/gpmi-nand.c b/drivers/mtd/nand/raw/gpmi-nand/gpmi-nand.c
> index c1f766cb225aa..527165ccc839d 100644
> --- a/drivers/mtd/nand/raw/gpmi-nand/gpmi-nand.c
> +++ b/drivers/mtd/nand/raw/gpmi-nand/gpmi-nand.c
> @@ -7,6 +7,7 @@
>   */
>  #include <linux/cleanup.h>
>  #include <linux/clk.h>
> +#include <linux/debugfs.h>
bch_remove_debugfs>  #include <linux/delay.h>
>  #include <linux/slab.h>
>  #include <linux/sched/task_stack.h>
> @@ -732,6 +733,31 @@ static int common_nfc_set_geometry(struct gpmi_nand_data *this)
>  	return err;
>  }
>
> +#ifdef CONFIG_DEBUG_FS
> +static void bch_remove_debugfs(void *data)
> +{
> +	struct gpmi_nand_data *this = data;
> +
> +	debugfs_remove_recursive(this->dbg_root);
> +	this->dbg_root = NULL;
> +}
> +
> +static void bch_create_debugfs(struct gpmi_nand_data *this)
> +{
> +	struct bch_geometry *bch_geo = &this->bch_geometry;
> +
> +	this->dbg_root = debugfs_create_dir("gpmi-nand", NULL);
> +	this->dbg_bch_geo.data = (void *)bch_geo;
> +	this->dbg_bch_geo.size = sizeof(struct bch_geometry);
> +	this->raw_mode = true;
> +	debugfs_create_blob("bch_geometry", 0444, this->dbg_root, &this->dbg_bch_geo);
> +	debugfs_create_bool("raw_mode", 0444, this->dbg_root, &this->raw_mode);
> +	devm_add_action_or_reset(this->dev, bch_remove_debugfs, this);
> +}
> +#else
> +static void bch_create_debugfs(struct gpmi_nand_data *this) {}
> +#endif /* CONFIG_DEBUG_FS */
> +
>  /* Configures the geometry for BCH.  */
>  static int bch_set_geometry(struct gpmi_nand_data *this)
>  {
> @@ -2282,6 +2308,9 @@ static int gpmi_init_last(struct gpmi_nand_data *this)
>  	if (ret)
>  		return ret;
>
> +	/* save BCH geometry to debugfs if CONFIG_DEBUG_FS is enabled */
> +	bch_create_debugfs(this);
> +
>  	/* Init the nand_ecc_ctrl{} */
>  	ecc->read_page	= gpmi_ecc_read_page;
>  	ecc->write_page	= gpmi_ecc_write_page;
> diff --git a/drivers/mtd/nand/raw/gpmi-nand/gpmi-nand.h b/drivers/mtd/nand/raw/gpmi-nand/gpmi-nand.h
> index 3e9bc985e44a3..80c32efbaef86 100644
> --- a/drivers/mtd/nand/raw/gpmi-nand/gpmi-nand.h
> +++ b/drivers/mtd/nand/raw/gpmi-nand/gpmi-nand.h
> @@ -161,6 +161,12 @@ struct gpmi_nand_data {
>  #define DMA_CHANS		8
>  	struct dma_chan		*dma_chans[DMA_CHANS];
>  	struct completion	dma_done;
> +
> +#ifdef CONFIG_DEBUG_FS
> +	struct			dentry *dbg_root;
> +	struct			debugfs_blob_wrapper dbg_bch_geo;
> +	bool			raw_mode;
> +#endif
>  };
>
>  /* BCH : Status Block Completion Codes */
>
> ---
> base-commit: f97bdc8ec1dc7b33781a702eeba55326c206be56
> change-id: 20260727-nand_debugfs-74d6d6ba52df
>
> Best regards,
> --
> Han Xu <han.xu@nxp.com>
>
>

  reply	other threads:[~2026-07-29 20:41 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-29 19:22 [PATCH v2] mtd: rawnand: gpmi: add debugfs entry for BCH geometry han.xu
2026-07-29 19:22 ` han.xu
2026-07-29 20:40 ` Frank Li [this message]
2026-07-29 20:40   ` Frank Li

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=amplTATeFqpGx7qe@SMW015318 \
    --to=frank.li@oss.nxp.com \
    --cc=han.xu@nxp.com \
    --cc=han.xu@oss.nxp.com \
    --cc=imx@lists.linux.dev \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mtd@lists.infradead.org \
    --cc=miquel.raynal@bootlin.com \
    --cc=richard@nod.at \
    --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.