Linux-mtd Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "James Hilliard" <james.hilliard1@gmail.com>,
	"Miquel Raynal" <miquel.raynal@bootlin.com>,
	"Richard Weinberger" <richard@nod.at>,
	"Vignesh Raghavendra" <vigneshr@ti.com>
Cc: linux-mtd@lists.infradead.org,
	"Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
	"Srinivas Kandagatla" <srini@kernel.org>,
	"Tze Yee Ng" <tze.yee.ng@altera.com>
Subject: Re: [PATCH v5 03/58] mtd: separate class devices from retained backing objects
Date: Mon, 16 Nov 2026 07:21:31 +0000	[thread overview]
Message-ID: <sashiko-outbox-216405@kernel.org> (raw)
In-Reply-To: <20261115-submit-rawnand-retained-handle-lifetime-v1-v5-3-cbc49c5c5e74@gmail.com>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] mtd: mtdpart: get_mtd_device() in add_mtd_partitions() breaks
  busy gluebi
--

commit ecf5ff75f8570e8ffd0f1f3b353ff398fca67be7
Author: James Hilliard <james.hilliard1@gmail.com>

mtd: separate class devices from retained backing objects

This commit separates the MTD class device allocation from struct
mtd_info and adds reference counting for backing objects and partition
lifetimes across unregistration.

> diff --git a/drivers/mtd/mtdpart.c b/drivers/mtd/mtdpart.c
> index c316cfe92c7e4..8be604f7c140e 100644
> --- a/drivers/mtd/mtdpart.c
> +++ b/drivers/mtd/mtdpart.c
[ ... ]
> @@ -419,35 +420,52 @@ int add_mtd_partitions(struct mtd_info *parent,
>  	       nbparts, parent->name);
>  
>  	for (i = 0; i < nbparts; i++) {
> +		mutex_lock(&master->master.partitions_lock);
> +		if (master->master.unregistering ||
> +		    (mtd_is_partition(parent) && !parent->registered)) {
> +			mutex_unlock(&master->master.partitions_lock);
> +			return -ENODEV;
> +		}
> +
>  		child = allocate_partition(parent, parts + i, i, cur_offset);
>  		if (IS_ERR(child)) {
>  			ret = PTR_ERR(child);
> -			goto err_del_partitions;
> +			goto err_unlock;
>  		}
>  
>  		if (IS_REACHABLE(CONFIG_MTD_VIRT_CONCAT)) {
> -			if (mtd_virt_concat_add(child))
> +			if (mtd_virt_concat_add(child)) {
> +				mutex_unlock(&master->master.partitions_lock);
>  				continue;
> +			}
>  		}
>  
> -		mutex_lock(&master->master.partitions_lock);
>  		list_add_tail(&child->part.node, &parent->partitions);
> -		mutex_unlock(&master->master.partitions_lock);
>  
>  		ret = add_mtd_device(child);
>  		if (ret) {
> -			mutex_lock(&master->master.partitions_lock);
>  			list_del(&child->part.node);
> -			mutex_unlock(&master->master.partitions_lock);
> -
>  			free_partition(child);
> -			goto err_del_partitions;
> +			goto err_unlock;
>  		}
>  
>  		mtd_add_partition_attrs(child);
> +		cur_offset = child->part.offset + child->part.size;
> +
> +		/* Parsing drops the partition lock and may race with deletion. */
> +		ret = PTR_ERR_OR_ZERO(get_mtd_device(child, -1));
> +		if (ret)
> +			goto err_unlock;

[Severity: Medium]
Does calling get_mtd_device(child, -1) during partition registration break
partitioned gluebi devices when the underlying UBI volume is already open
for writing?

get_mtd_device() calls __get_mtd_device(), which now invokes
master->_get_device(master).  For a writable gluebi device,
gluebi_get_device() opens the volume with UBI_READWRITE:

drivers/mtd/ubi/gluebi.c:gluebi_get_device() {
    ...
	if (mtd->flags & MTD_WRITEABLE)
		ubi_mode = UBI_READWRITE;
    ...
	gluebi->desc = ubi_open_volume(gluebi->ubi_num, gluebi->vol_id,
				       ubi_mode);
	if (IS_ERR(gluebi->desc)) {
		mutex_unlock(&devices_mutex);
		return PTR_ERR(gluebi->desc);
	}
}

Previously, gluebi_get_device() only ran when the MTD device was actually
opened.  When gluebi is loaded while a UBI volume already has an active
writer or exclusive opener (such as a mounted read-write UBIFS
filesystem), ubi_open_volume() returns -EBUSY from inside the UBI volume
notifier, causing add_mtd_partitions() to roll back all partitions and
fail gluebi_create().

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261115-submit-rawnand-retained-handle-lifetime-v1-v5-0-cbc49c5c5e74@gmail.com?part=3

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

  reply	other threads:[~2026-11-16  7:21 UTC|newest]

Thread overview: 63+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-16  6:29 [PATCH v5 00/58] mtd: rawnand: retain chip and controller state across removal James Hilliard
2026-11-16  6:29 ` [PATCH v5 01/58] nvmem: disconnect provider callbacks before unregister returns James Hilliard
2026-11-16  6:29 ` [PATCH v5 02/58] mtd: acquire an MTD handle from a referenced class device James Hilliard
2026-11-16  6:59   ` sashiko-bot
2026-11-16  6:29 ` [PATCH v5 03/58] mtd: separate class devices from retained backing objects James Hilliard
2026-11-16  7:21   ` sashiko-bot [this message]
2026-11-16  6:29 ` [PATCH v5 04/58] mtd: retain virtual concatenations across component removal James Hilliard
2026-11-16  6:29 ` [PATCH v5 05/58] mtd: rawnand: separate hardware disconnection from cleanup James Hilliard
2026-11-16  6:29 ` [PATCH v5 06/58] mtd: rawnand: share retained chip and controller ownership James Hilliard
2026-11-16  6:29 ` [PATCH v5 07/58] mtd: rawnand: sunxi: retain chip state until the final MTD put James Hilliard
2026-11-16  6:29 ` [PATCH v5 08/58] mtd: rawnand: plat_nand: retain open-handle state on removal James Hilliard
2026-11-16  6:29 ` [PATCH v5 09/58] mtd: rawnand: gpio: " James Hilliard
2026-11-16  6:29 ` [PATCH v5 10/58] mtd: rawnand: stm32_fmc2: " James Hilliard
2026-11-16  6:29 ` [PATCH v5 11/58] mtd: rawnand: denali: retain chips across controller removal James Hilliard
2026-11-16  6:29 ` [PATCH v5 12/58] mtd: rawnand: arasan: " James Hilliard
2026-11-16  6:29 ` [PATCH v5 13/58] mtd: rawnand: mxic: retain open-handle state on removal James Hilliard
2026-11-16  6:29 ` [PATCH v5 14/58] mtd: rawnand: intel: " James Hilliard
2026-11-16  6:29 ` [PATCH v5 15/58] mtd: rawnand: tegra: " James Hilliard
2026-11-16  6:29 ` [PATCH v5 16/58] mtd: rawnand: mtk: retain chips across controller removal James Hilliard
2026-11-16  6:29 ` [PATCH v5 17/58] mtd: rawnand: rockchip: " James Hilliard
2026-11-16  6:29 ` [PATCH v5 18/58] mtd: rawnand: atmel: " James Hilliard
2026-11-16  6:29 ` [PATCH v5 19/58] mtd: rawnand: orion: retain open-handle state on removal James Hilliard
2026-11-16  6:29 ` [PATCH v5 20/58] mtd: rawnand: socrates: " James Hilliard
2026-11-16  6:29 ` [PATCH v5 21/58] mtd: rawnand: fsl_upm: " James Hilliard
2026-11-16  6:29 ` [PATCH v5 22/58] mtd: rawnand: pasemi: " James Hilliard
2026-11-16  6:47   ` sashiko-bot
2026-11-16  6:29 ` [PATCH v5 23/58] mtd: rawnand: ams-delta: " James Hilliard
2026-11-16  6:29 ` [PATCH v5 24/58] mtd: rawnand: xway: " James Hilliard
2026-11-16  6:47   ` sashiko-bot
2026-11-16  6:29 ` [PATCH v5 25/58] mtd: rawnand: hisi504: " James Hilliard
2026-11-16  6:29 ` [PATCH v5 26/58] mtd: rawnand: vf610: " James Hilliard
2026-11-16  6:29 ` [PATCH v5 27/58] mtd: rawnand: technologic: " James Hilliard
2026-11-16  6:29 ` [PATCH v5 28/58] mtd: rawnand: loongson: " James Hilliard
2026-11-16  6:29 ` [PATCH v5 29/58] mtd: rawnand: ma35d1: " James Hilliard
2026-11-16  6:29 ` [PATCH v5 30/58] mtd: rawnand: pl35x: " James Hilliard
2026-11-16  6:29 ` [PATCH v5 31/58] mtd: rawnand: mxc: " James Hilliard
2026-11-16  6:29 ` [PATCH v5 32/58] mtd: rawnand: fsmc: " James Hilliard
2026-11-16  6:29 ` [PATCH v5 33/58] mtd: rawnand: gpmi: " James Hilliard
2026-11-16  6:29 ` [PATCH v5 34/58] mtd: rawnand: omap2: " James Hilliard
2026-11-16  6:29 ` [PATCH v5 35/58] mtd: rawnand: marvell: " James Hilliard
2026-11-16  6:29 ` [PATCH v5 36/58] mtd: rawnand: renesas: " James Hilliard
2026-11-16  6:29 ` [PATCH v5 37/58] mtd: rawnand: meson: " James Hilliard
2026-11-16  6:29 ` [PATCH v5 38/58] mtd: rawnand: cadence: " James Hilliard
2026-11-16  6:29 ` [PATCH v5 39/58] mtd: rawnand: qcom: " James Hilliard
2026-11-16  6:29 ` [PATCH v5 40/58] mtd: rawnand: cafe: " James Hilliard
2026-11-16  6:29 ` [PATCH v5 41/58] mtd: rawnand: brcmnand: " James Hilliard
2026-11-16  6:29 ` [PATCH v5 42/58] mtd: rawnand: au1550nd: retain chip state across removal James Hilliard
2026-11-16  6:29 ` [PATCH v5 43/58] mtd: rawnand: sharpsl: " James Hilliard
2026-11-16  6:29 ` [PATCH v5 44/58] mtd: rawnand: davinci: " James Hilliard
2026-11-16  6:30 ` [PATCH v5 45/58] mtd: rawnand: sh_flctl: " James Hilliard
2026-11-16  6:30 ` [PATCH v5 46/58] mtd: rawnand: lpc32xx_slc: " James Hilliard
2026-11-16  6:30 ` [PATCH v5 47/58] mtd: rawnand: lpc32xx_mlc: " James Hilliard
2026-11-16  6:30 ` [PATCH v5 48/58] mtd: rawnand: ndfc: " James Hilliard
2026-11-16  6:30 ` [PATCH v5 49/58] mtd: rawnand: txx9ndfmc: " James Hilliard
2026-11-16  6:30 ` [PATCH v5 50/58] mtd: rawnand: ingenic: " James Hilliard
2026-11-16  6:30 ` [PATCH v5 51/58] mtd: rawnand: mpc5121: " James Hilliard
2026-11-16  6:30 ` [PATCH v5 52/58] mtd: rawnand: bcm47xxnflash: " James Hilliard
2026-11-16  6:30 ` [PATCH v5 53/58] mtd: rawnand: fsl_elbc: " James Hilliard
2026-11-16  6:30 ` [PATCH v5 54/58] mtd: rawnand: fsl_ifc: " James Hilliard
2026-11-16  6:30 ` [PATCH v5 55/58] mtd: rawnand: r852: " James Hilliard
2026-11-16  6:30 ` [PATCH v5 56/58] mtd: rawnand: nandsim: " James Hilliard
2026-11-16  6:30 ` [PATCH v5 57/58] mtd: rawnand: cs553x: " James Hilliard
2026-11-16  6:30 ` [PATCH v5 58/58] mtd: rawnand: diskonchip: " James Hilliard

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-216405@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=james.hilliard1@gmail.com \
    --cc=linux-mtd@lists.infradead.org \
    --cc=miquel.raynal@bootlin.com \
    --cc=richard@nod.at \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=srini@kernel.org \
    --cc=tze.yee.ng@altera.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