Re: [PATCH 1/4] rtw88: Add packed attribute to the eFuse structs

From: Martin Blumenstingl
Date: Wed Jan 04 2023 - 12:49:47 EST


On Wed, Jan 4, 2023 at 5:31 PM David Laight <David.Laight@xxxxxxxxxx> wrote:
[...]
> > > What you may want to do is add compile-time asserts for the
> > > sizes of the structures.
> > Do I get you right that something like:
> > BUILD_BUG_ON(sizeof(rtw8821c_efuse) != 256);
> > is what you have in mind?
>
> That looks like the one...
I tried this (see the attached patch - it's just meant to show what I
did, it's not meant to be applied upstream).
With the attached patch but no other patches this makes the rtw88
driver compile fine on 6.2-rc2.

Adding __packed to struct rtw8723d_efuse changes the size of that
struct for me (I'm compiling for AArch64 / ARM64).
With the packed attribute it has 267 bytes, without 268 bytes.

Do you have any ideas as to why that is?


Best regards,
Martin
diff --git a/drivers/net/wireless/realtek/rtw88/rtw8723d.c b/drivers/net/wireless/realtek/rtw88/rtw8723d.c
index 2d2f768bae2e..47392d722f8d 100644
--- a/drivers/net/wireless/realtek/rtw88/rtw8723d.c
+++ b/drivers/net/wireless/realtek/rtw88/rtw8723d.c
@@ -222,6 +222,8 @@ static int rtw8723d_read_efuse(struct rtw_dev *rtwdev, u8 *log_map)
struct rtw8723d_efuse *map;
int i;

+ BUILD_BUG_ON(sizeof(*map) != 268);
+
map = (struct rtw8723d_efuse *)log_map;

efuse->rfe_option = 0;
diff --git a/drivers/net/wireless/realtek/rtw88/rtw8821c.c b/drivers/net/wireless/realtek/rtw88/rtw8821c.c
index 17f800f6efbd..ee0f4a0856d5 100644
--- a/drivers/net/wireless/realtek/rtw88/rtw8821c.c
+++ b/drivers/net/wireless/realtek/rtw88/rtw8821c.c
@@ -45,6 +45,8 @@ static int rtw8821c_read_efuse(struct rtw_dev *rtwdev, u8 *log_map)
struct rtw8821c_efuse *map;
int i;

+ BUILD_BUG_ON(sizeof(*map) != 512);
+
map = (struct rtw8821c_efuse *)log_map;

efuse->rfe_option = map->rfe_option;
diff --git a/drivers/net/wireless/realtek/rtw88/rtw8822b.c b/drivers/net/wireless/realtek/rtw88/rtw8822b.c
index 74dfb89b2c94..0deb02924114 100644
--- a/drivers/net/wireless/realtek/rtw88/rtw8822b.c
+++ b/drivers/net/wireless/realtek/rtw88/rtw8822b.c
@@ -38,6 +38,8 @@ static int rtw8822b_read_efuse(struct rtw_dev *rtwdev, u8 *log_map)
struct rtw8822b_efuse *map;
int i;

+ BUILD_BUG_ON(sizeof(*map) != 512);
+
map = (struct rtw8822b_efuse *)log_map;

efuse->rfe_option = map->rfe_option;
diff --git a/drivers/net/wireless/realtek/rtw88/rtw8822c.c b/drivers/net/wireless/realtek/rtw88/rtw8822c.c
index 964e27887fe2..980c50206c21 100644
--- a/drivers/net/wireless/realtek/rtw88/rtw8822c.c
+++ b/drivers/net/wireless/realtek/rtw88/rtw8822c.c
@@ -41,6 +41,8 @@ static int rtw8822c_read_efuse(struct rtw_dev *rtwdev, u8 *log_map)
struct rtw8822c_efuse *map;
int i;

+ BUILD_BUG_ON(sizeof(*map) != 410);
+
map = (struct rtw8822c_efuse *)log_map;

efuse->rfe_option = map->rfe_option;