[LEDE-DEV] [PATCH] kernel: owl-loader: fix EEPROM size validation for 4KiB EEPROMs

Christian Lamparter chunkeey at googlemail.com
Mon Oct 3 06:34:59 PDT 2016


On Monday, October 3, 2016 1:06:18 AM CEST Martin Blumenstingl wrote:
> The validation of the received EEPROM data uses struct firmware's size
> field, which contains the size in bytes. ath9k_platform_data's
> eeprom_data field however is an u16 array with 2048 elements.
> Using a simple sizeof(pdata->eeprom_data) returns the array size (2048
> in our case). 
Not according to ISO/IEC 9899:201x (N1570 C11) 6.5.3.4.2 page 90 [0]:
"The sizeof operator yields the size (in bytes) of its operand, [...]".

so sizeof(pdata->eeprom_data) will return 4096 and not 2048.
(If it does then the compiler is buggy.)

Just take a look at the FIELD_SIZEOF definition [1] you'll see that it
also just uses a single sizeof.
#define FIELD_SIZEOF(t, f) (sizeof(((t*)0)->f))

> The actual maximum size however is 2048 * sizeof(u16), or
> in other words 4096 bytes (the kernel's FIELD_SIZEOF macro does the
> same calculation, but is easier to read).
Yes, sizeof seems to confuse people (Some think it should do sth. like
ARRAY_SIZE for arrays). I'm fine with replacing the magic numbers with
something else. If you want, you can cut the part about 4096 vs 2048
from the commit message and simply state that the patch introduces 
proper names for the limits (and also change the subject).

Regards,
Christian
---

[0] <http://www.open-std.org/jtc1/sc22/WG14/www/docs/n1570.pdf>
[1] <http://lxr.free-electrons.com/source/include/linux/kernel.h#L73>



More information about the Lede-dev mailing list