iio: pressure: bmp280-core: Make read-only const array conversion_time_max static
Subsystems (2)
PATCH 1/1 iio: pressure: bmp280-core: Make read-only const array conversion_time_max static
Don't populate the read-only array conversion_time_max on the stack at run time, instead make it static.
--- drivers/iio/pressure/bmp280-core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iio/pressure/bmp280-core.c +1 -1
@@ -1865,7 +1865,7 @@ EXPORT_SYMBOL_NS(bmp580_chip_info, IIO_BMP280);static int bmp180_wait_for_eoc (struct bmp280_data *data,u8 ctrl_meas) { -const int conversion_time_max[] = {4500 ,7500 ,13500 ,25500 }; +static const int conversion_time_max[] = {4500 ,7500 ,13500 ,25500 };unsigned int delay_us;unsigned int ctrl;int ret;
Signature · 1 line
2.39.2
Jonathan Cameron
maintainerQuoted 4 lines · On Mon, 22 Jul 2024 16:17:38 +0100 Colin Ian King <[email protected]>…
Don't populate the read-only array
conversion_time_maxon the stack at run time, instead make it static.Signed-off-by Colin Ian King <[email protected]>
I'm almost 100% the compiler can hoist this off the stack if it feels like it but sure, it might not and adding the static keyword probably obliges it to do so. Is that better or worse? Probably better.
Ah well, I don't feel strongly and it's probably a good thing.
Applied to the testing branch of iio.git for now. I'll rebase on rc1 once available.
Thanks,
Jonathan
Quoted 17 lines
--- drivers/iio/pressure/bmp280-core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/iio/pressure/bmp280-core.c +1
-1@@ -1865,7 +1865,7 @@ EXPORT_SYMBOL_NS(bmp580_chip_info, IIO_BMP280);static int bmp180_wait_for_eoc (struct bmp280_data *data,u8 ctrl_meas) { -const int conversion_time_max[] = {4500 ,7500 ,13500 ,25500 }; +static const int conversion_time_max[] = {4500 ,7500 ,13500 ,25500 };unsigned int delay_us;unsigned int ctrl;int ret;
Quoted 11 lines · Jonathan Cameron
Quoted 4 lines · On Mon, 22 Jul 2024 16:17:38 +0100 Colin Ian King <[email protected]>…
Don't populate the read-only array
conversion_time_maxon the stack at run time, instead make it static.Signed-off-by Colin Ian King <[email protected]>I'm almost 100% the compiler can hoist this off the stack if it feels like it but sure, it might not and adding the static keyword probably obliges it to do so.
You would wish the compiler would do this correctly, but it doesn't. (Or it didn't the last time anyone checked).
regards,
dan carpenter
Quoted 7 lines · Dan Carpenter
Quoted 6 lines · Jonathan Cameron
Quoted 3 lines · On Mon, 22 Jul 2024 16:17:38 +0100 Colin Ian King <[email protected]>…
Don't populate the read-only array
conversion_time_maxon the stack at run time, instead make it static.
Quoted 8 lines
Quoted 5 lines
Quoted 1 line
Signed-off-by Colin Ian King <[email protected]>I'm almost 100% the compiler can hoist this off the stack if it feels like it but sure, it might not and adding the static keyword probably obliges it to do so.
You would wish the compiler would do this correctly, but it doesn't. (Or it didn't the last time anyone checked).
From what I understand, a const variable that's not static is either put in register or on the stack since it's implicitly an auto variable, hence it's populated with the initialization data at run time. Making it static will populate it at compile time. Assuming anything else is problematic.
Colin
Quoted 4 lines
regards,
dan carpenter