diff options
author | Ilias Apalodimas <ilias.apalodimas@linaro.org> | 2023-06-12 18:35:58 +0300 |
---|---|---|
committer | Heinrich Schuchardt <heinrich.schuchardt@canonical.com> | 2023-06-16 06:45:20 +0200 |
commit | 3cc2b9f5b982ff3a192202b6d422eeb1893fa667 (patch) | |
tree | cf5159be489e7ac95a8b688cfd1690844401a8b4 | |
parent | 3ae95fe21cbd1e367e6169968ed2497a2ea8561a (diff) | |
download | u-boot-3cc2b9f5b982ff3a192202b6d422eeb1893fa667.zip u-boot-3cc2b9f5b982ff3a192202b6d422eeb1893fa667.tar.gz u-boot-3cc2b9f5b982ff3a192202b6d422eeb1893fa667.tar.bz2 |
efi_loader: simplify efi_disk_remove
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.
Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
If a handle is not found, return 0 to let the device be removed.
Reviewed-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
-rw-r--r-- | lib/efi_loader/efi_disk.c | 91 |
1 files changed, 26 insertions, 65 deletions
diff --git a/lib/efi_loader/efi_disk.c b/lib/efi_loader/efi_disk.c index d225671..28c8cdf 100644 --- a/lib/efi_loader/efi_disk.c +++ b/lib/efi_loader/efi_disk.c @@ -690,91 +690,52 @@ int efi_disk_probe(void *ctx, struct event *event) return 0; } -/* - * Delete an efi_disk object for a whole raw disk +/** + * efi_disk_remove - delete an efi_disk object for a block device or partition * - * @dev uclass device (UCLASS_BLK) + * @ctx: event context: driver binding protocol + * @event: EV_PM_PRE_REMOVE event * - * Delete an efi_disk object which is associated with @dev. - * The type of @dev must be UCLASS_BLK. + * Delete an efi_disk object which is associated with the UCLASS_BLK or + * UCLASS_PARTITION device for which the EV_PM_PRE_REMOVE event is raised. * - * @return 0 on success, -1 otherwise + * 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 = event->data.dm.dev; efi_handle_t handle; struct blk_desc *desc; - struct efi_disk_obj *diskobj; + struct efi_disk_obj *diskobj = NULL; if (dev_tag_get_ptr(dev, DM_TAG_EFI, (void **)&handle)) - return -1; + return 0; - desc = dev_get_uclass_plat(dev); - if (desc->uclass_id != UCLASS_EFI_LOADER) { + id = device_get_uclass_id(dev); + switch (id) { + case UCLASS_BLK: + desc = dev_get_uclass_plat(dev); + if (desc && desc->uclass_id != UCLASS_EFI_LOADER) + diskobj = container_of(handle, struct efi_disk_obj, + header); + break; + case UCLASS_PARTITION: diskobj = container_of(handle, struct efi_disk_obj, header); - efi_free_pool(diskobj->dp); + break; + 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); 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 * |