[PATCH 5/6] cdev: export and use cdevfs_del_partition

Ahmad Fatoum a.fatoum at pengutronix.de
Wed Jan 3 02:16:28 PST 2024


Like what's the case with cdevfs_add_partition, a couple of users
already have a cdev, so it's wasteful to get its name and do a lookup
only to arrive at the same cdev. Export a cdevfs_del_partition that
directly works on the cdev and start using it instead.

Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
 drivers/base/driver.c |  2 +-
 fs/devfs-core.c       | 23 +++++++++++++++--------
 include/driver.h      |  1 +
 lib/bootstrap/devfs.c |  2 +-
 4 files changed, 18 insertions(+), 10 deletions(-)

diff --git a/drivers/base/driver.c b/drivers/base/driver.c
index 93607fc3b09d..4f18f5bb8123 100644
--- a/drivers/base/driver.c
+++ b/drivers/base/driver.c
@@ -295,7 +295,7 @@ int unregister_device(struct device *old_dev)
 	list_for_each_entry_safe(cdev, ct, &old_dev->cdevs, devices_list) {
 		if (cdev_is_partition(cdev)) {
 			dev_dbg(old_dev, "unregister part %s\n", cdev->name);
-			devfs_del_partition(cdev->name);
+			cdevfs_del_partition(cdev);
 		}
 	}
 
diff --git a/fs/devfs-core.c b/fs/devfs-core.c
index 912bfeede8dc..fef66e08e293 100644
--- a/fs/devfs-core.c
+++ b/fs/devfs-core.c
@@ -575,17 +575,10 @@ struct cdev *devfs_add_partition(const char *devname, loff_t offset,
 	return cdevfs_add_partition(cdev, &partinfo, NULL);
 }
 
-int devfs_del_partition(const char *name)
+int cdevfs_del_partition(struct cdev *cdev)
 {
-	struct cdev *cdev;
 	int ret;
 
-	cdev = cdev_by_name(name);
-	if (!cdev)
-		return -ENOENT;
-
-	if (!cdev_is_partition(cdev))
-		return -EINVAL;
 	if (cdev->flags & DEVFS_PARTITION_FIXED)
 		return -EPERM;
 
@@ -605,6 +598,20 @@ int devfs_del_partition(const char *name)
 	return 0;
 }
 
+int devfs_del_partition(const char *name)
+{
+	struct cdev *cdev;
+
+	cdev = cdev_by_name(name);
+	if (!cdev)
+		return -ENOENT;
+
+	if (!cdev_is_partition(cdev))
+		return -EINVAL;
+
+	return cdevfs_del_partition(cdev);
+}
+
 int devfs_create_partitions(const char *devname,
 		const struct devfs_partition partinfo[])
 {
diff --git a/include/driver.h b/include/driver.h
index 373c4f1d0bca..f4f26151e365 100644
--- a/include/driver.h
+++ b/include/driver.h
@@ -683,6 +683,7 @@ int devfs_del_partition(const char *name);
 
 struct cdev *cdevfs_add_partition(struct cdev *cdev,
 		const struct devfs_partition *partinfo, loff_t *end);
+int cdevfs_del_partition(struct cdev *cdev);
 
 #define of_match_ptr(compat) \
 	IS_ENABLED(CONFIG_OFDEVICE) ? (compat) : NULL
diff --git a/lib/bootstrap/devfs.c b/lib/bootstrap/devfs.c
index b127b27c1d58..b023da1f941e 100644
--- a/lib/bootstrap/devfs.c
+++ b/lib/bootstrap/devfs.c
@@ -150,7 +150,7 @@ void* bootstrap_read_devfs(char *devname, bool use_bb, int offset,
 	}
 
 delete_devfs_partition:
-	devfs_del_partition(partname);
+	cdevfs_del_partition(partition);
 
 	return result;
 }
-- 
2.39.2




More information about the barebox mailing list