mirror of
https://github.com/torvalds/linux.git
synced 2026-04-18 06:44:00 -04:00
mtd: use refcount to prevent corruption
When underlying device is removed mtd core will crash in case user space is holding open handle. Need to use proper refcounting so device is release only when has no users. Signed-off-by: Tomas Winkler <tomas.winkler@intel.com> Signed-off-by: Alexander Usyskin <alexander.usyskin@intel.com> Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com> Link: https://lore.kernel.org/linux-mtd/20230620131905.648089-2-alexander.usyskin@intel.com
This commit is contained in:
committed by
Miquel Raynal
parent
06c2afb862
commit
19bfa9ebeb
@@ -32,6 +32,12 @@ static inline void free_partition(struct mtd_info *mtd)
|
||||
kfree(mtd);
|
||||
}
|
||||
|
||||
void release_mtd_partition(struct mtd_info *mtd)
|
||||
{
|
||||
WARN_ON(!list_empty(&mtd->part.node));
|
||||
free_partition(mtd);
|
||||
}
|
||||
|
||||
static struct mtd_info *allocate_partition(struct mtd_info *parent,
|
||||
const struct mtd_partition *part,
|
||||
int partno, uint64_t cur_offset)
|
||||
@@ -309,13 +315,11 @@ static int __mtd_del_partition(struct mtd_info *mtd)
|
||||
|
||||
sysfs_remove_files(&mtd->dev.kobj, mtd_partition_attrs);
|
||||
|
||||
list_del_init(&mtd->part.node);
|
||||
err = del_mtd_device(mtd);
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
list_del(&mtd->part.node);
|
||||
free_partition(mtd);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -333,6 +337,7 @@ static int __del_mtd_partitions(struct mtd_info *mtd)
|
||||
__del_mtd_partitions(child);
|
||||
|
||||
pr_info("Deleting %s MTD partition\n", child->name);
|
||||
list_del_init(&child->part.node);
|
||||
ret = del_mtd_device(child);
|
||||
if (ret < 0) {
|
||||
pr_err("Error when deleting partition \"%s\" (%d)\n",
|
||||
@@ -340,9 +345,6 @@ static int __del_mtd_partitions(struct mtd_info *mtd)
|
||||
err = ret;
|
||||
continue;
|
||||
}
|
||||
|
||||
list_del(&child->part.node);
|
||||
free_partition(child);
|
||||
}
|
||||
|
||||
return err;
|
||||
|
||||
Reference in New Issue
Block a user