diff mbox series

[v4,1/7] smbios: Refactor 32-bit code into an else statement

Message ID 20231227074025.2178825-2-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
In preparation for adding support for SMBIOS3 move this code into an
else statement. There is no functional change.

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

(no changes since v1)

 lib/smbios.c | 38 +++++++++++++++++++++-----------------
 1 file changed, 21 insertions(+), 17 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:
>
> In preparation for adding support for SMBIOS3 move this code into an
> else statement. There is no functional change.
>
> Signed-off-by: Simon Glass <sjg@chromium.org>
> Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
> ---
>
> (no changes since v1)
>
>  lib/smbios.c | 38 +++++++++++++++++++++-----------------
>  1 file changed, 21 insertions(+), 17 deletions(-)
>
> diff --git a/lib/smbios.c b/lib/smbios.c
> index 45480b01af4..b417f8a9057 100644
> --- a/lib/smbios.c
> +++ b/lib/smbios.c
> @@ -589,14 +589,6 @@ ulong write_smbios_table(ulong addr)
>                 len += tmp;
>         }
>
> -       memcpy(se->anchor, "_SM_", 4);
> -       se->length = sizeof(struct smbios_entry);
> -       se->major_ver = SMBIOS_MAJOR_VER;
> -       se->minor_ver = SMBIOS_MINOR_VER;
> -       se->max_struct_size = max_struct_size;
> -       memcpy(se->intermediate_anchor, "_DMI_", 5);
> -       se->struct_table_length = len;
> -
>         /*
>          * We must use a pointer here so things work correctly on sandbox. The
>          * user of this table is not aware of the mapping of addresses to
> @@ -612,16 +604,28 @@ ulong write_smbios_table(ulong addr)
>                        (unsigned long long)table_addr);
>                 addr = 0;
>                 goto out;
> +       } else {
> +               memcpy(se->anchor, "_SM_", 4);
> +               se->length = sizeof(struct smbios_entry);
> +               se->major_ver = SMBIOS_MAJOR_VER;
> +               se->minor_ver = SMBIOS_MINOR_VER;
> +               se->max_struct_size = max_struct_size;
> +               memcpy(se->intermediate_anchor, "_DMI_", 5);
> +               se->struct_table_length = len;
> +
> +               se->struct_table_address = table_addr;
> +
> +               se->struct_count = handle;
> +
> +               /* calculate checksums */
> +               istart = (char *)se + SMBIOS_INTERMEDIATE_OFFSET;
> +               isize = sizeof(struct smbios_entry) -
> +                       SMBIOS_INTERMEDIATE_OFFSET;
> +               se->intermediate_checksum = table_compute_checksum(istart,
> +                                                                  isize);
> +               se->checksum = table_compute_checksum(se,
> +                                             sizeof(struct smbios_entry));
>         }
> -       se->struct_table_address = table_addr;
> -
> -       se->struct_count = handle;
> -
> -       /* calculate checksums */
> -       istart = (char *)se + SMBIOS_INTERMEDIATE_OFFSET;
> -       isize = sizeof(struct smbios_entry) - SMBIOS_INTERMEDIATE_OFFSET;
> -       se->intermediate_checksum = table_compute_checksum(istart, isize);
> -       se->checksum = table_compute_checksum(se, sizeof(struct smbios_entry));
>  out:
>         unmap_sysmem(se);
>
> --
> 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 45480b01af4..b417f8a9057 100644
--- a/lib/smbios.c
+++ b/lib/smbios.c
@@ -589,14 +589,6 @@  ulong write_smbios_table(ulong addr)
 		len += tmp;
 	}
 
-	memcpy(se->anchor, "_SM_", 4);
-	se->length = sizeof(struct smbios_entry);
-	se->major_ver = SMBIOS_MAJOR_VER;
-	se->minor_ver = SMBIOS_MINOR_VER;
-	se->max_struct_size = max_struct_size;
-	memcpy(se->intermediate_anchor, "_DMI_", 5);
-	se->struct_table_length = len;
-
 	/*
 	 * We must use a pointer here so things work correctly on sandbox. The
 	 * user of this table is not aware of the mapping of addresses to
@@ -612,16 +604,28 @@  ulong write_smbios_table(ulong addr)
 		       (unsigned long long)table_addr);
 		addr = 0;
 		goto out;
+	} else {
+		memcpy(se->anchor, "_SM_", 4);
+		se->length = sizeof(struct smbios_entry);
+		se->major_ver = SMBIOS_MAJOR_VER;
+		se->minor_ver = SMBIOS_MINOR_VER;
+		se->max_struct_size = max_struct_size;
+		memcpy(se->intermediate_anchor, "_DMI_", 5);
+		se->struct_table_length = len;
+
+		se->struct_table_address = table_addr;
+
+		se->struct_count = handle;
+
+		/* calculate checksums */
+		istart = (char *)se + SMBIOS_INTERMEDIATE_OFFSET;
+		isize = sizeof(struct smbios_entry) -
+			SMBIOS_INTERMEDIATE_OFFSET;
+		se->intermediate_checksum = table_compute_checksum(istart,
+								   isize);
+		se->checksum = table_compute_checksum(se,
+					      sizeof(struct smbios_entry));
 	}
-	se->struct_table_address = table_addr;
-
-	se->struct_count = handle;
-
-	/* calculate checksums */
-	istart = (char *)se + SMBIOS_INTERMEDIATE_OFFSET;
-	isize = sizeof(struct smbios_entry) - SMBIOS_INTERMEDIATE_OFFSET;
-	se->intermediate_checksum = table_compute_checksum(istart, isize);
-	se->checksum = table_compute_checksum(se, sizeof(struct smbios_entry));
 out:
 	unmap_sysmem(se);