diff mbox series

[05/32] x86: Allow writing tables to fail

Message ID 20200928042611.1696178-4-sjg@chromium.org
State Superseded
Delegated to: Bin Meng
Headers show
Series x86: Allow Coral to boot into Chrome OS | expand

Commit Message

Simon Glass Sept. 28, 2020, 4:25 a.m. UTC
At present write_tables() can fail but does not report this problem to its
caller. Fix this by changing the return type.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 arch/x86/cpu/cpu.c            | 7 ++++++-
 arch/x86/include/asm/tables.h | 4 +++-
 arch/x86/lib/tables.c         | 5 ++++-
 3 files changed, 13 insertions(+), 3 deletions(-)

Comments

Heinrich Schuchardt Sept. 28, 2020, 6:23 a.m. UTC | #1
Am 28. September 2020 06:25:44 MESZ schrieb Simon Glass <sjg@chromium.org>:
>At present write_tables() can fail but does not report this problem to
>its
>caller. Fix this by changing the return type.
>
>Signed-off-by: Simon Glass <sjg@chromium.org>
>---
>
> arch/x86/cpu/cpu.c            | 7 ++++++-
> arch/x86/include/asm/tables.h | 4 +++-
> arch/x86/lib/tables.c         | 5 ++++-
> 3 files changed, 13 insertions(+), 3 deletions(-)
>
>diff --git a/arch/x86/cpu/cpu.c b/arch/x86/cpu/cpu.c
>index f8692753963..5c33f02f034 100644
>--- a/arch/x86/cpu/cpu.c
>+++ b/arch/x86/cpu/cpu.c
>@@ -200,6 +200,7 @@ __weak void board_final_cleanup(void)
> int last_stage_init(void)
> {
> 	struct acpi_fadt __maybe_unused *fadt;
>+	int ret;
> 
> 	board_final_init();
> 
>@@ -210,7 +211,11 @@ int last_stage_init(void)
> 			acpi_resume(fadt);
> 	}
> 
>-	write_tables();
>+	ret = write_tables();
>+	if (ret) {
>+		printf("Failed to write tables\n");
>+		return log_msg_ret("table", ret);
>+	}

If we have print available, shouldn't we also have log?

> 
> 	if (IS_ENABLED(CONFIG_GENERATE_ACPI_TABLE)) {
> 		fadt = acpi_find_fadt();
>diff --git a/arch/x86/include/asm/tables.h
>b/arch/x86/include/asm/tables.h
>index f7c72ed3db0..bf66e79018e 100644
>--- a/arch/x86/include/asm/tables.h
>+++ b/arch/x86/include/asm/tables.h
>@@ -49,8 +49,10 @@ void table_fill_string(char *dest, const char *src,
>size_t n, char pad);
>  * This writes x86 configuration tables, including PIRQ routing table,
>  * Multi-Processor table and ACPI table. Whether a specific type of
>  * configuration table is written is controlled by a Kconfig option.
>+ *
>+ * @return 0 if OK, -ENOSPC if table too large
>  */
>-void write_tables(void);
>+int write_tables(void);
> 
> /**
>  * write_pirq_routing_table() - Write PIRQ routing table
>diff --git a/arch/x86/lib/tables.c b/arch/x86/lib/tables.c
>index 7bad5dd3032..7099866a78a 100644
>--- a/arch/x86/lib/tables.c
>+++ b/arch/x86/lib/tables.c
>@@ -64,7 +64,7 @@ void table_fill_string(char *dest, const char *src,
>size_t n, char pad)
> 		dest[i] = pad;
> }
> 
>-void write_tables(void)
>+int write_tables(void)
> {
> 	u32 rom_table_start = ROM_TABLE_ADDR;
> 	u32 rom_table_end;
>@@ -91,6 +91,7 @@ void write_tables(void)
> 			cfg_tables[i].size = table_size;
> 		} else {
> 			printf("%d: no memory for configuration tables\n", i);
>+			return -ENOSPC;
> 		}
> #endif
> 
>@@ -105,4 +106,6 @@ void write_tables(void)
> 	write_coreboot_table(CB_TABLE_ADDR, cfg_tables);
> #endif
> 	debug("- done writing tables\n");
>+
>+	return 0;
> }
Bin Meng Oct. 16, 2020, 9:55 a.m. UTC | #2
On Mon, Sep 28, 2020 at 12:26 PM Simon Glass <sjg@chromium.org> wrote:
>
> At present write_tables() can fail but does not report this problem to its
> caller. Fix this by changing the return type.
>
> Signed-off-by: Simon Glass <sjg@chromium.org>
> ---
>
>  arch/x86/cpu/cpu.c            | 7 ++++++-
>  arch/x86/include/asm/tables.h | 4 +++-
>  arch/x86/lib/tables.c         | 5 ++++-
>  3 files changed, 13 insertions(+), 3 deletions(-)
>

Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
diff mbox series

Patch

diff --git a/arch/x86/cpu/cpu.c b/arch/x86/cpu/cpu.c
index f8692753963..5c33f02f034 100644
--- a/arch/x86/cpu/cpu.c
+++ b/arch/x86/cpu/cpu.c
@@ -200,6 +200,7 @@  __weak void board_final_cleanup(void)
 int last_stage_init(void)
 {
 	struct acpi_fadt __maybe_unused *fadt;
+	int ret;
 
 	board_final_init();
 
@@ -210,7 +211,11 @@  int last_stage_init(void)
 			acpi_resume(fadt);
 	}
 
-	write_tables();
+	ret = write_tables();
+	if (ret) {
+		printf("Failed to write tables\n");
+		return log_msg_ret("table", ret);
+	}
 
 	if (IS_ENABLED(CONFIG_GENERATE_ACPI_TABLE)) {
 		fadt = acpi_find_fadt();
diff --git a/arch/x86/include/asm/tables.h b/arch/x86/include/asm/tables.h
index f7c72ed3db0..bf66e79018e 100644
--- a/arch/x86/include/asm/tables.h
+++ b/arch/x86/include/asm/tables.h
@@ -49,8 +49,10 @@  void table_fill_string(char *dest, const char *src, size_t n, char pad);
  * This writes x86 configuration tables, including PIRQ routing table,
  * Multi-Processor table and ACPI table. Whether a specific type of
  * configuration table is written is controlled by a Kconfig option.
+ *
+ * @return 0 if OK, -ENOSPC if table too large
  */
-void write_tables(void);
+int write_tables(void);
 
 /**
  * write_pirq_routing_table() - Write PIRQ routing table
diff --git a/arch/x86/lib/tables.c b/arch/x86/lib/tables.c
index 7bad5dd3032..7099866a78a 100644
--- a/arch/x86/lib/tables.c
+++ b/arch/x86/lib/tables.c
@@ -64,7 +64,7 @@  void table_fill_string(char *dest, const char *src, size_t n, char pad)
 		dest[i] = pad;
 }
 
-void write_tables(void)
+int write_tables(void)
 {
 	u32 rom_table_start = ROM_TABLE_ADDR;
 	u32 rom_table_end;
@@ -91,6 +91,7 @@  void write_tables(void)
 			cfg_tables[i].size = table_size;
 		} else {
 			printf("%d: no memory for configuration tables\n", i);
+			return -ENOSPC;
 		}
 #endif
 
@@ -105,4 +106,6 @@  void write_tables(void)
 	write_coreboot_table(CB_TABLE_ADDR, cfg_tables);
 #endif
 	debug("- done writing tables\n");
+
+	return 0;
 }