disk: part_dos: Fix a NULL pointer error
authorSimon Glass <sjg@chromium.org>
Sat, 23 Oct 2021 23:26:02 +0000 (17:26 -0600)
committerSimon Glass <sjg@chromium.org>
Sun, 28 Nov 2021 23:51:51 +0000 (16:51 -0700)
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>
disk/part_dos.c

index 9e29aa6..94fae71 100644 (file)
@@ -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 */