Skip to contentSkip to conversation

cxgb3: remove VLA usage

PATCH Applied Gustavo A. R. Silva 2 participants 2 messages Mar 7, 2018

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

PATCH v2 1/1 cxgb3: remove VLA usage

Remove VLA usage and change the 'len' argument to a u8 and use a 256 byte buffer on the stack. Notice that these lengths are limited by the encoding field in the VPD structure, which is a u8 [1].

[1] https://marc.info/?l=linux-netdev&m=152044354814024&w=2

---
Changes in v2:
- Update the code as suggested by David Miller.
- Update changelog based on David's comments.
- Update subject.

 drivers/net/ethernet/chelsio/cxgb3/t3_hw.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/net/ethernet/chelsio/cxgb3/t3_hw.c +4 -4
index a89721f..080918a 100644
@@ -681,18 +681,18 @@ int t3_seeprom_wp(struct adapter *adapter, int enable)
 	return t3_seeprom_write(adapter, EEPROM_STAT_ADDR, enable ? 0xc : 0);
 }
 
-static int vpdstrtouint(char *s, int len, unsigned int base, unsigned int *val)
+static int vpdstrtouint(char *s, u8 len, unsigned int base, unsigned int *val)
 {
-	char tok[len + 1];
+	char tok[256];
 
 	memcpy(tok, s, len);
 	tok[len] = 0;
 	return kstrtouint(strim(tok), base, val);
 }
 
-static int vpdstrtou16(char *s, int len, unsigned int base, u16 *val)
+static int vpdstrtou16(char *s, u8 len, unsigned int base, u16 *val)
 {
-	char tok[len + 1];
+	char tok[256];
 
 	memcpy(tok, s, len);
 	tok[len] = 0;
Signature · 1 line
2.7.4
maintainer Applied
#1 lore raw

From: "Gustavo A. R. Silva" <[email protected]>
Date: Wed, 7 Mar 2018 12:03:33 -0600

Quoted 4 lines

Remove VLA usage and change the 'len' argument to a u8 and use a 256 byte buffer on the stack. Notice that these lengths are limited by the encoding field in the VPD structure, which is a u8 [1].

Quoted 8 lines

[1] https://marc.info/?l=linux-netdev&m=152044354814024&w=2

---
Changes in v2:
- Update the code as suggested by David Miller.
- Update changelog based on David's comments.
- Update subject.

Applied to net-next, thanks.