diff options
author | Sascha Hauer <s.hauer@pengutronix.de> | 2021-06-02 09:15:33 +0200 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2021-06-09 14:34:11 +0200 |
commit | 71c1671d27eb2e561f0b23b245925b2e27e67042 (patch) | |
tree | 75a0ba5826a86eda2e64a41dde346e8c33aa61e9 /common | |
parent | 2a4c3b384ca35a83eb7e973fccea5bd20f8b2567 (diff) | |
download | barebox-71c1671d27eb2e561f0b23b245925b2e27e67042.tar.gz barebox-71c1671d27eb2e561f0b23b245925b2e27e67042.tar.xz |
partitions: efi: Fix MAX_PARTITION check
The GPT partiton parser has a check which should check if the GPT has
more partitions than we support. This doesn't work because the loop
iterating over the partitions exits with a maximum i of MAX_PARTITION,
i > MAX_PARTITION will never be true. Fix the check.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Reviewed-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
Link: https://lore.barebox.org/20210602071533.10093-2-s.hauer@pengutronix.de
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'common')
-rw-r--r-- | common/partitions/efi.c | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/common/partitions/efi.c b/common/partitions/efi.c index 437c3d64f8..135b08901a 100644 --- a/common/partitions/efi.c +++ b/common/partitions/efi.c @@ -446,7 +446,14 @@ static void efi_partition(void *buf, struct block_device *blk, } nb_part = le32_to_cpu(gpt->num_partition_entries); - for (i = 0; i < MAX_PARTITION && i < nb_part; i++) { + + if (nb_part > MAX_PARTITION) { + dev_warn(blk->dev, "GPT has more partitions than we support (%d) > max partition number (%d)\n", + nb_part, MAX_PARTITION); + nb_part = MAX_PARTITION; + } + + for (i = 0; i < nb_part; i++) { if (!is_pte_valid(&ptes[i], last_lba(blk))) { dev_dbg(blk->dev, "Invalid pte %d\n", i); return; @@ -460,10 +467,6 @@ static void efi_partition(void *buf, struct block_device *blk, snprintf(pentry->partuuid, sizeof(pentry->partuuid), "%pUl", &ptes[i].unique_partition_guid); pd->used_entries++; } - - if (i > MAX_PARTITION) - dev_warn(blk->dev, "num_partition_entries (%d) > max partition number (%d)\n", - nb_part, MAX_PARTITION); } static struct partition_parser efi_partition_parser = { |