[PATCH] efi_loader: simplify efi_disk_remove
Ilias Apalodimas
ilias.apalodimas at linaro.org
Mon Jun 12 12:07:44 CEST 2023
Instead of discovering the ID of the device and call two different
functions for a block device or a partition, we can rewrite
efi_disk_remove() and handle the minor differences between the two
variants internally. As a results we can simplify efi_disk_remove()
a lot and get rid of the extra efi_disk_delete_raw/blk calls.
bloat-o-meter seems the size reduction as well
add/remove: 0/0 grow/shrink: 0/1 up/down: 0/-84 (-84)
Function old new delta
efi_disk_remove 160 76 -84
Total: Before=784824, After=784740, chg -0.01%
Signed-off-by: Ilias Apalodimas <ilias.apalodimas at linaro.org>
---
lib/efi_loader/efi_disk.c | 82 +++++++++++----------------------------
1 file changed, 22 insertions(+), 60 deletions(-)
diff --git a/lib/efi_loader/efi_disk.c b/lib/efi_loader/efi_disk.c
index d2256713a8e7..8ab476b02445 100644
--- a/lib/efi_loader/efi_disk.c
+++ b/lib/efi_loader/efi_disk.c
@@ -691,90 +691,52 @@ int efi_disk_probe(void *ctx, struct event *event)
}
/*
- * Delete an efi_disk object for a whole raw disk
+ * Delete an efi_disk object for a block device
*
- * @dev uclass device (UCLASS_BLK)
+ * @dev uclass device (UCLASS_BLK or UCLASS_PARTITION)
*
* Delete an efi_disk object which is associated with @dev.
- * The type of @dev must be UCLASS_BLK.
+ * The type of @dev must be either UCLASS_BLK or UCLASS_PARTITION.
+ * This function is expected to be called at EV_PM_PRE_REMOVE.
*
* @return 0 on success, -1 otherwise
*/
-static int efi_disk_delete_raw(struct udevice *dev)
+int efi_disk_remove(void *ctx, struct event *event)
{
+ enum uclass_id id;
+ struct udevice *dev;
efi_handle_t handle;
struct blk_desc *desc;
- struct efi_disk_obj *diskobj;
+ struct efi_disk_obj *diskobj = NULL;
+
+ dev = event->data.dm.dev;
if (dev_tag_get_ptr(dev, DM_TAG_EFI, (void **)&handle))
return -1;
desc = dev_get_uclass_plat(dev);
- if (desc->uclass_id != UCLASS_EFI_LOADER) {
+ if (desc && desc->uclass_id == UCLASS_EFI_LOADER)
+ goto out;
+
+ id = device_get_uclass_id(dev);
+ switch (id) {
+ case UCLASS_BLK:
+ case UCLASS_PARTITION:
diskobj = container_of(handle, struct efi_disk_obj, header);
- efi_free_pool(diskobj->dp);
+ default:
+ return 0;
}
- efi_delete_handle(handle);
- dev_tag_del(dev, DM_TAG_EFI);
-
- return 0;
-}
-
-/*
- * Delete an efi_disk object for a disk partition
- *
- * @dev uclass device (UCLASS_PARTITION)
- *
- * Delete an efi_disk object which is associated with @dev.
- * The type of @dev must be UCLASS_PARTITION.
- *
- * @return 0 on success, -1 otherwise
- */
-static int efi_disk_delete_part(struct udevice *dev)
-{
- efi_handle_t handle;
- struct efi_disk_obj *diskobj;
-
- if (dev_tag_get_ptr(dev, DM_TAG_EFI, (void **)&handle))
- return -1;
-
- diskobj = container_of(handle, struct efi_disk_obj, header);
+ if (diskobj)
+ efi_free_pool(diskobj->dp);
- efi_free_pool(diskobj->dp);
+out:
efi_delete_handle(handle);
dev_tag_del(dev, DM_TAG_EFI);
return 0;
}
-/*
- * Delete an efi_disk object for a block device
- *
- * @dev uclass device (UCLASS_BLK or UCLASS_PARTITION)
- *
- * Delete an efi_disk object which is associated with @dev.
- * The type of @dev must be either UCLASS_BLK or UCLASS_PARTITION.
- * This function is expected to be called at EV_PM_PRE_REMOVE.
- *
- * @return 0 on success, -1 otherwise
- */
-int efi_disk_remove(void *ctx, struct event *event)
-{
- enum uclass_id id;
- struct udevice *dev;
-
- dev = event->data.dm.dev;
- id = device_get_uclass_id(dev);
-
- if (id == UCLASS_BLK)
- return efi_disk_delete_raw(dev);
- else if (id == UCLASS_PARTITION)
- return efi_disk_delete_part(dev);
- else
- return 0;
-}
-
/**
* efi_disk_get_device_name() - get U-Boot device name associated with EFI handle
*
--
2.39.2
More information about the U-Boot
mailing list