Skip to contentSkip to conversation

Remove Variable Length Arrays from powerpc code

PATCH In review Suraj Jitindar Singh 3 participants 6 messages Sep 5, 2018 – Sep 20, 2018 PowerPC

lore
Share & tools
lore
#0 lore raw

cover Remove Variable Length Arrays from powerpc code

This patch series removes two Variable Length Arrays (VLAs) from the powerpc code.

Series based on v4.19-rc2

Suraj Jitindar Singh (2):
powerpc/prom: Remove VLA in prom_check_platform_support() powerpc/pseries: Remove VLA from lparcfg_write()

 arch/powerpc/kernel/prom_init.c          | 7 +++++--
 arch/powerpc/platforms/pseries/lparcfg.c | 5 ++---
 2 files changed, 7 insertions(+), 5 deletions(-)
Signature · 1 line
2.13.6
#1 lore raw

PATCH 1/2 powerpc/prom: Remove VLA in prom_check_platform_support()

In prom_check_platform_support() we retrieve and parse the "ibm,arch-vec-5-platform-support" property of the chosen node. Currently we use a variable length array however to avoid this use an array of constant length 8.

This property is used to indicate the supported options of vector 5 bytes 23-26 of the ibm,architecture.vec node. Each of these options is a pair of bytes, thus for 4 options we have a max length of 8 bytes.

---
 arch/powerpc/kernel/prom_init.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
arch/powerpc/kernel/prom_init.c +5 -2
index 9b38a2e5dd35..ce5fc03dc69f 100644
@@ -1131,12 +1131,15 @@ static void __init prom_check_platform_support(void)
 				       "ibm,arch-vec-5-platform-support");
 	if (prop_len > 1) {
 		int i;
-		u8 vec[prop_len];
+		u8 vec[8];
 		prom_debug("Found ibm,arch-vec-5-platform-support, len: %d\n",
 			   prop_len);
+		if (prop_len > sizeof(vec))
+			prom_printf("WARNING: ibm,arch-vec-5-platform-support longer "\
+				    " than expected (len: %d)\n", prop_len);
 		prom_getprop(prom.chosen, "ibm,arch-vec-5-platform-support",
 			     &vec, sizeof(vec));
-		for (i = 0; i < prop_len; i += 2) {
+		for (i = 0; i < sizeof(vec); i += 2) {
 			prom_debug("%d: index = 0x%x val = 0x%x\n", i / 2
 								  , vec[i]
 								  , vec[i + 1]);
Signature · 1 line
2.13.6
Reviewed-by on v1 1/2
#2 lore raw

Re: [PATCH 1/2] powerpc/prom: Remove VLA in prom_check_platform_support()

Quoted 11 lines · Suraj Jitindar Singh

In prom_check_platform_support() we retrieve and parse the "ibm,arch-vec-5-platform-support" property of the chosen node. Currently we use a variable length array however to avoid this use an array of constant length 8.

This property is used to indicate the supported options of vector 5 bytes 23-26 of the ibm,architecture.vec node. Each of these options is a pair of bytes, thus for 4 options we have a max length of 8 bytes.

#3 lore raw

Re: [1/2] powerpc/prom: Remove VLA in prom_check_platform_support()

In reply to Suraj Jitindar Singh
Quoted 11 lines · Suraj Jitindar Singh

In prom_check_platform_support() we retrieve and parse the "ibm,arch-vec-5-platform-support" property of the chosen node. Currently we use a variable length array however to avoid this use an array of constant length 8.

This property is used to indicate the supported options of vector 5 bytes 23-26 of the ibm,architecture.vec node. Each of these options is a pair of bytes, thus for 4 options we have a max length of 8 bytes.

Series applied to powerpc next, thanks.

https://git.kernel.org/powerpc/c/ab91239942a900e209f72488627306

cheers

#4 lore raw

PATCH 2/2 powerpc/pseries: Remove VLA from lparcfg_write()

In reply to Suraj Jitindar Singh

In lparcfg_write we hard code kbuf_sz and then use this as the variable length of kbuf creating a variable length array. Since we're hard coding the length anyway just define the array using this as the length and remove the need for kbuf_sz, thus removing the variable length array.

---
 arch/powerpc/platforms/pseries/lparcfg.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
arch/powerpc/platforms/pseries/lparcfg.c +2 -3
index 7c872dc01bdb..8bd590af488a 100644
@@ -585,8 +585,7 @@ static ssize_t update_mpp(u64 *entitlement, u8 *weight)
 static ssize_t lparcfg_write(struct file *file, const char __user * buf,
 			     size_t count, loff_t * off)
 {
-	int kbuf_sz = 64;
-	char kbuf[kbuf_sz];
+	char kbuf[64];
 	char *tmp;
 	u64 new_entitled, *new_entitled_ptr = &new_entitled;
 	u8 new_weight, *new_weight_ptr = &new_weight;
@@ -595,7 +594,7 @@ static ssize_t lparcfg_write(struct file *file, const char __user * buf,
 	if (!firmware_has_feature(FW_FEATURE_SPLPAR))
 		return -EINVAL;
 
-	if (count > kbuf_sz)
+	if (count > sizeof(kbuf))
 		return -EINVAL;
 
 	if (copy_from_user(kbuf, buf, count))
Signature · 1 line
2.13.6
Reviewed-by on v1 2/2
#5 lore raw

Re: [PATCH 2/2] powerpc/pseries: Remove VLA from lparcfg_write()

Quoted 7 lines · Suraj Jitindar Singh

In lparcfg_write we hard code kbuf_sz and then use this as the variable length of kbuf creating a variable length array. Since we're hard coding the length anyway just define the array using this as the length and remove the need for kbuf_sz, thus removing the variable length array.