Skip to contentSkip to conversation

iio: potentiometer: ds1803: remove VLA usage

PATCH In review Gustavo A. R. Silva 2 participants 6 messages Mar 13, 2018 IIO

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 iio: potentiometer: ds1803: remove VLA usage

In preparation to enabling -Wvla, remove VLA. In this particular case use macro ARRAY_SIZE so the length of array _result_ can be computed at preprocessing time.

The use of stack Variable Length Arrays needs to be avoided, as they can be a vector for stack exhaustion, which can be both a runtime bug or a security flaw. Also, in general, as code evolves it is easy to lose track of how big a VLA can get. Thus, we can end up having runtime failures that are hard to debug.

Also, fixed as part of the directive to remove all VLAs from the kernel: https://lkml.org/lkml/2018/3/7/621

---
 drivers/iio/potentiometer/ds1803.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iio/potentiometer/ds1803.c +1 -1
index 9b0ff4a..6bf12c9 100644
@@ -64,7 +64,7 @@ static int ds1803_read_raw(struct iio_dev *indio_dev,
 	struct ds1803_data *data = iio_priv(indio_dev);
 	int pot = chan->channel;
 	int ret;
-	u8 result[indio_dev->num_channels];
+	u8 result[ARRAY_SIZE(ds1803_channels)];
 
 	switch (mask) {
 	case IIO_CHAN_INFO_RAW:
Signature · 1 line
2.7.4
#1 lore raw

Hi Gustavo,

Quoted 10 lines · Gustavo A. R. Silva

In preparation to enabling -Wvla, remove VLA. In this particular case use macro ARRAY_SIZE so the length of array _result_ can be computed at preprocessing time.

The use of stack Variable Length Arrays needs to be avoided, as they can be a vector for stack exhaustion, which can be both a runtime bug or a security flaw. Also, in general, as code evolves it is easy to lose track of how big a VLA can get. Thus, we can end up having runtime failures that are hard to debug.

Quoted 5 lines

Also, fixed as part of the directive to remove all VLAs from the kernel: https://lkml.org/lkml/2018/3/7/621

---

It is already applied as I had sent the patch few days ago.
https://lkml.org/lkml/2018/3/10/164

I specifically CC'ed you and Kees to avoid the patch collisions.

Signature · 2 lines
Thanks
Himanshu Jha
#2 lore raw
Quoted 16 lines · Himanshu Jha

Hi Gustavo,

Quoted 13 lines · Gustavo A. R. Silva

In preparation to enabling -Wvla, remove VLA. In this particular case use macro ARRAY_SIZE so the length of array _result_ can be computed at preprocessing time.

The use of stack Variable Length Arrays needs to be avoided, as they can be a vector for stack exhaustion, which can be both a runtime bug or a security flaw. Also, in general, as code evolves it is easy to lose track of how big a VLA can get. Thus, we can end up having runtime failures that are hard to debug.

Also, fixed as part of the directive to remove all VLAs from the kernel: https://lkml.org/lkml/2018/3/7/621

Quoted 8 lines
Quoted 2 lines

---

It is already applied as I had sent the patch few days ago.
https://lkml.org/lkml/2018/3/10/164

I specifically CC'ed you and Kees to avoid the patch collisions.

I see. Can you please update this spreadsheet:

https://docs.google.com/spreadsheets/d/1OcfyKK8pJ24esYhSEsW4Q2boZE7UTGbYsSEEtFXf7U0/edit

Thanks
--
Gustavo

#3 lore raw
Quoted 25 lines · Gustavo A. R. Silva
Quoted 22 lines · Himanshu Jha

Hi Gustavo,

Quoted 10 lines · Gustavo A. R. Silva

In preparation to enabling -Wvla, remove VLA. In this particular case use macro ARRAY_SIZE so the length of array _result_ can be computed at preprocessing time.

The use of stack Variable Length Arrays needs to be avoided, as they can be a vector for stack exhaustion, which can be both a runtime bug or a security flaw. Also, in general, as code evolves it is easy to lose track of how big a VLA can get. Thus, we can end up having runtime failures that are hard to debug.

Quoted 5 lines

Also, fixed as part of the directive to remove all VLAs from the kernel: https://lkml.org/lkml/2018/3/7/621

---

It is already applied as I had sent the patch few days ago.
https://lkml.org/lkml/2018/3/10/164

Quoted 6 lines
Quoted 2 lines

I specifically CC'ed you and Kees to avoid the patch collisions.

I see. Can you please update this spreadsheet:

https://docs.google.com/spreadsheets/d/1OcfyKK8pJ24esYhSEsW4Q2boZE7UTGbYsSEEtFXf7U0/edit

Updated!

Also,

drivers/iio/humidity/hts221_i2c.c:43:2: warning: ISO C90 forbids variable length array ‘send’ [-Wvla]

This was already removed in recent commit when regmap API was used.

"6217792 iio: humidity: hts221: add regmap API support"

For this I added a short note in the *Notes* column.

Signature · 2 lines
Thanks
Himanshu Jha
#4 lore raw
Quoted 37 lines · Himanshu Jha
Quoted 25 lines · Gustavo A. R. Silva
Quoted 22 lines · Himanshu Jha

Hi Gustavo,

Quoted 10 lines · Gustavo A. R. Silva

In preparation to enabling -Wvla, remove VLA. In this particular case use macro ARRAY_SIZE so the length of array _result_ can be computed at preprocessing time.

The use of stack Variable Length Arrays needs to be avoided, as they can be a vector for stack exhaustion, which can be both a runtime bug or a security flaw. Also, in general, as code evolves it is easy to lose track of how big a VLA can get. Thus, we can end up having runtime failures that are hard to debug.

Quoted 5 lines

Also, fixed as part of the directive to remove all VLAs from the kernel: https://lkml.org/lkml/2018/3/7/621

---

It is already applied as I had sent the patch few days ago.
https://lkml.org/lkml/2018/3/10/164

Quoted 6 lines
Quoted 2 lines

I specifically CC'ed you and Kees to avoid the patch collisions.

I see. Can you please update this spreadsheet:

https://docs.google.com/spreadsheets/d/1OcfyKK8pJ24esYhSEsW4Q2boZE7UTGbYsSEEtFXf7U0/edit

Updated!

Also,

Quoted 9 lines

drivers/iio/humidity/hts221_i2c.c:43:2: warning: ISO C90 forbids variable length array ‘send’ [-Wvla]

This was already removed in recent commit when regmap API was used.

"6217792 iio: humidity: hts221: add regmap API support"

For this I added a short note in the *Notes* column.

Awesome.

Thank you
--
Gustavo

#5 lore raw
In reply to Himanshu Jha
Quoted 37 lines · Himanshu Jha
Quoted 25 lines · Gustavo A. R. Silva
Quoted 22 lines · Himanshu Jha

Hi Gustavo,

Quoted 10 lines · Gustavo A. R. Silva

In preparation to enabling -Wvla, remove VLA. In this particular case use macro ARRAY_SIZE so the length of array _result_ can be computed at preprocessing time.

The use of stack Variable Length Arrays needs to be avoided, as they can be a vector for stack exhaustion, which can be both a runtime bug or a security flaw. Also, in general, as code evolves it is easy to lose track of how big a VLA can get. Thus, we can end up having runtime failures that are hard to debug.

Quoted 5 lines

Also, fixed as part of the directive to remove all VLAs from the kernel: https://lkml.org/lkml/2018/3/7/621

---

It is already applied as I had sent the patch few days ago.
https://lkml.org/lkml/2018/3/10/164

Quoted 6 lines
Quoted 2 lines

I specifically CC'ed you and Kees to avoid the patch collisions.

I see. Can you please update this spreadsheet:

https://docs.google.com/spreadsheets/d/1OcfyKK8pJ24esYhSEsW4Q2boZE7UTGbYsSEEtFXf7U0/edit

Updated!

Also,

Quoted 9 lines

drivers/iio/humidity/hts221_i2c.c:43:2: warning: ISO C90 forbids variable length array ‘send’ [-Wvla]

This was already removed in recent commit when regmap API was used.

"6217792 iio: humidity: hts221: add regmap API support"

For this I added a short note in the *Notes* column.

Awesome.

Thank you
--
Gustavo