diff mbox series

wifi: b43: fix incorrect __packed annotation

Message ID 20230516074554.1674536-1-arnd@kernel.org (mailing list archive)
State Superseded
Delegated to: Netdev Maintainers
Headers show
Series wifi: b43: fix incorrect __packed annotation | expand

Checks

Context Check Description
netdev/tree_selection success Not a local patch

Commit Message

Arnd Bergmann May 16, 2023, 7:45 a.m. UTC
From: Arnd Bergmann <arnd@arndb.de>

clang warns about an unpacked structure inside of a packed one:

drivers/net/wireless/broadcom/b43/b43.h:654:4: error: field data within 'struct b43_iv' is less aligned than 'union (unnamed union at /home/arnd/arm-soc/drivers/net/wireless/broadcom/b43/b43.h:651:2)' and is usually due to 'struct b43_iv' being packed, which can lead to unaligned accesses [-Werror,-Wunaligned-access]

The problem here is that the anonymous union has the default alignment
from its members, apparently because the original author mixed up the
placement of the __packed attribute by placing it next to the struct
member rather than the union definition. As the struct itself is
also marked as __packed, there is no need to mark its members, so just
move the annotation to the inner type instead.

Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
 drivers/net/wireless/broadcom/b43/b43.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Simon Horman May 16, 2023, 11 a.m. UTC | #1
On Tue, May 16, 2023 at 09:45:42AM +0200, Arnd Bergmann wrote:
> From: Arnd Bergmann <arnd@arndb.de>
> 
> clang warns about an unpacked structure inside of a packed one:
> 
> drivers/net/wireless/broadcom/b43/b43.h:654:4: error: field data within 'struct b43_iv' is less aligned than 'union (unnamed union at /home/arnd/arm-soc/drivers/net/wireless/broadcom/b43/b43.h:651:2)' and is usually due to 'struct b43_iv' being packed, which can lead to unaligned accesses [-Werror,-Wunaligned-access]
> 
> The problem here is that the anonymous union has the default alignment
> from its members, apparently because the original author mixed up the
> placement of the __packed attribute by placing it next to the struct
> member rather than the union definition. As the struct itself is
> also marked as __packed, there is no need to mark its members, so just
> move the annotation to the inner type instead.
> 
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>

Reviewed-by: Simon Horman <simon.horman@corigine.com>
Michael Büsch May 16, 2023, 5:12 p.m. UTC | #2
On Tue, 16 May 2023 09:45:42 +0200
Arnd Bergmann <arnd@kernel.org> wrote:

> b43_iv { union {
>  		__be16 d16;
>  		__be32 d32;
> -	} data __packed;
> +	} __packed data;
>  } __packed;
>  
>  

Oh, interesting. This has probably been there forever.
Did you check if the b43legacy driver has the same issue?

Acked-by: Michael Büsch <m@bues.ch>
Arnd Bergmann May 16, 2023, 5:45 p.m. UTC | #3
On Tue, May 16, 2023, at 19:12, Michael Büsch wrote:
> On Tue, 16 May 2023 09:45:42 +0200
> Arnd Bergmann <arnd@kernel.org> wrote:
>
>> b43_iv { union {
>>  		__be16 d16;
>>  		__be32 d32;
>> -	} data __packed;
>> +	} __packed data;
>>  } __packed;
>>  
>>  
>
> Oh, interesting. This has probably been there forever.
> Did you check if the b43legacy driver has the same issue?

I had not checked, but I see that it does have the same bug.

I only sent this one because the build bot (incorrectly)
blamed one of my recent patches for a regression here.
Which reminds me that I was missing:

Reported-by: kernel test robot <lkp@intel.com>
Link: https://lore.kernel.org/oe-kbuild-all/202305160749.ay1HAoyP-lkp@intel.com/

Should I resend this as a combined patch for both drivers?

   Arnd
Michael Büsch May 16, 2023, 5:47 p.m. UTC | #4
On Tue, 16 May 2023 19:45:16 +0200
"Arnd Bergmann" <arnd@arndb.de> wrote:

> Should I resend this as a combined patch for both drivers?

I think that would be fine, yes.
Thank you for checking.
Larry Finger May 16, 2023, 5:53 p.m. UTC | #5
On 5/16/23 02:45, Arnd Bergmann wrote:
> From: Arnd Bergmann <arnd@arndb.de>
> 
> clang warns about an unpacked structure inside of a packed one:
> 
> drivers/net/wireless/broadcom/b43/b43.h:654:4: error: field data within 'struct b43_iv' is less aligned than 'union (unnamed union at /home/arnd/arm-soc/drivers/net/wireless/broadcom/b43/b43.h:651:2)' and is usually due to 'struct b43_iv' being packed, which can lead to unaligned accesses [-Werror,-Wunaligned-access]
> 
> The problem here is that the anonymous union has the default alignment
> from its members, apparently because the original author mixed up the
> placement of the __packed attribute by placing it next to the struct
> member rather than the union definition. As the struct itself is
> also marked as __packed, there is no need to mark its members, so just
> move the annotation to the inner type instead.
> 
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>
> ---
>   drivers/net/wireless/broadcom/b43/b43.h | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/net/wireless/broadcom/b43/b43.h b/drivers/net/wireless/broadcom/b43/b43.h
> index 9fc7c088a539..67b4bac048e5 100644
> --- a/drivers/net/wireless/broadcom/b43/b43.h
> +++ b/drivers/net/wireless/broadcom/b43/b43.h
> @@ -651,7 +651,7 @@ struct b43_iv {
>   	union {
>   		__be16 d16;
>   		__be32 d32;
> -	} data __packed;
> +	} __packed data >   } __packed;

This change works on a BCM4306 and BCM4318=.

Tested-by: Larry Finger <Larry.Finger@lwfinger.net>

To answer Michael's question, b43legacy has the same issue.

Larry


Larry
diff mbox series

Patch

diff --git a/drivers/net/wireless/broadcom/b43/b43.h b/drivers/net/wireless/broadcom/b43/b43.h
index 9fc7c088a539..67b4bac048e5 100644
--- a/drivers/net/wireless/broadcom/b43/b43.h
+++ b/drivers/net/wireless/broadcom/b43/b43.h
@@ -651,7 +651,7 @@  struct b43_iv {
 	union {
 		__be16 d16;
 		__be32 d32;
-	} data __packed;
+	} __packed data;
 } __packed;