X-Git-Url: https://git.kernelconcepts.de/?p=karo-tx-uboot.git;a=blobdiff_plain;f=disk%2Fpart_efi.c;h=733d5bde94ed416e0831d326a0e865c56edc02b8;hp=59865897085c1750067a3c8f2712006cbe6c5abe;hb=61fcc7d2757bc5d6bf52739e4fc7132b5fa84efe;hpb=ec7023db8dc95966919589541f1ca09355a3f7a5 diff --git a/disk/part_efi.c b/disk/part_efi.c index 5986589708..733d5bde94 100644 --- a/disk/part_efi.c +++ b/disk/part_efi.c @@ -2,23 +2,7 @@ * Copyright (C) 2008 RuggedCom, Inc. * Richard Retanubun * - * See file CREDITS for list of people who contributed to this - * project. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, - * MA 02111-1307 USA + * SPDX-License-Identifier: GPL-2.0+ */ /* @@ -180,8 +164,9 @@ int get_partition_info_efi(block_dev_desc_t * dev_desc, int part, if (part > le32_to_cpu(gpt_head->num_partition_entries) || !is_pte_valid(&gpt_pte[part - 1])) { - printf("%s: *** ERROR: Invalid partition number %d ***\n", + debug("%s: *** ERROR: Invalid partition number %d ***\n", __func__, part); + free(gpt_pte); return -1; } @@ -200,8 +185,8 @@ int get_partition_info_efi(block_dev_desc_t * dev_desc, int part, uuid_string(gpt_pte[part - 1].unique_partition_guid.b, info->uuid); #endif - debug("%s: start 0x%lX, size 0x%lX, name %s", __func__, - info->start, info->size, info->name); + debug("%s: start 0x" LBAF ", size 0x" LBAF ", name %s", __func__, + info->start, info->size, info->name); /* Remember to free pte */ free(gpt_pte); @@ -228,10 +213,10 @@ int test_part_efi(block_dev_desc_t * dev_desc) */ static int set_protective_mbr(block_dev_desc_t *dev_desc) { - legacy_mbr *p_mbr; - /* Setup the Protective MBR */ - p_mbr = calloc(1, sizeof(p_mbr)); + ALLOC_CACHE_ALIGN_BUFFER(legacy_mbr, p_mbr, 1); + memset(p_mbr, 0, sizeof(*p_mbr)); + if (p_mbr == NULL) { printf("%s: calloc failed!\n", __func__); return -1; @@ -246,11 +231,9 @@ static int set_protective_mbr(block_dev_desc_t *dev_desc) if (dev_desc->block_write(dev_desc->dev, 0, 1, p_mbr) != 1) { printf("** Can't write to device %d **\n", dev_desc->dev); - free(p_mbr); return -1; } - free(p_mbr); return 0; } @@ -372,7 +355,7 @@ int gpt_fill_pte(gpt_header *gpt_h, gpt_entry *gpt_e, u32 offset = (u32)le32_to_cpu(gpt_h->first_usable_lba); ulong start; int i, k; - size_t name_len; + size_t efiname_len, dosname_len; #ifdef CONFIG_PARTITION_UUIDS char *str_uuid; #endif @@ -420,13 +403,18 @@ int gpt_fill_pte(gpt_header *gpt_h, gpt_entry *gpt_e, sizeof(gpt_entry_attributes)); /* partition name */ - name_len = sizeof(gpt_e[i].partition_name) + efiname_len = sizeof(gpt_e[i].partition_name) / sizeof(efi_char16_t); - for (k = 0; k < name_len; k++) + dosname_len = sizeof(partitions[i].name); + + memset(gpt_e[i].partition_name, 0, + sizeof(gpt_e[i].partition_name)); + + for (k = 0; k < min(dosname_len, efiname_len); k++) gpt_e[i].partition_name[k] = (efi_char16_t)(partitions[i].name[k]); - debug("%s: name: %s offset[%d]: 0x%x size[%d]: 0x%lx\n", + debug("%s: name: %s offset[%d]: 0x%x size[%d]: 0x" LBAF "\n", __func__, partitions[i].name, i, offset, i, partitions[i].size); }