Blame SOURCES/0229-Make-grub_error-more-verbose.patch

d9d99f
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
d9d99f
From: Peter Jones <pjones@redhat.com>
d9d99f
Date: Mon, 27 Aug 2018 13:14:06 -0400
d9d99f
Subject: [PATCH] Make grub_error() more verbose
d9d99f
d9d99f
Signed-off-by: Peter Jones <pjones@redhat.com>
d9d99f
---
d9d99f
 grub-core/kern/efi/mm.c | 17 ++++++++++++++---
d9d99f
 grub-core/kern/err.c    | 13 +++++++++++--
d9d99f
 include/grub/err.h      |  5 ++++-
d9d99f
 3 files changed, 29 insertions(+), 6 deletions(-)
d9d99f
d9d99f
diff --git a/grub-core/kern/efi/mm.c b/grub-core/kern/efi/mm.c
d9d99f
index 5cdf6c943f2..7692e63ba24 100644
d9d99f
--- a/grub-core/kern/efi/mm.c
d9d99f
+++ b/grub-core/kern/efi/mm.c
d9d99f
@@ -157,12 +157,20 @@ grub_efi_allocate_pages_real (grub_efi_physical_address_t address,
d9d99f
 
d9d99f
   /* Limit the memory access to less than 4GB for 32-bit platforms.  */
d9d99f
   if (address > GRUB_EFI_MAX_USABLE_ADDRESS)
d9d99f
-    return 0;
d9d99f
+    {
d9d99f
+      grub_error (GRUB_ERR_BAD_ARGUMENT,
d9d99f
+		  N_("invalid memory address (0x%llx > 0x%llx)"),
d9d99f
+		  address, GRUB_EFI_MAX_USABLE_ADDRESS);
d9d99f
+      return NULL;
d9d99f
+    }
d9d99f
 
d9d99f
   b = grub_efi_system_table->boot_services;
d9d99f
   status = efi_call_4 (b->allocate_pages, alloctype, memtype, pages, &address);
d9d99f
   if (status != GRUB_EFI_SUCCESS)
d9d99f
-    return 0;
d9d99f
+    {
d9d99f
+      grub_error (GRUB_ERR_OUT_OF_MEMORY, N_("out of memory"));
d9d99f
+      return NULL;
d9d99f
+    }
d9d99f
 
d9d99f
   if (address == 0)
d9d99f
     {
d9d99f
@@ -172,7 +180,10 @@ grub_efi_allocate_pages_real (grub_efi_physical_address_t address,
d9d99f
       status = efi_call_4 (b->allocate_pages, alloctype, memtype, pages, &address);
d9d99f
       grub_efi_free_pages (0, pages);
d9d99f
       if (status != GRUB_EFI_SUCCESS)
d9d99f
-	return 0;
d9d99f
+	{
d9d99f
+	  grub_error (GRUB_ERR_OUT_OF_MEMORY, N_("out of memory"));
d9d99f
+	  return NULL;
d9d99f
+	}
d9d99f
     }
d9d99f
 
d9d99f
   grub_efi_store_alloc (address, pages);
d9d99f
diff --git a/grub-core/kern/err.c b/grub-core/kern/err.c
d9d99f
index 53c734de70e..aebfe0cf839 100644
d9d99f
--- a/grub-core/kern/err.c
d9d99f
+++ b/grub-core/kern/err.c
d9d99f
@@ -33,15 +33,24 @@ static struct grub_error_saved grub_error_stack_items[GRUB_ERROR_STACK_SIZE];
d9d99f
 static int grub_error_stack_pos;
d9d99f
 static int grub_error_stack_assert;
d9d99f
 
d9d99f
+#ifdef grub_error
d9d99f
+#undef grub_error
d9d99f
+#endif
d9d99f
+
d9d99f
 grub_err_t
d9d99f
-grub_error (grub_err_t n, const char *fmt, ...)
d9d99f
+grub_error (grub_err_t n, const char *file, const int line, const char *fmt, ...)
d9d99f
 {
d9d99f
   va_list ap;
d9d99f
+  int m;
d9d99f
 
d9d99f
   grub_errno = n;
d9d99f
 
d9d99f
+  m = grub_snprintf (grub_errmsg, sizeof (grub_errmsg), "%s:%d:", file, line);
d9d99f
+  if (m < 0)
d9d99f
+    m = 0;
d9d99f
+
d9d99f
   va_start (ap, fmt);
d9d99f
-  grub_vsnprintf (grub_errmsg, sizeof (grub_errmsg), _(fmt), ap);
d9d99f
+  grub_vsnprintf (grub_errmsg + m, sizeof (grub_errmsg) - m, _(fmt), ap);
d9d99f
   va_end (ap);
d9d99f
 
d9d99f
   return n;
d9d99f
diff --git a/include/grub/err.h b/include/grub/err.h
d9d99f
index 1590c688e1d..9b830757d35 100644
d9d99f
--- a/include/grub/err.h
d9d99f
+++ b/include/grub/err.h
d9d99f
@@ -84,7 +84,10 @@ struct grub_error_saved
d9d99f
 extern grub_err_t EXPORT_VAR(grub_errno);
d9d99f
 extern char EXPORT_VAR(grub_errmsg)[GRUB_MAX_ERRMSG];
d9d99f
 
d9d99f
-grub_err_t EXPORT_FUNC(grub_error) (grub_err_t n, const char *fmt, ...);
d9d99f
+grub_err_t EXPORT_FUNC(grub_error) (grub_err_t n, const char *file, const int line, const char *fmt, ...);
d9d99f
+
d9d99f
+#define grub_error(n, fmt, ...) grub_error (n, __FILE__, __LINE__, fmt, ##__VA_ARGS__)
d9d99f
+
d9d99f
 void EXPORT_FUNC(grub_fatal) (const char *fmt, ...) __attribute__ ((noreturn));
d9d99f
 void EXPORT_FUNC(grub_error_push) (void);
d9d99f
 int EXPORT_FUNC(grub_error_pop) (void);