Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

init: handle ubi/mtd root mounting like all other root types

Assign a Root_Generic magic value for UBI/MTD root and handle the root
mounting in mount_root like all other root types. Besides making the
code more clear this also means that UBI/MTD root can be used together
with an initrd (not that anyone should care).

Also factor parsing of the root name into a helper now that it can
be easily done and will get more complicated with subsequent patches.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Link: https://lore.kernel.org/r/20230531125535.676098-11-hch@lst.de
Signed-off-by: Jens Axboe <axboe@kernel.dk>

authored by

Christoph Hellwig and committed by
Jens Axboe
07d63cbb 73231b58

+15 -9
+1
include/linux/root_dev.h
··· 9 9 enum { 10 10 Root_NFS = MKDEV(UNNAMED_MAJOR, 255), 11 11 Root_CIFS = MKDEV(UNNAMED_MAJOR, 254), 12 + Root_Generic = MKDEV(UNNAMED_MAJOR, 253), 12 13 Root_RAM0 = MKDEV(RAMDISK_MAJOR, 0), 13 14 }; 14 15
+14 -9
init/do_mounts.c
··· 591 591 case Root_CIFS: 592 592 mount_cifs_root(); 593 593 break; 594 + case Root_Generic: 595 + mount_root_generic(root_device_name, root_device_name, 596 + root_mountflags); 597 + break; 594 598 case 0: 595 599 if (root_device_name && root_fs_names && 596 600 mount_nodev_root(root_device_name) == 0) ··· 604 600 mount_block_root(root_device_name); 605 601 break; 606 602 } 603 + } 604 + 605 + static dev_t __init parse_root_device(char *root_device_name) 606 + { 607 + if (!strncmp(root_device_name, "mtd", 3) || 608 + !strncmp(root_device_name, "ubi", 3)) 609 + return Root_Generic; 610 + return name_to_dev_t(root_device_name); 607 611 } 608 612 609 613 /* ··· 636 624 637 625 md_run_setup(); 638 626 639 - if (saved_root_name[0]) { 640 - if (!strncmp(saved_root_name, "mtd", 3) || 641 - !strncmp(saved_root_name, "ubi", 3)) { 642 - mount_root_generic(saved_root_name, saved_root_name, 643 - root_mountflags); 644 - goto out; 645 - } 646 - ROOT_DEV = name_to_dev_t(saved_root_name); 647 - } 627 + if (saved_root_name[0]) 628 + ROOT_DEV = parse_root_device(saved_root_name); 648 629 649 630 if (initrd_load(saved_root_name)) 650 631 goto out;