[PATCH 04/10] mci: turn bool members into bitfield in struct mci

Ahmad Fatoum a.fatoum at pengutronix.de
Tue Jul 30 04:10:50 PDT 2024


On 30.07.24 11:06, Sascha Hauer wrote:
> On Tue, Jul 30, 2024 at 09:19:23AM +0200, Ahmad Fatoum wrote:
>> In preparation for adding more boolean flags, turn the current two bools
>> into two bits sharing the same u8-sized member.
>>
>> Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
>> ---
>>  include/mci.h | 4 ++--
>>  1 file changed, 2 insertions(+), 2 deletions(-)
>>
>> diff --git a/include/mci.h b/include/mci.h
>> index 773aed896c96..4f1ff9dc57c8 100644
>> --- a/include/mci.h
>> +++ b/include/mci.h
>> @@ -568,8 +568,8 @@ struct mci {
>>  	unsigned csd[4];	/**< card's "card specific data register" */
>>  	unsigned cid[4];	/**< card's "card identification register" */
>>  	unsigned short rca;	/**< relative card address */
>> -	bool sdio;              /**< card is a SDIO card */
>> -	bool high_capacity;	/**< high capacity card is connected (OCR -> OCR_HCS) */
>> +	u8 sdio:1;              /**< card is a SDIO card */
>> +	u8 high_capacity:1;	/**< high capacity card is connected (OCR -> OCR_HCS) */
> 
> This doesn't seem to be necessary. They share the same byte in either
> way. From a quick test:

They don't share the same byte, but the size didn't change because of
padding. More members are added into the padding space in subsequent
commits, which would affect structure size.

> 
> struct foo {
> 	u16 a;
> 	bool b;
> 	bool c;
> 	u32 d;
> };
> 
> struct bar {
> 	u16 a;
> 	u8 b:1;
> 	u8 c:1;
> 	u32 d;
> };
> 
> printf("%d %d\n", sizeof(struct foo), sizeof(struct bar));
> 
> The result is 8 for both structs.
> 
> Sascha
> 

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |




More information about the barebox mailing list