summaryrefslogtreecommitdiff
path: root/disk
diff options
context:
space:
mode:
authorSimon Glass <sjg@chromium.org>2021-10-23 17:26:02 -0600
committerSimon Glass <sjg@chromium.org>2021-11-28 16:51:51 -0700
commitb7c2cc49ffa50b8a0664460f3899536e07a78158 (patch)
tree0a1c9884a12a31d2db62a9bab5d85eeaa034e5c0 /disk
parent362a79f3e8582138545d408a56d4accf35e894b3 (diff)
disk: part_dos: Fix a NULL pointer error
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@chromium.org>
Diffstat (limited to 'disk')
-rw-r--r--disk/part_dos.c10
1 files changed, 6 insertions, 4 deletions
diff --git a/disk/part_dos.c b/disk/part_dos.c
index 9e29aa6583..94fae7166d 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 */