--- linux/fs/partitions/efi.h.orig	Tue Sep 25 16:47:20 2001
+++ linux/fs/partitions/efi.h	Wed Sep 26 16:27:41 2001
@@ -1,10 +1,10 @@
 /************************************************************
  * EFI GUID Partition Table
- * Per Intel EFI Specification v0.99
+ * Per Intel EFI Specification v1.02
  * http://developer.intel.com/technology/efi/efi.htm
  *
  * By Matt Domsch <Matt_Domsch@dell.com>  Fri Sep 22 22:15:56 CDT 2000  
- *   Copyright 2000 Dell Computer Corporation
+ *   Copyright 2000,2001 Dell Computer Corporation
  *
  *  This program is free software; you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by
@@ -40,11 +40,9 @@
 #define EFI_PMBR_OSTYPE_EFI 0xEF
 #define EFI_PMBR_OSTYPE_EFI_GPT 0xEE
 
-#define GUID_PT_BLOCK_SIZE 512
-
-#define GUID_PT_HEADER_SIGNATURE 0x5452415020494645L
-#define GUID_PT_HEADER_REVISION_V1 0x00010000
-#define GUID_PT_HEADER_REVISION_V0_99 0x00000099
+#define GPT_BLOCK_SIZE 512
+#define GPT_HEADER_SIGNATURE 0x5452415020494645L
+#define GPT_HEADER_REVISION_V1 0x00010000
 #define UNUSED_ENTRY_GUID    \
     ((efi_guid_t) { 0x00000000, 0x0000, 0x0000, { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }})
 #define PARTITION_SYSTEM_GUID \
@@ -59,6 +57,8 @@
     ((efi_guid_t) { 0xa19d880f, 0x05fc, 0x4d3b, { 0xa0, 0x06, 0x74, 0x3f, 0x0f, 0x84, 0x91, 0x1e  }})
 #define PARTITION_LINUX_SWAP_GUID \
     ((efi_guid_t) { 0x0657fd6d, 0xa4ab, 0x43c4, { 0x84, 0xe5, 0x09, 0x33, 0xc8, 0x4b, 0x4f, 0x4f  }})
+#define PARTITION_LINUX_LVM_GUID \
+    ((efi_guid_t) { 0xe6d6d379, 0xf507, 0x44c2, { 0xa2, 0x3c, 0x23, 0x8f, 0x2a, 0x3d, 0xf9, 0x28 }})
 
 typedef struct _GuidPartitionTableHeader_t {
   u64 Signature;
@@ -75,13 +75,13 @@
   u32 NumberOfPartitionEntries;
   u32 SizeOfPartitionEntry;
   u32 PartitionEntryArrayCRC32;
-  u8 Reserved2[GUID_PT_BLOCK_SIZE - 92];
-} GuidPartitionTableHeader_t;
+  u8 Reserved2[GPT_BLOCK_SIZE - 92];
+} __attribute__((packed)) GuidPartitionTableHeader_t;
 
 typedef struct _GuidPartitionEntryAttributes_t {
   __u64 RequiredToFunction:1;
   __u64 Reserved:63;
-} GuidPartitionEntryAttributes_t;
+} __attribute__((packed)) GuidPartitionEntryAttributes_t;
 
 typedef struct _GuidPartitionEntry_t {
   efi_guid_t PartitionTypeGuid;
@@ -90,9 +90,7 @@
   u64 EndingLBA;
   GuidPartitionEntryAttributes_t Attributes;
   efi_char16_t PartitionName[72/sizeof(efi_char16_t)];
-} GuidPartitionEntry_t;
-
-
+} __attribute__((packed)) GuidPartitionEntry_t;
 
 typedef struct _PartitionRecord_t {
   u8 BootIndicator;  /* Not used by EFI firmware. Set to 0x80 to indicate that this
@@ -118,7 +116,7 @@
   u16 Unknown;
   PartitionRecord_t PartitionRecord[4];
   u16 Signature;
-} __attribute__ ((packed)) LegacyMBR_t;
+} __attribute__((packed)) LegacyMBR_t;
 
 
 
--- linux/Documentation/kernel-parameters.txt.orig	Fri Sep 28 10:50:21 2001
+++ linux/Documentation/kernel-parameters.txt	Fri Sep 28 10:58:08 2001
@@ -17,6 +17,7 @@
 	CD	Appropriate CD support is enabled.
 	DEVFS   devfs support is enabled. 
 	DRM	Direct Rendering Management support is enabled. 
+	EFI	EFI Partitioning (GPT) is enabled
 	EIDE	EIDE/ATAPI support is enabled.
 	FB	The frame buffer device is enabled.
 	HW	Appropriate hardware is enabled.
@@ -212,6 +213,9 @@
  
 	gdth=		[HW,SCSI]
 
+	gpt             [EFI] Forces disk with valid GPT signature but
+			invalid Protective MBR to be treated as GPT.
+
 	gscd=		[HW,CD]
 
 	gus=		[HW,SOUND] 
--- linux/fs/partitions/efi.c.orig	Tue Sep 25 17:47:17 2001
+++ linux/fs/partitions/efi.c	Mon Oct  1 14:54:45 2001
@@ -1,11 +1,11 @@
 /************************************************************
  * EFI GUID Partition Table handling
- * Per Intel EFI Specification v0.99
+ * Per Intel EFI Specification v1.02
  * http://developer.intel.com/technology/efi/efi.htm
  * efi.[ch] by Matt Domsch <Matt_Domsch@dell.com>
- *   Copyright 2000 Dell Computer Corporation
+ *   Copyright 2000,2001 Dell Computer Corporation
  *
- * Note, the EFI Specification, v0.99, has a reference to
+ * Note, the EFI Specification, v1.02, has a reference to
  * Dr. Dobbs Journal, May 1994 (actually it's in May 1992)
  * but that isn't the CRC function being used by EFI.  Intel's
  * EFI Sample Implementation shows that they use the same function
@@ -27,8 +27,27 @@
  *
  *
  * TODO:
+ * - Change read_lba() when 64-bit block addressing is allowed.
+ * - printing of 64-bit values on a 32-bit system is broken.  %llx should
+ *   work on both ia64 and ia32 to print a u64, but if -Wall is used,
+ *   gcc complains.
  *
  * Changelog:
+ * Mon Oct 01 2001 Matt Domsch <Matt_Domsch@dell.com>
+ * - Style cleanups
+ * - made most functions static
+ * - Endianness addition
+ * - remove test for second alternate header, as it's not per spec,
+ *   and is unnecessary.  There's now a method to read/write the last
+ *   sector of an odd-sized disk from user space.  No tools have ever
+ *   been released which used this code, so it's effectively dead.
+ * - Per Asit Mallick of Intel, added a test for a valid PMBR.
+ * - Added kernel command line option 'gpt' to override valid PMBR test.
+ *
+ * Wed Jun  6 2001 Martin Wilck <Martin.Wilck@Fujitsu-Siemens.com>
+ * - added devfs GUID support (/dev/guid) for mounting file systems
+ *   by the partition GUID. 
+ *
  * Tue Dec  5 2000 Matt Domsch <Matt_Domsch@dell.com>
  * - Moved crc32() to linux/lib, added efi_crc32().
  *
@@ -37,7 +56,7 @@
  *   non-license-restricted version.
  *
  * Wed Oct 25 2000 Matt Domsch <Matt_Domsch@dell.com>
- * - Fixed the LastLBA() call to return the proper last block
+ * - Fixed the last_lba() call to return the proper last block
  *
  * Thu Oct 12 2000 Matt Domsch <Matt_Domsch@dell.com>
  * - Thanks to Andries Brouwer for his debugging assistance.
@@ -52,11 +71,13 @@
 #include <linux/string.h>
 #include <linux/blk.h>
 #include <linux/blkpg.h>
-#include <linux/malloc.h>
+#include <linux/slab.h>
 #include <linux/smp_lock.h>
+#include <linux/crc32.h>
+#include <linux/init.h>
 #include <asm/system.h>
 #include <asm/efi.h>
-#include <linux/crc32.h>
+#include <asm/byteorder.h>
 
 #include "check.h"
 #include "efi.h"
@@ -74,6 +95,21 @@ static char *efi_printk_level = KERN_DEB
 #define debug_printk(...)
 #endif
 
+/* This allows a kernel command line option 'gpt' to override
+ * the test for invalid PMBR.  Not __initdata because reloading
+ * the partition tables happens after init too.
+ */
+static int forcegpt;
+static int __init force_gpt (char *str)
+{
+        forcegpt = 1;
+	return 1;
+}
+__setup("gpt", force_gpt);
+
+
+
+
 /************************************************************
  * efi_crc32()
  * Requires:
@@ -86,17 +122,55 @@ static char *efi_printk_level = KERN_DEB
  * but seeds the function with ~0, and xor's with ~0 at the end.
  ************************************************************/
 
-u32 static inline
+static inline u32
 efi_crc32(const void *buf, unsigned long len)
 {
   return (crc32(buf, len, ~0L) ^ ~0L);
 }
 
 
+/************************************************************
+ * le_guid_to_cpus()
+ * Requires: guid
+ * Modifies: guid in situ
+ * Returns: nothing
+ *
+ * This function converts a little endian efi_guid_t to the
+ * native cpu representation.  The EFI Spec. declares that all 
+ * on-disk structures are stored in little endian format.
+ * 
+ ************************************************************/
+
+static void
+le_guid_to_cpus(efi_guid_t *guid)
+{
+        le32_to_cpus(guid->data1);
+        le16_to_cpus(guid->data2);
+        le16_to_cpus(guid->data3);
+       /* no need to change data4. It's already an array of chars */
+        return;
+}
+
+/************************************************************
+ * le_part_attributes_to_cpus()
+ * Requires: attributes
+ * Modifies: attributes in situ
+ * Returns: nothing
+ *
+ * This function converts a little endian partition attributes
+ * struct to the native cpu representation.
+ * 
+ ************************************************************/
 
+static void
+le_part_attributes_to_cpus(GuidPartitionEntryAttributes_t *a)
+{
+        u64 *b = (u64 *)a;
+        *b = le64_to_cpu(*b);
+}
 
 /************************************************************
- * IsLegacyMBRValid()
+ * is_pmbr_valid()
  * Requires:
  *  - mbr is a pointer to a legacy mbr structure
  * Modifies: nothing
@@ -104,16 +178,25 @@ efi_crc32(const void *buf, unsigned long
  *  1 on true
  *  0 on false
  ************************************************************/
-static inline int
-IsLegacyMBRValid(LegacyMBR_t *mbr)
+static int
+is_pmbr_valid(LegacyMBR_t *mbr)
 {
-	return (mbr ? (mbr->Signature == MSDOS_MBR_SIGNATURE) : 0);
+        int i, found = 0, signature = 0;
+        if (!mbr) return 0;
+	signature = (le16_to_cpu(mbr->Signature) == MSDOS_MBR_SIGNATURE);
+        for (i=0; signature && i<4; i++) {
+                if (mbr->PartitionRecord[i].OSType ==
+                    EFI_PMBR_OSTYPE_EFI_GPT) {
+                        found = 1;
+                        break;
+                }
+        }
+        return (signature && found);
 }
 
 
-
 /************************************************************
- * LastLBA()
+ * last_lba()
  * Requires:
  *  - struct gendisk hd
  *  - kdev_t dev
@@ -125,8 +208,8 @@ IsLegacyMBRValid(LegacyMBR_t *mbr)
  *  physical sectors available on the disk.
  *  0 on error
  ************************************************************/
-u64
-LastLBA(struct gendisk *hd, kdev_t dev)
+static u64
+last_lba(struct gendisk *hd, kdev_t dev)
 {
   if (!hd || !hd->part) return 0;
   return hd->part[MINOR(dev)].nr_sects - 1;
@@ -134,7 +217,7 @@ LastLBA(struct gendisk *hd, kdev_t dev)
 
 
 /************************************************************
- * ReadLBA()
+ * read_lba()
  * Requires:
  *  - hd is our disk device.
  *  - dev is our device major number
@@ -154,12 +237,12 @@ LastLBA(struct gendisk *hd, kdev_t dev)
  ************************************************************/
 
 static size_t
-ReadLBA(struct gendisk *hd, kdev_t dev, u64 _lba, u8 *buffer, size_t count)
+read_lba(struct gendisk *hd, kdev_t dev, u64 _lba, u8 *buffer, size_t count)
 {
 	struct buffer_head *bh;
 	size_t totalreadcount = 0, bytesread;
 	int lba = (_lba & 0x7FFFFFFF), i, blockstoread, blocksize;
-	debug_printk(efi_printk_level "ReadLBA(%p,%s,%x,%p,%x)\n",
+	debug_printk(efi_printk_level "read_lba(%p,%s,%x,%p,%x)\n",
 		     hd, kdevname(dev), lba, buffer, count);
 
 	if (!hd || !buffer || !count) return 0;
@@ -194,8 +277,10 @@ ReadLBA(struct gendisk *hd, kdev_t dev, 
 	return totalreadcount;
 }
 
-void
-PrintGuidPartitionTableHeader(GuidPartitionTableHeader_t *gpt)
+
+
+static void
+print_gpt_header(GuidPartitionTableHeader_t *gpt)
 {
 	debug_printk(efi_printk_level "GUID Partition Table Header\n");
 	if (!gpt) return;
@@ -231,23 +316,21 @@ PrintGuidPartitionTableHeader(GuidPartit
 
 
 /************************************************************
- * ReadGuidPartitionEntries()
+ * alloc_read_gpt_entries()
  * Requires:
- *  - filedes is an open file descriptor, suitable for reading
- *  - lba is the Logical Block Address of the partition table
- *  - gpt is a buffer into which the GPT will be put
+ *  - hd, dev, gpt
  * Modifies:
- *  - filedes file and pointer
- *  - gpt
+ *  - nothing
  * Returns:
- *   pte on success
+ *   ptes on success
  *   NULL on error
  * Notes: remember to free pte when you're done!
  ************************************************************/
-GuidPartitionEntry_t *
-ReadGuidPartitionEntries(struct gendisk *hd, kdev_t dev,
+static GuidPartitionEntry_t *
+alloc_read_gpt_entries(struct gendisk *hd, kdev_t dev,
 			 GuidPartitionTableHeader_t *gpt)
 {
+        u32 i, j;
 	size_t count;
 	GuidPartitionEntry_t *pte;
 	if (!hd || !gpt) return NULL;
@@ -260,18 +343,30 @@ ReadGuidPartitionEntries(struct gendisk 
 	if (!pte)  return NULL;
 	memset(pte, 0, count);
 
-	if (ReadLBA(hd, dev, gpt->PartitionEntryLBA, (u8 *)pte,
+	if (read_lba(hd, dev, gpt->PartitionEntryLBA, (u8 *)pte,
 		    count) < count) {
 		kfree(pte);
 		return NULL;
 	}
+        /* Fixup endianness */
+        for (i=0; i<gpt->NumberOfPartitionEntries; i++) {
+                le_guid_to_cpus(&pte[i].PartitionTypeGuid);
+                le_guid_to_cpus(&pte[i].UniquePartitionGuid);
+                le64_to_cpus(pte[i].StartingLBA);
+                le64_to_cpus(pte[i].EndingLBA);
+                le_part_attributes_to_cpus(&pte[i].Attributes);
+                for (j=0; j<(72/sizeof(efi_char16_t)); j++) {
+                        le16_to_cpus((u16)(pte[i].PartitionName[j]));
+                }
+        }
+        
 	return pte;
 }
 
 
 
 /************************************************************
- * ReadGuidPartitionTableHeader()
+ * alloc_read_gpt_header()
  * Requires:
  *  - hd is our struct gendisk
  *  - dev is our device major number
@@ -285,8 +380,8 @@ ReadGuidPartitionEntries(struct gendisk 
  *   0 on error
  ************************************************************/
 
-GuidPartitionTableHeader_t *
-ReadGuidPartitionTableHeader(struct gendisk *hd, kdev_t dev, u64 lba)
+static GuidPartitionTableHeader_t *
+alloc_read_gpt_header(struct gendisk *hd, kdev_t dev, u64 lba)
 
 {
 	GuidPartitionTableHeader_t *gpt;
@@ -296,8 +391,8 @@ ReadGuidPartitionTableHeader(struct gend
 	if (!gpt) return NULL;
 	memset(gpt, 0, sizeof(GuidPartitionTableHeader_t));
 
-	debug_printk(efi_printk_level "GPTH() calling ReadLBA().\n");
-	if (ReadLBA(hd, dev, lba, (u8 *)gpt,
+	debug_printk(efi_printk_level "GPTH() calling read_lba().\n");
+	if (read_lba(hd, dev, lba, (u8 *)gpt,
 		    sizeof(GuidPartitionTableHeader_t)) <
 	    sizeof(GuidPartitionTableHeader_t)) {
 		debug_printk(efi_printk_level "ReadGPTH(%lx) read failed.\n",
@@ -305,7 +400,24 @@ ReadGuidPartitionTableHeader(struct gend
 		kfree(gpt);
 		return NULL;
 	}
-	PrintGuidPartitionTableHeader(gpt);
+
+        /* Fixup endianness */
+        le64_to_cpus(gpt->Signature);
+        le32_to_cpus(gpt->Revision);
+        le32_to_cpus(gpt->HeaderSize);
+        le32_to_cpus(gpt->HeaderCRC32);
+        le32_to_cpus(gpt->Reserved1);
+        le64_to_cpus(gpt->MyLBA);
+        le64_to_cpus(gpt->AlternateLBA);
+        le64_to_cpus(gpt->FirstUsableLBA);
+        le64_to_cpus(gpt->LastUsableLBA);
+        le_guid_to_cpus(&gpt->DiskGUID);
+        le64_to_cpus(gpt->PartitionEntryLBA);
+        le32_to_cpus(gpt->NumberOfPartitionEntries);
+        le32_to_cpus(gpt->SizeOfPartitionEntry);
+        le32_to_cpus(gpt->PartitionEntryArrayCRC32);
+
+	print_gpt_header(gpt);
 
 	return gpt;
 }
@@ -313,7 +425,7 @@ ReadGuidPartitionTableHeader(struct gend
 
 
 /************************************************************
- * IsGuidPartitionTableValid()
+ * is_gpt_valid()
  * Requires:
  *  - gd points to our struct gendisk
  *  - dev is our device major number
@@ -327,18 +439,18 @@ ReadGuidPartitionTableHeader(struct gend
  *   0 on error
  ************************************************************/
 static int
-IsGuidPartitionTableValid(struct gendisk *hd, kdev_t dev, u64 lba,
+is_gpt_valid(struct gendisk *hd, kdev_t dev, u64 lba,
 			  GuidPartitionTableHeader_t **gpt,
 			  GuidPartitionEntry_t **ptes)
 {
 	u32 crc, origcrc;
 
 	if (!hd || !gpt || !ptes) return 0;
-	if (!(*gpt = ReadGuidPartitionTableHeader(hd, dev, lba))) return 0;
+	if (!(*gpt = alloc_read_gpt_header(hd, dev, lba))) return 0;
 
 	/* Check the GUID Partition Table Signature */
-	if ((*gpt)->Signature != GUID_PT_HEADER_SIGNATURE) {
-		debug_printk(efi_printk_level "GUID Partition Table Header Signature is wrong: %x != %x\n", (*gpt)->Signature, GUID_PT_HEADER_SIGNATURE);
+	if ((*gpt)->Signature != GPT_HEADER_SIGNATURE) {
+		debug_printk(efi_printk_level "GUID Partition Table Header Signature is wrong: %x != %x\n", (*gpt)->Signature, GPT_HEADER_SIGNATURE);
 		kfree(*gpt);
 		*gpt = NULL;
 		return 0;
@@ -367,7 +479,7 @@ IsGuidPartitionTableValid(struct gendisk
 		return 0;
 	}
 
-	if (!(*ptes = ReadGuidPartitionEntries(hd, dev, *gpt))) {
+	if (!(*ptes = alloc_read_gpt_entries(hd, dev, *gpt))) {
 		debug_printk(efi_printk_level "read PTEs failed.\n");
 		kfree(*gpt);
 		*gpt = NULL;
@@ -396,7 +508,7 @@ IsGuidPartitionTableValid(struct gendisk
 
 
 /************************************************************
- * FindValidGPT()
+ * find_valid_gpt()
  * Requires:
  *  - gd points to our struct gendisk
  *  - dev is our device major number
@@ -409,24 +521,25 @@ IsGuidPartitionTableValid(struct gendisk
  *   0 on error
  ************************************************************/
 static int
-FindValidGPT(struct gendisk *hd, kdev_t dev,
+find_valid_gpt(struct gendisk *hd, kdev_t dev,
 	     GuidPartitionTableHeader_t **gpt,
 	     GuidPartitionEntry_t **ptes)
 {
-	int rc = 0;
+	int good_pgpt = 0, good_agpt=0, good_pmbr=0;
 	GuidPartitionTableHeader_t *pgpt = NULL, *agpt = NULL;
 	GuidPartitionEntry_t *pptes = NULL, *aptes = NULL;
+        LegacyMBR_t *legacyMbr = NULL;
 	u64 lastlba;
 	if (!hd || !gpt || !ptes) return 0;
 
-	lastlba = LastLBA(hd, dev);
+	lastlba = last_lba(hd, dev);
 	/* Check the Primary GPT */
-	rc = IsGuidPartitionTableValid(hd, dev, 1, &pgpt, &pptes);
-	if (rc) {
+	good_pgpt = is_gpt_valid(hd, dev, 1, &pgpt, &pptes);
+	if (good_pgpt) {
 		/* Primary GPT is OK, check the alternate and warn if bad */
-		rc = IsGuidPartitionTableValid(hd, dev, pgpt->AlternateLBA,
+		good_agpt= is_gpt_valid(hd, dev, pgpt->AlternateLBA,
 					       &agpt, &aptes);
-		if (!rc){
+		if (!good_agpt){
 			printk(KERN_WARNING "Alternate GPT is invalid, using primary GPT.\n");
 		}
 
@@ -434,48 +547,52 @@ FindValidGPT(struct gendisk *hd, kdev_t 
 		*ptes = pptes;
 		if (agpt)  kfree(agpt);
 		if (aptes) kfree(aptes);
-		return 1;
 	} /* if primary is valid */
 	else {
 		/* Primary GPT is bad, check the Alternate GPT */
-		rc = IsGuidPartitionTableValid(hd, dev, lastlba,
+		good_agpt = is_gpt_valid(hd, dev, lastlba,
 					       &agpt, &aptes);
-		if (rc) {
+		if (good_agpt) {
 			/* Primary is bad, alternate is good.
 			   Return values from the alternate and warn.
 			*/
 			printk(KERN_WARNING "Primary GPT is invalid, using alternate GPT.\n");
 			*gpt = agpt;
 			*ptes = aptes;
-			return 1;
 		}
-		else {
-			/* Primary is bad, alternate is bad, try "other"
-			 * alternate.  This is necessary because if we
-			 * have an odd-sized disk, user-space might
-			 * have put the alternate in block lastlba-1.
-			 */
-			if (!(lastlba & 1)) {
-				lastlba--;
-				rc = IsGuidPartitionTableValid(hd, dev,
-							       lastlba,
-							       &agpt, &aptes);
-				if (rc) {
-					/* Primary is bad, alternate is good.
-					 * Return values from the alternate
-					 * and warn.
-					 */
-					printk("Primary GPT is invalid, using alternate GPT.\n");
-					*gpt = agpt;
-					*ptes = aptes;
-					return 1;
 				}
+
+        /* Now test for valid PMBR */
+        /* This will be added to the EFI Spec. per Intel after v1.02. */
+        if (good_pgpt || good_agpt) {
+                legacyMbr = kmalloc(sizeof(*legacyMbr), GFP_KERNEL);
+                if (legacyMbr) {
+                        memset(legacyMbr, 0, sizeof(*legacyMbr));
+                        read_lba(hd, dev, 0, (u8 *)legacyMbr, sizeof(*legacyMbr));
+                        good_pmbr = is_pmbr_valid(legacyMbr);
+                        kfree(legacyMbr);
+                }
+                if (good_pmbr) return 1;
+                if (!forcegpt) {
+                        printk(" Warning: Disk has a valid GPT signature but invalid PMBR.\n");
+                        printk(KERN_WARNING "  Assuming this disk is *not* a GPT disk anymore.\n");
+                        printk(KERN_WARNING "  Use gpt kernel option to override.  Use GNU Parted to correct disk.\n");
 			}
+                else {
+                        printk(KERN_WARNING "  Warning: Disk has a valid GPT signature but invalid PMBR.\n");
+                        printk(KERN_WARNING "  Use GNU Parted to correct disk.\n");
+                        printk(KERN_WARNING "  gpt option taken, disk treated as GPT.\n");
+                        return 1;
 		}
 	}
-	/* Both primary and alternate GPTs are bad.
+
+	/* Both primary and alternate GPTs are bad, and/or PMBR is invalid.
 	 * This isn't our disk, return 0.
 	 */
+        if (pgpt) {kfree(pgpt); pgpt = NULL;}
+        if (agpt) {kfree(agpt); agpt = NULL;}
+        if (pptes) {kfree(pptes); pptes = NULL;}
+        if (aptes) {kfree(aptes); aptes = NULL;}
 	return 0;
 }
 
@@ -531,7 +648,7 @@ add_gpt_partitions(struct gendisk *hd, k
 
 	if (!hd) return -1;
 
-	if (!FindValidGPT(hd, dev, &gpt, &ptes) ||
+	if (!find_valid_gpt(hd, dev, &gpt, &ptes) ||
 	    !gpt || !ptes) {
 		if (gpt) kfree(gpt);
 		if (ptes) kfree(ptes);
@@ -578,7 +695,7 @@ add_gpt_partitions(struct gendisk *hd, k
  * efi_partition()
  *
  * If the first block on the disk is a legacy MBR,
- * it got handled already by msdos_partition().
+ * it will get handled by msdos_partition().
  * If it's a Protective MBR, we'll handle it here.
  *
  * Returns:
