[PATCH v2 08/41] disk: part_dos: Fix a NULL pointer error
Simon Glass
sjg at chromium.org
Sun Oct 24 01:26:02 CEST 2021
When ext is NULL we cannot dereference it. Update the code flow to avoid
this, so that layout_mbr_partitions() can be used with partition tables
that do not include an extended partition.
Signed-off-by: Simon Glass <sjg at chromium.org>
---
(no changes since v1)
disk/part_dos.c | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)
diff --git a/disk/part_dos.c b/disk/part_dos.c
index 9e29aa6583a..94fae7166d7 100644
--- a/disk/part_dos.c
+++ b/disk/part_dos.c
@@ -459,10 +459,12 @@ int layout_mbr_partitions(struct disk_partition *p, int count,
ext = &p[i];
}
- if (i >= 4 && !ext) {
- printf("%s: extended partition is needed for more than 4 partitions\n",
- __func__);
- return -1;
+ if (count < 4)
+ return 0;
+
+ if (!ext) {
+ log_err("extended partition is needed for more than 4 partitions\n");
+ return -EINVAL;
}
/* calculate extended volumes start and size if needed */
--
2.33.0.1079.g6e70778dc9-goog
More information about the U-Boot
mailing list