mxc_ipuv3_fb.c: call display_enable
[platform/kernel/u-boot.git] / disk / part_dos.c
index 1a36be0..aae9d95 100644 (file)
@@ -1,9 +1,8 @@
+// SPDX-License-Identifier: GPL-2.0+
 /*
  * (C) Copyright 2001
  * Raymond Lo, lo@routefree.com
  * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
- *
- * SPDX-License-Identifier:    GPL-2.0+
  */
 
 /*
 #include <memalign.h>
 #include "part_dos.h"
 
-#ifdef HAVE_BLOCK_DEVICE
+#ifdef CONFIG_HAVE_BLOCK_DEVICE
 
 #define DOS_PART_DEFAULT_SECTOR 512
 
+/* should this be configurable? It looks like it's not very common at all
+ * to use large numbers of partitions */
+#define MAX_EXT_PARTS 256
+
 /* Convert char[4] in little endian format to the host format integer
  */
 static inline unsigned int le32_to_int(unsigned char *le32)
@@ -89,7 +92,8 @@ static int test_block_type(unsigned char *buffer)
 
 static int part_test_dos(struct blk_desc *dev_desc)
 {
-       ALLOC_CACHE_ALIGN_BUFFER(legacy_mbr, mbr, dev_desc->blksz);
+#ifndef CONFIG_SPL_BUILD
+       ALLOC_CACHE_ALIGN_BUFFER(legacy_mbr, mbr, 1);
 
        if (blk_dread(dev_desc, 0, 1, (ulong *)mbr) != 1)
                return -1;
@@ -102,6 +106,15 @@ static int part_test_dos(struct blk_desc *dev_desc)
                dev_desc->sig_type = SIG_TYPE_MBR;
                dev_desc->mbr_sig = mbr->unique_mbr_signature;
        }
+#else
+       ALLOC_CACHE_ALIGN_BUFFER(unsigned char, buffer, dev_desc->blksz);
+
+       if (blk_dread(dev_desc, 0, 1, (ulong *)buffer) != 1)
+               return -1;
+
+       if (test_block_type(buffer) != DOS_MBR)
+               return -1;
+#endif
 
        return 0;
 }
@@ -117,6 +130,13 @@ static void print_partition_extended(struct blk_desc *dev_desc,
        dos_partition_t *pt;
        int i;
 
+       /* set a maximum recursion level */
+       if (part_num > MAX_EXT_PARTS)
+       {
+               printf("** Nested DOS partitions detected, stopping **\n");
+               return;
+    }
+
        if (blk_dread(dev_desc, ext_part_sector, 1, (ulong *)buffer) != 1) {
                printf ("** Can't read partition table on %d:" LBAFU " **\n",
                        dev_desc->devnum, ext_part_sector);
@@ -182,6 +202,13 @@ static int part_get_info_extended(struct blk_desc *dev_desc,
        int i;
        int dos_type;
 
+       /* set a maximum recursion level */
+       if (part_num > MAX_EXT_PARTS)
+       {
+               printf("** Nested DOS partitions detected, stopping **\n");
+               return -1;
+    }
+
        if (blk_dread(dev_desc, ext_part_sector, 1, (ulong *)buffer) != 1) {
                printf ("** Can't read partition table on %d:" LBAFU " **\n",
                        dev_desc->devnum, ext_part_sector);
@@ -210,7 +237,7 @@ static int part_get_info_extended(struct blk_desc *dev_desc,
                if (((pt->boot_ind & ~0x80) == 0) &&
                    (pt->sys_ind != 0) &&
                    (part_num == which_part) &&
-                   (is_extended(pt->sys_ind) == 0)) {
+                   (ext_part_sector == 0 || is_extended(pt->sys_ind) == 0)) {
                        info->blksz = DOS_PART_DEFAULT_SECTOR;
                        info->start = (lbaint_t)(ext_part_sector +
                                        le32_to_int(pt->start4));