Remove Variable Length Arrays from powerpc code
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
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
@@ -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
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.
Signed-off-by Suraj Jitindar Singh <[email protected]>
Re: [1/2] powerpc/prom: Remove VLA in prom_check_platform_support()
In reply to Suraj Jitindar SinghQuoted 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.
Signed-off-by Suraj Jitindar Singh <[email protected]>Reviewed-by Joel Stanley <[email protected]>
Series applied to powerpc next, thanks.
https://git.kernel.org/powerpc/c/ab91239942a900e209f72488627306
cheers
PATCH 2/2 powerpc/pseries: Remove VLA from lparcfg_write()
In reply to Suraj Jitindar SinghIn 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
@@ -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
Re: [PATCH 2/2] powerpc/pseries: Remove VLA from lparcfg_write()
Quoted 7 lines · Suraj Jitindar Singh
In
lparcfg_writewe hard codekbuf_szand 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 forkbuf_sz, thus removing the variable length array.Signed-off-by Suraj Jitindar Singh <[email protected]>