From 5f7ed0da830d40fd738068d0fe5613076f3a4631 Mon Sep 17 00:00:00 2001 From: Oleksij Rempel Date: Fri, 15 Feb 2019 10:00:37 +0100 Subject: efi: cleanups make local functions static and remove unused code Signed-off-by: Oleksij Rempel Signed-off-by: Sascha Hauer --- common/efi-devicepath.c | 222 +----------------------------------------------- 1 file changed, 1 insertion(+), 221 deletions(-) (limited to 'common/efi-devicepath.c') diff --git a/common/efi-devicepath.c b/common/efi-devicepath.c index 54c2f4e3c5..24722284b4 100644 --- a/common/efi-devicepath.c +++ b/common/efi-devicepath.c @@ -453,34 +453,6 @@ struct efi_device_path end_instance_device_path = { .length = END_DEVICE_PATH_LENGTH, }; -unsigned long -device_path_size(struct efi_device_path *dev_path) -{ - struct efi_device_path *Start; - - Start = dev_path; - while (!is_device_path_end(dev_path)) - dev_path = next_device_path_node(dev_path); - - return ((unsigned long) dev_path - (unsigned long) Start) + - sizeof (struct efi_device_path); -} - -struct efi_device_path * -duplicate_device_path(struct efi_device_path *dev_path) -{ - struct efi_device_path *new_dev_path; - unsigned long Size; - - Size = device_path_size(dev_path); - - new_dev_path = malloc(Size); - if (new_dev_path) - memcpy(new_dev_path, dev_path, Size); - - return new_dev_path; -} - struct efi_device_path * device_path_from_handle(efi_handle_t Handle) { @@ -495,134 +467,7 @@ device_path_from_handle(efi_handle_t Handle) return device_path; } -struct efi_device_path * -device_path_instance(struct efi_device_path **device_path, unsigned long *Size) -{ - struct efi_device_path *Start, *Next, *dev_path; - unsigned long Count; - - dev_path = *device_path; - Start = dev_path; - - if (!dev_path) - return NULL; - - for (Count = 0;; Count++) { - Next = next_device_path_node(dev_path); - - if (is_device_path_end_type(dev_path)) - break; - - dev_path = Next; - } - - if (dev_path->sub_type == END_ENTIRE_DEVICE_PATH_SUBTYPE) - Next = NULL; - - *device_path = Next; - - *Size = ((u8 *) dev_path) - ((u8 *) Start); - - return Start; -} - -unsigned long -device_path_instance_count(struct efi_device_path *device_path) -{ - unsigned long Count, Size; - - Count = 0; - while (device_path_instance(&device_path, &Size)) { - Count += 1; - } - - return Count; -} - -struct efi_device_path * -append_device_path(struct efi_device_path *Src1, struct efi_device_path *Src2) -/* - * Src1 may have multiple "instances" and each instance is appended - * Src2 is appended to each instance is Src1. (E.g., it's possible - * to append a new instance to the complete device path by passing - * it in Src2) - */ -{ - unsigned long src1_size, src1_inst, src2_size, Size; - struct efi_device_path *Dst, *Inst; - u8 *dst_pos; - - if (!Src1) - return duplicate_device_path(Src2); - - if (!Src2) { - return duplicate_device_path(Src1); - } - - src1_size = device_path_size(Src1); - src1_inst = device_path_instance_count(Src1); - src2_size = device_path_size(Src2); - Size = src1_size * src1_inst + src2_size; - - Dst = malloc(Size); - if (Dst) { - dst_pos = (u8 *) Dst; - - /* Copy all device path instances */ - - while ((Inst = device_path_instance(&Src1, &Size))) { - - memcpy(dst_pos, Inst, Size); - dst_pos += Size; - - memcpy(dst_pos, Src2, src2_size); - dst_pos += src2_size; - - memcpy(dst_pos, &end_instance_device_path, - sizeof (struct efi_device_path)); - dst_pos += sizeof (struct efi_device_path); - } - - /* Change last end marker */ - dst_pos -= sizeof (struct efi_device_path); - memcpy(dst_pos, &end_device_path, - sizeof (struct efi_device_path)); - } - - return Dst; -} - -struct efi_device_path * -append_device_path_node(struct efi_device_path *Src1, - struct efi_device_path *Src2) -/* - * Src1 may have multiple "instances" and each instance is appended - * Src2 is a signal device path node (without a terminator) that is - * appended to each instance is Src1. - */ -{ - struct efi_device_path *Temp, *Eop; - unsigned long length; - - /* Build a Src2 that has a terminator on it */ - - length = Src2->length; - Temp = malloc(length + sizeof (struct efi_device_path)); - if (!Temp) - return NULL; - - memcpy(Temp, Src2, length); - Eop = next_device_path_node(Temp); - set_device_path_end_node(Eop); - - /* Append device paths */ - - Src1 = append_device_path(Src1, Temp); - free(Temp); - return Src1; -} - -struct efi_device_path * +static struct efi_device_path * unpack_device_path(struct efi_device_path *dev_path) { struct efi_device_path *Src, *Dest, *new_path; @@ -665,71 +510,6 @@ unpack_device_path(struct efi_device_path *dev_path) return new_path; } -struct efi_device_path * -append_device_path_instance(struct efi_device_path *Src, - struct efi_device_path *Instance) -{ - u8 *Ptr; - struct efi_device_path *dev_path; - unsigned long src_size; - unsigned long instance_size; - - if (Src == NULL) - return duplicate_device_path(Instance); - - src_size = device_path_size(Src); - instance_size = device_path_size(Instance); - Ptr = malloc(src_size + instance_size); - dev_path = (struct efi_device_path *) Ptr; - - memcpy(Ptr, Src, src_size); - - while (!is_device_path_end(dev_path)) - dev_path = next_device_path_node(dev_path); - - /* - * Convert the End to an End Instance, since we are - * appending another instacne after this one its a good - * idea. - */ - dev_path->sub_type = END_INSTANCE_DEVICE_PATH_SUBTYPE; - - dev_path = next_device_path_node(dev_path); - memcpy(dev_path, Instance, instance_size); - - return (struct efi_device_path *) Ptr; -} - -efi_status_t -lib_device_path_to_interface(efi_guid_t * Protocol, - struct efi_device_path *file_path, - void **Interface) -{ - efi_status_t Status; - efi_handle_t Device; - - Status = BS->locate_device_path(Protocol, &file_path, &Device); - - if (!EFI_ERROR(Status)) { - - /* If we didn't get a direct match return not found */ - Status = EFI_NOT_FOUND; - - if (is_device_path_end(file_path)) { - - /* It was a direct match, lookup the protocol interface */ - - Status = - BS->handle_protocol(Device, Protocol, Interface); - } - } - - if (EFI_ERROR(Status)) - *Interface = NULL; - - return Status; -} - static void dev_path_pci(struct string *str, void *dev_path) { -- cgit v1.2.3