From: Pengpeng Hou <pengpeng@iscas.ac.cn>
To: Miquel Raynal <miquel.raynal@bootlin.com>
Cc: Richard Weinberger <richard@nod.at>,
Vignesh Raghavendra <vigneshr@ti.com>,
Amit Kumar Mahapatra <amit.kumar-mahapatra@amd.com>,
Luca Ceresoli <luca.ceresoli@bootlin.com>,
linux-mtd@lists.infradead.org, linux-kernel@vger.kernel.org,
Pengpeng Hou <pengpeng@iscas.ac.cn>
Subject: [RFC] mtd: virt-concat: define duplicate partition handling
Date: Wed, 22 Jul 2026 12:19:25 +0800 [thread overview]
Message-ID: <20260722041925.31407-1-pengpeng@iscas.ac.cn> (raw)
mtd_device_parse_register() contains compatibility handling for drivers that
call it more than once, while its comment notes that partition parsing can
register the same partitions again.
When CONFIG_MTD_PARTITIONED_MASTER is disabled and the first call finds
partitions, the master itself is not registered before parsing. A later call
can therefore reach partition parsing again.
With CONFIG_MTD_VIRT_CONCAT, each newly allocated partition whose OF node
belongs to a virtual concatenation reaches mtd_virt_concat_add(). That
function appends the partition based only on the OF node and increments
num_subdev without checking whether the node was already added or whether
the fixed subdev[] array is full.
A repeated parse can therefore append the same node again. If all configured
slots were already populated, the append is out of bounds. If other members
are still missing, the duplicate can make num_subdev reach the configured
count with the wrong membership.
A local bounds check does not seem sufficient for a correct patch:
- concat_node_list and the concat population state are global, but node
creation, addition, join creation and destruction have no common
serialization.
- mtd_virt_concat_add() returns bool. false means both "not a concat
member" and "not added". Returning false for a duplicate makes
add_mtd_partitions() register it as an ordinary partition, while returning
true without storing it would leak the newly allocated partition.
- join creation and destruction call back into MTD registration helpers, so
a driver-global mutex must have a carefully defined scope to avoid
recursive locking.
My current view is that the fix needs both a serialization contract for the
global virtual-concat state and a tri-state add result, so the caller can
distinguish "not a member" from a duplicate or capacity error and free the
new partition on error.
Would you prefer this serialization to live inside mtd_virt_concat, or should
the MTD registration layer serialize the node-create/partition-add/join
transaction? I have not attached a patch because choosing either scope
without agreement would encode a new lifetime and error-handling contract.
next reply other threads:[~2026-07-22 4:19 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-22 4:19 Pengpeng Hou [this message]
2026-07-24 9:39 ` Miquel Raynal
2026-07-31 14:22 ` Pengpeng Hou
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=20260722041925.31407-1-pengpeng@iscas.ac.cn \
--to=pengpeng@iscas.ac.cn \
--cc=amit.kumar-mahapatra@amd.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mtd@lists.infradead.org \
--cc=luca.ceresoli@bootlin.com \
--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 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®