public inbox for linux-iio@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH][next] iio: pressure: bmp280-core: Make read-only const array conversion_time_max static
@ 2024-07-22 15:17 Colin Ian King
  2024-07-22 20:01 ` Jonathan Cameron
  0 siblings, 1 reply; 4+ messages in thread
From: Colin Ian King @ 2024-07-22 15:17 UTC (permalink / raw)
  To: Jonathan Cameron, Lars-Peter Clausen, Vasileios Amoiridis,
	linux-iio
  Cc: kernel-janitors, linux-kernel

Don't populate the read-only array conversion_time_max on the stack at
run time, instead make it static.

Signed-off-by: Colin Ian King <colin.i.king@gmail.com>
---
 drivers/iio/pressure/bmp280-core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/iio/pressure/bmp280-core.c b/drivers/iio/pressure/bmp280-core.c
index 49081b729618..9ead52954de3 100644
--- a/drivers/iio/pressure/bmp280-core.c
+++ b/drivers/iio/pressure/bmp280-core.c
@@ -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;
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH][next] iio: pressure: bmp280-core: Make read-only const array conversion_time_max static
  2024-07-22 15:17 [PATCH][next] iio: pressure: bmp280-core: Make read-only const array conversion_time_max static Colin Ian King
@ 2024-07-22 20:01 ` Jonathan Cameron
  2024-07-23 17:04   ` Dan Carpenter
  0 siblings, 1 reply; 4+ messages in thread
From: Jonathan Cameron @ 2024-07-22 20:01 UTC (permalink / raw)
  To: Colin Ian King
  Cc: Lars-Peter Clausen, Vasileios Amoiridis, linux-iio,
	kernel-janitors, linux-kernel

On Mon, 22 Jul 2024 16:17:38 +0100
Colin Ian King <colin.i.king@gmail.com> wrote:

> Don't populate the read-only array conversion_time_max on the stack at
> run time, instead make it static.
> 
> Signed-off-by: Colin Ian King <colin.i.king@gmail.com>

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


> ---
>  drivers/iio/pressure/bmp280-core.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/iio/pressure/bmp280-core.c b/drivers/iio/pressure/bmp280-core.c
> index 49081b729618..9ead52954de3 100644
> --- a/drivers/iio/pressure/bmp280-core.c
> +++ b/drivers/iio/pressure/bmp280-core.c
> @@ -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;


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH][next] iio: pressure: bmp280-core: Make read-only const array conversion_time_max static
  2024-07-22 20:01 ` Jonathan Cameron
@ 2024-07-23 17:04   ` Dan Carpenter
  2024-07-23 17:40     ` Colin King (gmail)
  0 siblings, 1 reply; 4+ messages in thread
From: Dan Carpenter @ 2024-07-23 17:04 UTC (permalink / raw)
  To: Jonathan Cameron
  Cc: Colin Ian King, Lars-Peter Clausen, Vasileios Amoiridis,
	linux-iio, kernel-janitors, linux-kernel

On Mon, Jul 22, 2024 at 09:01:11PM +0100, Jonathan Cameron wrote:
> On Mon, 22 Jul 2024 16:17:38 +0100
> Colin Ian King <colin.i.king@gmail.com> wrote:
> 
> > Don't populate the read-only array conversion_time_max on the stack at
> > run time, instead make it static.
> > 
> > Signed-off-by: Colin Ian King <colin.i.king@gmail.com>
> 
> 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


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH][next] iio: pressure: bmp280-core: Make read-only const array conversion_time_max static
  2024-07-23 17:04   ` Dan Carpenter
@ 2024-07-23 17:40     ` Colin King (gmail)
  0 siblings, 0 replies; 4+ messages in thread
From: Colin King (gmail) @ 2024-07-23 17:40 UTC (permalink / raw)
  To: Dan Carpenter, Jonathan Cameron
  Cc: Lars-Peter Clausen, Vasileios Amoiridis, linux-iio,
	kernel-janitors, linux-kernel

On 23/07/2024 18:04, Dan Carpenter wrote:
> On Mon, Jul 22, 2024 at 09:01:11PM +0100, Jonathan Cameron wrote:
>> On Mon, 22 Jul 2024 16:17:38 +0100
>> Colin Ian King <colin.i.king@gmail.com> wrote:
>>
>>> Don't populate the read-only array conversion_time_max on the stack at
>>> run time, instead make it static.
>>>
>>> Signed-off-by: Colin Ian King <colin.i.king@gmail.com>
>>
>> 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

> 
> regards,
> dan carpenter
> 


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2024-07-23 17:40 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-07-22 15:17 [PATCH][next] iio: pressure: bmp280-core: Make read-only const array conversion_time_max static Colin Ian King
2024-07-22 20:01 ` Jonathan Cameron
2024-07-23 17:04   ` Dan Carpenter
2024-07-23 17:40     ` Colin King (gmail)

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox