Re: [PATCH] mtd: fix double free and WARN_ON in add_mtd_device() error paths

From: Miquel Raynal

Date: Mon Jul 06 2026 - 03:57:53 EST


On Wed, 01 Jul 2026 20:10:42 +0800, Xue Lei wrote:
> When device_register() or mtd_nvmem_add() fails inside
> add_mtd_device() for a partition, the error handling triggers
> mtd_release() via put_device() or device_unregister(). mtd_release()
> calls release_mtd_partition() which frees the mtd_info structure.
> However, callers such as mtd_add_partition() and add_mtd_partitions()
> also call free_partition() in their error paths, resulting in a double
> free.
>
> [...]

Applied to mtd/fixes, thanks!

[1/1] mtd: fix double free and WARN_ON in add_mtd_device() error paths
commit: 9d4af746af8ce27eefc2338b2feaa1e01f28b6c3

Patche(s) should be available on mtd/linux.git and will be
part of the next PR (provided that no robot complains by then).

Kind regards,
Miquèl