Skip to contentSkip to conversation

power: supply: da9150-fg: remove VLA usage

PATCH Superseded Gustavo A. R. Silva 3 participants 3 messages Mar 9, 2018

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 power: supply: da9150-fg: remove VLA usage

In preparation to enabling -Wvla, remove VLA usage and replace it with fixed-length arrays.

It seems that the length of array 'buf' will not exceed DA9150_QIF_SHORT_SIZE bytes (2 bytes). But a fixed length of DA9150_QIF_BYTE_SIZE bytes (8 bytes) was chosen in case this change in the future.

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

---
 drivers/power/supply/da9150-fg.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/power/supply/da9150-fg.c +2 -2
index 8b8ce97..96893be 100644
@@ -92,7 +92,7 @@ struct da9150_fg {
 static u32 da9150_fg_read_attr(struct da9150_fg *fg, u8 code, u8 size)
 
 {
-	u8 buf[size];
+	u8 buf[DA9150_QIF_BYTE_SIZE];
 	u8 read_addr;
 	u32 res = 0;
 	int i;
@@ -111,7 +111,7 @@ static void da9150_fg_write_attr(struct da9150_fg *fg, u8 code, u8 size,
 				 u32 val)
 
 {
-	u8 buf[size];
+	u8 buf[DA9150_QIF_BYTE_SIZE];
 	u8 write_addr;
 	int i;
 
Signature · 1 line
2.7.4
#1 lore raw
Quoted 21 lines · Gustavo A. R. Silva

In preparation to enabling -Wvla, remove VLA usage and replace it with fixed-length arrays.

It seems that the length of array 'buf' will not exceed DA9150_QIF_SHORT_SIZE bytes (2 bytes). But a fixed length of DA9150_QIF_BYTE_SIZE bytes (8 bytes) was chosen in case this change in the future.

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

---
 drivers/power/supply/da9150-fg.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/power/supply/da9150-fg.c +0 -0
index 8b8ce97..96893be 100644

drivers/power/supply/da9150-fg.c struct da9150_fg { · line 95

Quoted 5 lines
drivers/power/supply/da9150-fg.c +1 -1
@@ -92,7 +92,7 @@ struct da9150_fg {
 static u32 da9150_fg_read_attr(struct da9150_fg *fg, u8 code, u8 size)
 
 {
-	u8 buf[size];
+	u8 buf[DA9150_QIF_BYTE_SIZE];

You can use DA9150_QIF_LONG_SIZE as that's the biggest size of an attribute which can be accessed. This will also save a little space.

Quoted 15 lines
drivers/power/supply/da9150-fg.c +1 -2
 	u8 read_addr;
 	u32 res = 0;
 	int i;
@@ -111,7 +111,7 @@ static void da9150_fg_write_attr(struct da9150_fg *fg, u8
 code, u8 size,
 				 u32 val)
 
 {
-	u8 buf[size];
+	u8 buf[DA9150_QIF_BYTE_SIZE];
 	u8 write_addr;
 	int i;
 
--

2.7.4

#2 lore raw
Quoted 25 lines · Adam Thomson
Quoted 23 lines · Gustavo A. R. Silva

In preparation to enabling -Wvla, remove VLA usage and replace it with fixed-length arrays.

It seems that the length of array 'buf' will not exceed DA9150_QIF_SHORT_SIZE bytes (2 bytes). But a fixed length of DA9150_QIF_BYTE_SIZE bytes (8 bytes) was chosen in case this change in the future.

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

---
  drivers/power/supply/da9150-fg.c | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)
drivers/power/supply/da9150-fg.c +0 -0
index 8b8ce97..96893be 100644
@@ -92,7 +92,7 @@ struct da9150_fg {
  static u32 da9150_fg_read_attr(struct da9150_fg *fg, u8 code, u8 size)
 
Quoted 7 lines

drivers/power/supply/da9150-fg.c struct da9150_fg { · line 95

Quoted 3 lines
drivers/power/supply/da9150-fg.c +1 -1
  {
-	u8 buf[size];
+	u8 buf[DA9150_QIF_BYTE_SIZE];

You can use DA9150_QIF_LONG_SIZE as that's the biggest size of an attribute which can be accessed. This will also save a little space.

I got it. I'll send v2 shortly.

Thanks for the feedback, Adam.
--
Gustavo