diff mbox series

[v4,2/7] smbios: Move the rest of the SMBIOS2 code

Message ID 20231227074025.2178825-3-sjg@chromium.org
State Superseded
Delegated to: Tom Rini
Headers show
Series smbios: Deal with tables beyond 4GB | expand

Commit Message

Simon Glass Dec. 27, 2023, 7:40 a.m. UTC
Move all of this logic into the else clause, since it will not be used
for SMBIOS3

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
---

(no changes since v1)

 lib/smbios.c | 15 +++++++--------
 1 file changed, 7 insertions(+), 8 deletions(-)

Comments

Ilias Apalodimas Dec. 27, 2023, 11:02 a.m. UTC | #1
On Wed, 27 Dec 2023 at 09:40, Simon Glass <sjg@chromium.org> wrote:
>
> Move all of this logic into the else clause, since it will not be used
> for SMBIOS3
>
> Signed-off-by: Simon Glass <sjg@chromium.org>
> Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
> ---
>
> (no changes since v1)
>
>  lib/smbios.c | 15 +++++++--------
>  1 file changed, 7 insertions(+), 8 deletions(-)
>
> diff --git a/lib/smbios.c b/lib/smbios.c
> index b417f8a9057..eea72670bd9 100644
> --- a/lib/smbios.c
> +++ b/lib/smbios.c
> @@ -544,9 +544,8 @@ static struct smbios_write_method smbios_write_funcs[] = {
>  ulong write_smbios_table(ulong addr)
>  {
>         ofnode parent_node = ofnode_null();
> -       struct smbios_entry *se;
> +       ulong table_addr, start_addr;
>         struct smbios_ctx ctx;
> -       ulong table_addr;
>         ulong tables;
>         int len = 0;
>         int max_struct_size = 0;
> @@ -566,9 +565,7 @@ ulong write_smbios_table(ulong addr)
>
>         /* 16 byte align the table address */
>         addr = ALIGN(addr, 16);
> -
> -       se = map_sysmem(addr, sizeof(struct smbios_entry));
> -       memset(se, 0, sizeof(struct smbios_entry));
> +       start_addr = addr;
>
>         addr += sizeof(struct smbios_entry);
>         addr = ALIGN(addr, 16);
> @@ -603,8 +600,11 @@ ulong write_smbios_table(ulong addr)
>                 printf("WARNING: SMBIOS table_address overflow %llx\n",
>                        (unsigned long long)table_addr);
>                 addr = 0;
> -               goto out;
>         } else {
> +               struct smbios_entry *se;
> +
> +               se = map_sysmem(start_addr, sizeof(struct smbios_entry));
> +               memset(se, '\0', sizeof(struct smbios_entry));
>                 memcpy(se->anchor, "_SM_", 4);
>                 se->length = sizeof(struct smbios_entry);
>                 se->major_ver = SMBIOS_MAJOR_VER;
> @@ -625,9 +625,8 @@ ulong write_smbios_table(ulong addr)
>                                                                    isize);
>                 se->checksum = table_compute_checksum(se,
>                                               sizeof(struct smbios_entry));
> +               unmap_sysmem(se);
>         }
> -out:
> -       unmap_sysmem(se);
>
>         return addr;
>  }
> --
> 2.34.1
>

Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
diff mbox series

Patch

diff --git a/lib/smbios.c b/lib/smbios.c
index b417f8a9057..eea72670bd9 100644
--- a/lib/smbios.c
+++ b/lib/smbios.c
@@ -544,9 +544,8 @@  static struct smbios_write_method smbios_write_funcs[] = {
 ulong write_smbios_table(ulong addr)
 {
 	ofnode parent_node = ofnode_null();
-	struct smbios_entry *se;
+	ulong table_addr, start_addr;
 	struct smbios_ctx ctx;
-	ulong table_addr;
 	ulong tables;
 	int len = 0;
 	int max_struct_size = 0;
@@ -566,9 +565,7 @@  ulong write_smbios_table(ulong addr)
 
 	/* 16 byte align the table address */
 	addr = ALIGN(addr, 16);
-
-	se = map_sysmem(addr, sizeof(struct smbios_entry));
-	memset(se, 0, sizeof(struct smbios_entry));
+	start_addr = addr;
 
 	addr += sizeof(struct smbios_entry);
 	addr = ALIGN(addr, 16);
@@ -603,8 +600,11 @@  ulong write_smbios_table(ulong addr)
 		printf("WARNING: SMBIOS table_address overflow %llx\n",
 		       (unsigned long long)table_addr);
 		addr = 0;
-		goto out;
 	} else {
+		struct smbios_entry *se;
+
+		se = map_sysmem(start_addr, sizeof(struct smbios_entry));
+		memset(se, '\0', sizeof(struct smbios_entry));
 		memcpy(se->anchor, "_SM_", 4);
 		se->length = sizeof(struct smbios_entry);
 		se->major_ver = SMBIOS_MAJOR_VER;
@@ -625,9 +625,8 @@  ulong write_smbios_table(ulong addr)
 								   isize);
 		se->checksum = table_compute_checksum(se,
 					      sizeof(struct smbios_entry));
+		unmap_sysmem(se);
 	}
-out:
-	unmap_sysmem(se);
 
 	return addr;
 }