From 57f962bb2234c989b21497af3a4f0ea088589cd2 Mon Sep 17 00:00:00 2001
From: linyanly <linyanly.lin@huawei.com>
Date: Fri, 3 Nov 2017 15:53:29 +0800
Subject: [PATCH] backport 'support TPM2.0 in grub2, both legacy and efi'

---
 grub-core/Makefile.am                 |   1 +
 grub-core/Makefile.core.def           |   3 +
 grub-core/boot/i386/pc/boot.S         |  31 ++++
 grub-core/boot/i386/pc/diskboot.S     |  44 ++++++
 grub-core/kern/dl.c                   |   4 +
 grub-core/kern/efi/tpm.c              | 282 ++++++++++++++++++++++++++++++++++
 grub-core/kern/emu/mm.c               |   3 +-
 grub-core/kern/i386/pc/tpm.c          | 144 +++++++++++++++++
 grub-core/kern/tpm.c                  |  19 +++
 grub-core/lib/cmdline.c               |   7 +-
 grub-core/loader/i386/efi/linux.c     |   6 +
 grub-core/loader/i386/linux.c         |   4 +
 grub-core/loader/i386/multiboot_mbi.c |   4 +
 grub-core/loader/i386/pc/linux.c      |   4 +
 grub-core/loader/linux.c              |   2 +
 grub-core/loader/multiboot.c          |   4 +
 grub-core/loader/multiboot_mbi2.c     |   3 +
 grub-core/script/execute.c            |  28 +++-
 include/grub/efi/tpm.h                | 153 ++++++++++++++++++
 include/grub/tpm.h                    |  89 +++++++++++
 20 files changed, 831 insertions(+), 4 deletions(-)
 create mode 100644 grub-core/kern/efi/tpm.c
 create mode 100644 grub-core/kern/i386/pc/tpm.c
 create mode 100644 grub-core/kern/tpm.c
 create mode 100644 include/grub/efi/tpm.h
 create mode 100644 include/grub/tpm.h

diff --git a/grub-core/kern/emu/mm.c b/grub-core/kern/emu/mm.c
index f262e95..43b31fa 100644
--- a/grub-core/kern/emu/mm.c
+++ b/grub-core/kern/emu/mm.c
@@ -50,7 +50,8 @@
 void
 grub_free (void *ptr)
 {
-  free (ptr);
+  if (ptr)
+    free (ptr);
 }
 
 void *
-- 
1.8.3.1
