Skip to content

Commit 46b5889

Browse files
committed
mtd: implement proper partition handling
Instead of collecting partitions in a flat list, create a hierarchy within the mtd_info structure: use a partitions list to keep track of the partitions of an MTD device (which might be itself a partition of another MTD device), a pointer to the parent device (NULL when the MTD device is the root one, not a partition). By also saving directly in mtd_info the offset of the partition, we can get rid of the mtd_part structure. While at it, be consistent in the naming of the mtd_info structures to ease the understanding of the new hierarchy: these structures are usually called 'mtd', unless there are multiple instances of the same structure. In this case, there is usually a parent/child bound so we will call them 'parent' and 'child'. Signed-off-by: Miquel Raynal <[email protected]> Link: https://lore.kernel.org/linux-mtd/[email protected]
1 parent 98d54f8 commit 46b5889

File tree

5 files changed

+478
-605
lines changed

5 files changed

+478
-605
lines changed

drivers/mtd/mtdchar.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,7 @@ static int mtdchar_writeoob(struct file *file, struct mtd_info *mtd,
349349
uint64_t start, uint32_t length, void __user *ptr,
350350
uint32_t __user *retp)
351351
{
352+
struct mtd_info *master = mtd_get_master(mtd);
352353
struct mtd_file_info *mfi = file->private_data;
353354
struct mtd_oob_ops ops = {};
354355
uint32_t retlen;
@@ -360,7 +361,7 @@ static int mtdchar_writeoob(struct file *file, struct mtd_info *mtd,
360361
if (length > 4096)
361362
return -EINVAL;
362363

363-
if (!mtd->_write_oob)
364+
if (!master->_write_oob)
364365
return -EOPNOTSUPP;
365366

366367
ops.ooblen = length;
@@ -586,6 +587,7 @@ static int mtdchar_blkpg_ioctl(struct mtd_info *mtd,
586587
static int mtdchar_write_ioctl(struct mtd_info *mtd,
587588
struct mtd_write_req __user *argp)
588589
{
590+
struct mtd_info *master = mtd_get_master(mtd);
589591
struct mtd_write_req req;
590592
struct mtd_oob_ops ops = {};
591593
const void __user *usr_data, *usr_oob;
@@ -597,9 +599,8 @@ static int mtdchar_write_ioctl(struct mtd_info *mtd,
597599
usr_data = (const void __user *)(uintptr_t)req.usr_data;
598600
usr_oob = (const void __user *)(uintptr_t)req.usr_oob;
599601

600-
if (!mtd->_write_oob)
602+
if (!master->_write_oob)
601603
return -EOPNOTSUPP;
602-
603604
ops.mode = req.mode;
604605
ops.len = (size_t)req.len;
605606
ops.ooblen = (size_t)req.ooblen;
@@ -635,6 +636,7 @@ static int mtdchar_ioctl(struct file *file, u_int cmd, u_long arg)
635636
{
636637
struct mtd_file_info *mfi = file->private_data;
637638
struct mtd_info *mtd = mfi->mtd;
639+
struct mtd_info *master = mtd_get_master(mtd);
638640
void __user *argp = (void __user *)arg;
639641
int ret = 0;
640642
struct mtd_info_user info;
@@ -824,7 +826,7 @@ static int mtdchar_ioctl(struct file *file, u_int cmd, u_long arg)
824826
{
825827
struct nand_oobinfo oi;
826828

827-
if (!mtd->ooblayout)
829+
if (!master->ooblayout)
828830
return -EOPNOTSUPP;
829831

830832
ret = get_oobinfo(mtd, &oi);
@@ -918,7 +920,7 @@ static int mtdchar_ioctl(struct file *file, u_int cmd, u_long arg)
918920
{
919921
struct nand_ecclayout_user *usrlay;
920922

921-
if (!mtd->ooblayout)
923+
if (!master->ooblayout)
922924
return -EOPNOTSUPP;
923925

924926
usrlay = kmalloc(sizeof(*usrlay), GFP_KERNEL);

0 commit comments

Comments
 (0)