Skip to contentSkip to conversation

power: supply: da9150-fg: remove VLA usage

PATCH In review Gustavo A. R. Silva 3 participants 3 messages Mar 9, 2018 – Mar 12, 2018

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

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

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

DA9150_QIF_LONG_SIZE (4 bytes) is the biggest size of an attribute which can be accessed [1].

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

[1] https://marc.info/?l=kernel-hardening&m=152059600524753&w=2

---
Changes in v2:
- Use DA9150_QIF_LONG_SIZE instead of DA9150_QIF_BYTE_SIZE as the maximum size for array 'buf'. Thanks to Adam Thomson for the feedback on this.
- Update changelog based on Adam's comments.

 drivers/power/supply/da9150-fg.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/power/supply/da9150-fg.c +2 -2
index 8b8ce97..7ea2188 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_LONG_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_LONG_SIZE];
 	u8 write_addr;
 	int i;
 
Signature · 1 line
2.7.4
Acked-by on v2 1/1
#1 lore raw
Quoted 6 lines · Gustavo A. R. Silva

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

DA9150_QIF_LONG_SIZE (4 bytes) is the biggest size of an attribute which can be accessed [1].

Quoted 6 lines

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

[1] https://marc.info/?l=kernel-hardening&m=152059600524753&w=2

Quoted 35 lines

---
Changes in v2:
- Use DA9150_QIF_LONG_SIZE instead of DA9150_QIF_BYTE_SIZE as the maximum size for array 'buf'. Thanks to Adam Thomson for the feedback on this.
- Update changelog based on Adam's comments.

 drivers/power/supply/da9150-fg.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/power/supply/da9150-fg.c +2 -3
index 8b8ce97..7ea2188 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_LONG_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_LONG_SIZE];
 	u8 write_addr;
 	int i;
 
--

2.7.4

#2 lore raw
In reply to Gustavo A. R. Silva

Hi,

Quoted 6 lines · Gustavo A. R. Silva

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

DA9150_QIF_LONG_SIZE (4 bytes) is the biggest size of an attribute which can be accessed [1].

Quoted 7 lines

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

[1] https://marc.info/?l=kernel-hardening&m=152059600524753&w=2

---

Thanks, queued to power-supply's for-next branch.

-- Sebastian

Quoted 34 lines

Changes in v2:
- Use DA9150_QIF_LONG_SIZE instead of DA9150_QIF_BYTE_SIZE as the maximum size for array 'buf'. Thanks to Adam Thomson for the feedback on this.
- Update changelog based on Adam's comments.

 drivers/power/supply/da9150-fg.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/power/supply/da9150-fg.c +2 -2
index 8b8ce97..7ea2188 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_LONG_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_LONG_SIZE];
 	u8 write_addr;
 	int i;
 
Signature · 1 line
2.7.4