Skip to contentSkip to conversation

smbios: Fix warning when building with clang

PATCH In review Tom Rini 3 participants 4 messages Nov 6, 2025 – Nov 18, 2025

lore
Share & tools
lore

Tom Rini

author
#0 lore raw

PATCH 1/1 smbios: Fix warning when building with clang

When building with clang, we see warnings such as:
error: field max_size within 'struct smbios_type7' is less aligned than 'union cache_size_word' and is usually due to 'struct smbios_type7' being packed, which can lead to unaligned accesses [-Werror,-Wunaligned-access]
when building drivers/sysinfo/smbios.c. Resolve this error by packing the unions as well after verifying they are complete (16 or 32 bits).

---
Cc: Ilias Apalodimas <[email protected]>
Cc: Raymond Mao <[email protected]>
Cc: Heinrich Schuchardt <[email protected]>

---
 include/smbios.h | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
include/smbios.h +4 -4
index b5fed57aba21..f2f7483bce5a 100644
@@ -204,7 +204,7 @@ struct __packed smbios_type4 {
 	char eos[SMBIOS_STRUCT_EOS_BYTES];
 };
 
-union cache_config {
+union __packed cache_config {
 	struct {
 		u16 level:3;
 		u16 bsocketed:1;
@@ -217,7 +217,7 @@ union cache_config {
 	u16 data;
 };
 
-union cache_size_word {
+union __packed cache_size_word {
 	struct {
 		u16 size:15;
 		u16 granu:1;
@@ -225,7 +225,7 @@ union cache_size_word {
 	u16 data;
 };
 
-union cache_size_dword {
+union __packed cache_size_dword {
 	struct {
 		u32 size:31;
 		u32 granu:1;
@@ -233,7 +233,7 @@ union cache_size_dword {
 	u32 data;
 };
 
-union cache_sram_type {
+union __packed cache_sram_type {
 	struct {
 		u16 other:1;
 		u16 unknown:1;
Signature · 1 line
2.43.0
Reviewed-by on v1 1/1
#1 lore raw

Hi Tom,

Quoted 8 lines · Tom Rini

When building with clang, we see warnings such as:
error: field max_size within 'struct smbios_type7' is less aligned than 'union cache_size_word' and is usually due to 'struct smbios_type7' being packed, which can lead to unaligned accesses [-Werror,-Wunaligned-access]
when building drivers/sysinfo/smbios.c. Resolve this error by packing the unions as well after verifying they are complete (16 or 32 bits).

Quoted 10 lines

---
Cc: Ilias Apalodimas <[email protected]>
Cc: Raymond Mao <[email protected]>
Cc: Heinrich Schuchardt <[email protected]>

---
 include/smbios.h | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

Raymond

Quoted 44 lines
include/smbios.h +4 -5
index b5fed57aba21..f2f7483bce5a 100644
@@ -204,7 +204,7 @@ struct __packed smbios_type4 {
        char eos[SMBIOS_STRUCT_EOS_BYTES];
 };
 
-union cache_config {
+union __packed cache_config {
        struct {
                u16 level:3;
                u16 bsocketed:1;
@@ -217,7 +217,7 @@ union cache_config {
        u16 data;
 };
 
-union cache_size_word {
+union __packed cache_size_word {
        struct {
                u16 size:15;
                u16 granu:1;
@@ -225,7 +225,7 @@ union cache_size_word {
        u16 data;
 };
 
-union cache_size_dword {
+union __packed cache_size_dword {
        struct {
                u32 size:31;
                u32 granu:1;
@@ -233,7 +233,7 @@ union cache_size_dword {
        u32 data;
 };
 
-union cache_sram_type {
+union __packed cache_sram_type {
        struct {
                u16 other:1;
                u16 unknown:1;
--

2.43.0

Reviewed-by on v1 1/1
#2 lore raw
In reply to Tom Rini
Quoted 10 lines · Tom Rini

When building with clang, we see warnings such as:
error: field max_size within 'struct smbios_type7' is less aligned than 'union cache_size_word' and is usually due to 'struct smbios_type7' being packed, which can lead to unaligned accesses [-Werror,-Wunaligned-access]
when building drivers/sysinfo/smbios.c. Resolve this error by packing the unions as well after verifying they are complete (16 or 32 bits).

Quoted 51 lines

---
Cc: Ilias Apalodimas <[email protected]>
Cc: Raymond Mao <[email protected]>
Cc: Heinrich Schuchardt <[email protected]>

---
 include/smbios.h | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
include/smbios.h +4 -5
index b5fed57aba21..f2f7483bce5a 100644
@@ -204,7 +204,7 @@ struct __packed smbios_type4 {
        char eos[SMBIOS_STRUCT_EOS_BYTES];
 };
 
-union cache_config {
+union __packed cache_config {
        struct {
                u16 level:3;
                u16 bsocketed:1;
@@ -217,7 +217,7 @@ union cache_config {
        u16 data;
 };
 
-union cache_size_word {
+union __packed cache_size_word {
        struct {
                u16 size:15;
                u16 granu:1;
@@ -225,7 +225,7 @@ union cache_size_word {
        u16 data;
 };
 
-union cache_size_dword {
+union __packed cache_size_dword {
        struct {
                u32 size:31;
                u32 granu:1;
@@ -233,7 +233,7 @@ union cache_size_dword {
        u32 data;
 };
 
-union cache_sram_type {
+union __packed cache_sram_type {
        struct {
                u16 other:1;
                u16 unknown:1;
--

2.43.0

author
#3 lore raw
In reply to Tom Rini
Quoted 9 lines · Tom Rini

When building with clang, we see warnings such as:
error: field max_size within 'struct smbios_type7' is less aligned than 'union cache_size_word' and is usually due to 'struct smbios_type7' being packed, which can lead to unaligned accesses [-Werror,-Wunaligned-access]
when building drivers/sysinfo/smbios.c. Resolve this error by packing the unions as well after verifying they are complete (16 or 32 bits).

[...]

Applied to u-boot/master, thanks!

[1/1] smbios: Fix warning when building with clang

      commit: 2d226a735e0e9df2c017259c72cfd569986db480
Signature · 1 line
Tom