Skip to contentSkip to conversation

cxgb3: remove VLA

PATCH Superseded Gustavo A. R. Silva 3 participants 3 messages Mar 6, 2018 – Mar 7, 2018

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 cxgb3: remove VLA

In preparation to enabling -Wvla, remove VLA and replace it with dynamic memory allocation.

---
 drivers/net/ethernet/chelsio/cxgb3/t3_hw.c | 25 +++++++++++++++++++++----
 1 file changed, 21 insertions(+), 4 deletions(-)
drivers/net/ethernet/chelsio/cxgb3/t3_hw.c +21 -4
index a89721f..ad6a280 100644
@@ -683,20 +683,37 @@ int t3_seeprom_wp(struct adapter *adapter, int enable)
 
 static int vpdstrtouint(char *s, int len, unsigned int base, unsigned int *val)
 {
-	char tok[len + 1];
+	char *tok;
+	int ret;
+
+	tok = kcalloc(len + 1, sizeof(*tok), GFP_KERNEL);
+	if (!tok)
+		return -ENOMEM;
 
 	memcpy(tok, s, len);
 	tok[len] = 0;
-	return kstrtouint(strim(tok), base, val);
+	ret = kstrtouint(strim(tok), base, val);
+
+	kfree(tok);
+	return ret;
 }
 
 static int vpdstrtou16(char *s, int len, unsigned int base, u16 *val)
 {
-	char tok[len + 1];
+	char *tok;
+	int ret;
+
+	tok = kcalloc(len + 1, sizeof(*tok), GFP_KERNEL);
+	if (!tok)
+		return -ENOMEM;
 
 	memcpy(tok, s, len);
 	tok[len] = 0;
-	return kstrtou16(strim(tok), base, val);
+
+	ret = kstrtou16(strim(tok), base, val);
+
+	kfree(tok);
+	return ret;
 }
 
 /**
Signature · 1 line
2.7.4
maintainer
#1 lore raw

From: "Gustavo A. R. Silva" <[email protected]>
Date: Mon, 5 Mar 2018 23:39:34 -0600

Quoted 4 lines

In preparation to enabling -Wvla, remove VLA and replace it with dynamic memory allocation.

All of these lengths are limited by the encoding of the field in the VPD, which is a u8, and thus 255 bytes.

Please just change the 'len' argument to these functions to a u8 and use a 256 byte buffer on the stack.

Thanks.

#2 lore raw
Quoted 8 lines · David Miller

From: "Gustavo A. R. Silva" <[email protected]>
Date: Mon, 5 Mar 2018 23:39:34 -0600

Quoted 4 lines

In preparation to enabling -Wvla, remove VLA and replace it with dynamic memory allocation.

Quoted 8 lines

All of these lengths are limited by the encoding of the field in the VPD, which is a u8, and thus 255 bytes.

Please just change the 'len' argument to these functions to a u8 and use a 256 byte buffer on the stack.

Thanks.

OK. I got it.

Thanks for the feedback.
--
Gustavo