kernel: fix FIT partition parser compatibility issues
[openwrt/staging/wigyori.git] / target / linux / generic / hack-5.4 / 400-block-fit-partition-parser.patch
index 1f756fac9b184b29fb1a2f2019f4ef2c7367a46d..6b3267ef80bca1d9374942f828589e3058d80f3b 100644 (file)
 +int parse_fit_partitions(struct parsed_partitions *state, u64 start_sector, u64 nr_sectors, int *slot, int add_remain);
 --- a/block/partitions/efi.c
 +++ b/block/partitions/efi.c
-@@ -679,7 +679,7 @@ int efi_partition(struct parsed_partitio
- {
-       gpt_header *gpt = NULL;
+@@ -681,6 +681,9 @@ int efi_partition(struct parsed_partitio
        gpt_entry *ptes = NULL;
--      u32 i;
-+      u32 i, slot = 0;
+       u32 i;
        unsigned ssz = bdev_logical_block_size(state->bdev) / 512;
++#ifdef CONFIG_FIT_PARTITION
++      u32 extra_slot = 64;
++#endif
  
        if (!find_valid_gpt(state, &gpt, &ptes) || !gpt || !ptes) {
-@@ -698,16 +698,18 @@ int efi_partition(struct parsed_partitio
-               u64 size = le64_to_cpu(ptes[i].ending_lba) -
-                          le64_to_cpu(ptes[i].starting_lba) + 1ULL;
--              if (!is_pte_valid(&ptes[i], last_lba(state->bdev)))
-+              if (!is_pte_valid(&ptes[i], last_lba(state->bdev))) {
-+                      ++slot;
-                       continue;
-+              }
--              put_partition(state, i+1, start * ssz, size * ssz);
-+              put_partition(state, ++slot, start * ssz, size * ssz);
-               /* If this is a RAID volume, tell md */
-               if (!efi_guidcmp(ptes[i].partition_type_guid, PARTITION_LINUX_RAID_GUID))
--                      state->parts[i + 1].flags = ADDPART_FLAG_RAID;
-+                      state->parts[slot].flags = ADDPART_FLAG_RAID;
--              info = &state->parts[i + 1].info;
-+              info = &state->parts[slot].info;
-               efi_guid_to_str(&ptes[i].unique_partition_guid, info->uuid);
-               /* Naively convert UTF16-LE to 7 bits. */
-@@ -721,7 +723,12 @@ int efi_partition(struct parsed_partitio
-                       info->volname[label_count] = c;
+               kfree(gpt);
+@@ -722,6 +725,11 @@ int efi_partition(struct parsed_partitio
                        label_count++;
                }
--              state->parts[i + 1].has_info = true;
-+              state->parts[slot].has_info = true;
+               state->parts[i + 1].has_info = true;
 +#ifdef CONFIG_FIT_PARTITION
 +              /* If this is a U-Boot FIT volume it may have subpartitions */
 +              if (!efi_guidcmp(ptes[i].partition_type_guid, PARTITION_LINUX_FIT_GUID))
-+                      (void) parse_fit_partitions(state, start * ssz, size * ssz, &slot, 1);
++                      (void) parse_fit_partitions(state, start * ssz, size * ssz, &extra_slot, 1);
 +#endif
        }
        kfree(ptes);