[PATCH 1/2] fs: export cdev_get_linux_rootarg() for reuse

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



We've the root=PARTUUID=%s generation at two places: Once to populate
fsdev->linux_rootarg and once to handle struct bootm_data::root_dev.

In preparation for dropping the duplicate out-of-sync code in the bootm
code, export the originl fs/fs.c code as cdev_get_linux_rootarg().

Signed-off-by: Ahmad Fatoum <a.fatoum@xxxxxxxxxxxxxx>
---
 fs/fs.c      | 50 +++++++++++++++++++++++++++++++++++---------------
 include/fs.h |  1 +
 2 files changed, 36 insertions(+), 15 deletions(-)

diff --git a/fs/fs.c b/fs/fs.c
index bd6f144742ac..620cd6597a63 100644
--- a/fs/fs.c
+++ b/fs/fs.c
@@ -2876,12 +2876,23 @@ int popd(char *oldcwd)
 	return ret;
 }
 
-static char *get_linux_mmcblkdev(struct fs_device_d *fsdev)
+static bool cdev_partname_equal(const struct cdev *a,
+				const struct cdev *b)
 {
-	struct cdev *cdevm, *cdev;
+	return a->partname && b->partname &&
+		!strcmp(a->partname, b->partname);
+}
+
+static char *get_linux_mmcblkdev(const struct cdev *root_cdev)
+{
+	struct cdev *cdevm = root_cdev->master, *cdev;
 	int id, partnum;
 
-	cdevm = fsdev->cdev->master;
+	if (!IS_ENABLED(CONFIG_MMCBLKDEV_ROOTARG))
+		return NULL;
+	if (!cdevm || !cdev_is_mci_main_part_dev(cdevm))
+		return NULL;
+
 	id = of_alias_get_id(cdevm->device_node, "mmc");
 	if (id < 0)
 		return NULL;
@@ -2894,8 +2905,7 @@ static char *get_linux_mmcblkdev(struct fs_device_d *fsdev)
 		 * in the partitions list so we need to count it instead of
 		 * skipping it.
 		 */
-		if (cdev->partname &&
-		    !strcmp(cdev->partname, fsdev->cdev->partname))
+		if (cdev_partname_equal(root_cdev, cdev))
 			return basprintf("root=/dev/mmcblk%dp%d", id, partnum);
 		partnum++;
 	}
@@ -2903,6 +2913,23 @@ static char *get_linux_mmcblkdev(struct fs_device_d *fsdev)
 	return NULL;
 }
 
+char *cdev_get_linux_rootarg(const struct cdev *cdev)
+{
+	char *str;
+
+	if (!cdev)
+		return NULL;
+
+	str = get_linux_mmcblkdev(cdev);
+	if (str)
+		return str;
+
+	if (cdev->uuid[0] != 0)
+		return basprintf("root=PARTUUID=%s", cdev->uuid);
+
+	return NULL;
+}
+
 /*
  * Mount a device to a directory.
  * We do this by registering a new device on which the filesystem
@@ -2991,17 +3018,10 @@ int mount(const char *device, const char *fsname, const char *pathname,
 
 	fsdev->vfsmount.mnt_root = fsdev->sb.s_root;
 
-	if (!fsdev->linux_rootarg && fsdev->cdev) {
-		char *str = NULL;
-
-		if (IS_ENABLED(CONFIG_MMCBLKDEV_ROOTARG) &&
-		    fsdev->cdev->master &&
-		    cdev_is_mci_main_part_dev(fsdev->cdev->master))
-			str = get_linux_mmcblkdev(fsdev);
-
-		if (!str && fsdev->cdev->uuid[0] != 0)
-			str = basprintf("root=PARTUUID=%s", fsdev->cdev->uuid);
+	if (!fsdev->linux_rootarg) {
+		char *str;
 
+		str = cdev_get_linux_rootarg(fsdev->cdev);
 		if (str)
 			fsdev_set_linux_rootarg(fsdev, str);
 	}
diff --git a/include/fs.h b/include/fs.h
index cd5eb571e08e..894cae3e4c2f 100644
--- a/include/fs.h
+++ b/include/fs.h
@@ -168,6 +168,7 @@ void mount_all(void);
 
 void fsdev_set_linux_rootarg(struct fs_device_d *fsdev, const char *str);
 char *path_get_linux_rootarg(const char *path);
+char *cdev_get_linux_rootarg(const struct cdev *cdev);
 
 static inline const char *devpath_to_name(const char *devpath)
 {
-- 
2.30.2





[Index of Archives]     [Linux Embedded]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux