aboutsummaryrefslogtreecommitdiffstats
path: root/disk
diff options
context:
space:
mode:
authorMaxime Ripard2017-08-23 09:01:31 -0500
committerTom Rini2017-09-03 10:04:48 -0500
commit5276e8b62d958a50e90dc7e8cb8260be597ae51f (patch)
tree57b701f7fe080c49a16f36f78b31b9065cdcc1d6 /disk
parent89d33a2c0dce785b8c503399db91eec520def249 (diff)
downloadu-boot-5276e8b62d958a50e90dc7e8cb8260be597ae51f.tar.gz
u-boot-5276e8b62d958a50e90dc7e8cb8260be597ae51f.tar.xz
u-boot-5276e8b62d958a50e90dc7e8cb8260be597ae51f.zip
part: efi: rework the partition start and size in gpt_fill_pte
The start variable is only used inside a loop, and is never affected inside it, so it's a purely local variable. In the same way the partition size is accessed several times, so we can store it in a variable. Signed-off-by: Maxime Ripard <maxime.ripard@free-electrons.com> Reviewed-by: Tom Rini <trini@konsulko.com>
Diffstat (limited to 'disk')
-rw-r--r--disk/part_efi.c14
1 files changed, 8 insertions, 6 deletions
diff --git a/disk/part_efi.c b/disk/part_efi.c
index 75d0a78f0a..fa95ce1232 100644
--- a/disk/part_efi.c
+++ b/disk/part_efi.c
@@ -432,7 +432,6 @@ int gpt_fill_pte(gpt_header *gpt_h, gpt_entry *gpt_e,
432 disk_partition_t *partitions, int parts) 432 disk_partition_t *partitions, int parts)
433{ 433{
434 lbaint_t offset = (lbaint_t)le64_to_cpu(gpt_h->first_usable_lba); 434 lbaint_t offset = (lbaint_t)le64_to_cpu(gpt_h->first_usable_lba);
435 lbaint_t start;
436 lbaint_t last_usable_lba = (lbaint_t) 435 lbaint_t last_usable_lba = (lbaint_t)
437 le64_to_cpu(gpt_h->last_usable_lba); 436 le64_to_cpu(gpt_h->last_usable_lba);
438 int i, k; 437 int i, k;
@@ -448,24 +447,27 @@ int gpt_fill_pte(gpt_header *gpt_h, gpt_entry *gpt_e,
448 447
449 for (i = 0; i < parts; i++) { 448 for (i = 0; i < parts; i++) {
450 /* partition starting lba */ 449 /* partition starting lba */
451 start = partitions[i].start; 450 lbaint_t start = partitions[i].start;
451 lbaint_t size = partitions[i].size;
452
452 if (start && (start < offset)) { 453 if (start && (start < offset)) {
453 printf("Partition overlap\n"); 454 printf("Partition overlap\n");
454 return -1; 455 return -1;
455 } 456 }
457
456 if (start) { 458 if (start) {
457 gpt_e[i].starting_lba = cpu_to_le64(start); 459 gpt_e[i].starting_lba = cpu_to_le64(start);
458 offset = start + partitions[i].size; 460 offset = start + size;
459 } else { 461 } else {
460 gpt_e[i].starting_lba = cpu_to_le64(offset); 462 gpt_e[i].starting_lba = cpu_to_le64(offset);
461 offset += partitions[i].size; 463 offset += size;
462 } 464 }
463 if (offset > (last_usable_lba + 1)) { 465 if (offset > (last_usable_lba + 1)) {
464 printf("Partitions layout exceds disk size\n"); 466 printf("Partitions layout exceds disk size\n");
465 return -1; 467 return -1;
466 } 468 }
467 /* partition ending lba */ 469 /* partition ending lba */
468 if ((i == parts - 1) && (partitions[i].size == 0)) 470 if ((i == parts - 1) && (size == 0))
469 /* extend the last partition to maximuim */ 471 /* extend the last partition to maximuim */
470 gpt_e[i].ending_lba = gpt_h->last_usable_lba; 472 gpt_e[i].ending_lba = gpt_h->last_usable_lba;
471 else 473 else
@@ -525,7 +527,7 @@ int gpt_fill_pte(gpt_header *gpt_h, gpt_entry *gpt_e,
525 debug("%s: name: %s offset[%d]: 0x" LBAF 527 debug("%s: name: %s offset[%d]: 0x" LBAF
526 " size[%d]: 0x" LBAF "\n", 528 " size[%d]: 0x" LBAF "\n",
527 __func__, partitions[i].name, i, 529 __func__, partitions[i].name, i,
528 offset, i, partitions[i].size); 530 offset, i, size);
529 } 531 }
530 532
531 return 0; 533 return 0;