hw/ssi/xilinx_spips: Avoid variable length array
PATCH 1/1 hw/ssi/xilinx_spips: Avoid variable length array
In the stripe8() function we use a variable length array; however we know that the maximum length required is MAX_NUM_BUSSES. Use a fixed-length array and an assert instead.
--- hw/ssi/xilinx_spips.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
hw/ssi/xilinx_spips.c +4 -2
@@ -429,12 +429,14 @@ static void xlnx_zynqmp_qspips_reset(DeviceState *d)static inline void stripe8 (uint8_t *x,int num,bool dir) { -uint8_t r[num]; -memset (r,0 ,sizeof (uint8_t ) * num); +uint8_t r[MAX_NUM_BUSSES ];int idx[2 ] = {0 ,0 };int bit[2 ] = {0 ,7 };int d = dir; +assert (num <=MAX_NUM_BUSSES ); +memset (r,0 ,sizeof (uint8_t ) * num); +for (idx[0 ] =0 ; idx[0 ] < num; ++idx[0 ]) {for (bit[0 ] =7 ; bit[0 ] >=0 ; bit[0 ]--) { r[idx[!d]] |= x[idx[d]] &1 << bit[d] ?1 << bit[!d] :0 ;
Signature · 1 line
2.20.1
+ Francisco
Quoted 34 lines · On Thu, 28 Mar. 2019, 16:26 Peter Maydell, <[email protected]> wrote:
In the
stripe8()function we use a variable length array; however we know that the maximum length required isMAX_NUM_BUSSES. Use a fixed-length array and an assert instead.Signed-off-by Peter Maydell <[email protected]>--- hw/ssi/xilinx_spips.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)hw/ssi/xilinx_spips.c +4
-3@@ -429,12 +429,14 @@ static void xlnx_zynqmp_qspips_reset(DeviceState *d)static inline void stripe8 (uint8_t *x,int num,bool dir) { -uint8_t r[num]; -memset (r,0 ,sizeof (uint8_t ) * num); +uint8_t r[MAX_NUM_BUSSES ];int idx[2 ] = {0 ,0 };int bit[2 ] = {0 ,7 };int d = dir; +assert (num <=MAX_NUM_BUSSES ); +memset (r,0 ,sizeof (uint8_t ) * num); +for (idx[0 ] =0 ; idx[0 ] < num; ++idx[0 ]) {for (bit[0 ] =7 ; bit[0 ] >=0 ; bit[0 ]--) { r[idx[!d]] |= x[idx[d]] &1 << bit[d] ?1 << bit[!d] :0 ; --2.20.1
Philippe Mathieu-Daudé
Reviewed-byLe jeu. 28 mars 2019 16:41, Edgar E. Iglesias <[email protected]> a écrit :
Quoted 29 lines
+ Francisco
Quoted 24 lines · On Thu, 28 Mar. 2019, 16:26 Peter Maydell, <[email protected]> wrote:
In the
stripe8()function we use a variable length array; however we know that the maximum length required isMAX_NUM_BUSSES. Use a fixed-length array and an assert instead.Signed-off-by Peter Maydell <[email protected]>--- hw/ssi/xilinx_spips.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)hw/ssi/xilinx_spips.c +1
-2@@ -429,12 +429,14 @@ static void xlnx_zynqmp_qspips_reset(DeviceState *d)static inline void stripe8 (uint8_t *x,int num,bool dir) { -uint8_t r[num]; -memset (r,0 ,sizeof (uint8_t ) * num); +uint8_t r[MAX_NUM_BUSSES ];int idx[2 ] = {0 ,0 };int bit[2 ] = {0 ,7 };int d = dir;
Quoted 10 lines
Quoted 9 lines
hw/ssi/xilinx_spips.c +3
-1+assert (num <=MAX_NUM_BUSSES ); +memset (r,0 ,sizeof (uint8_t ) * num); +for (idx[0 ] =0 ; idx[0 ] < num; ++idx[0 ]) {for (bit[0 ] =7 ; bit[0 ] >=0 ; bit[0 ]--) { r[idx[!d]] |= x[idx[d]] &1 << bit[d] ?1 << bit[!d] :0 ; --2.20.1
Quoted 1 line
Quoted 5 lines · Peter Maydell
In the
stripe8()function we use a variable length array; however we know that the maximum length required isMAX_NUM_BUSSES. Use a fixed-length array and an assert instead.Signed-off-by Peter Maydell <[email protected]>
Quoted 29 lines
--- hw/ssi/xilinx_spips.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)hw/ssi/xilinx_spips.c +4
-2@@ -429,12 +429,14 @@ static void xlnx_zynqmp_qspips_reset(DeviceState *d)static inline void stripe8 (uint8_t *x,int num,bool dir) { -uint8_t r[num]; -memset (r,0 ,sizeof (uint8_t ) * num); +uint8_t r[MAX_NUM_BUSSES ];int idx[2 ] = {0 ,0 };int bit[2 ] = {0 ,7 };int d = dir; +assert (num <=MAX_NUM_BUSSES ); +memset (r,0 ,sizeof (uint8_t ) * num); +for (idx[0 ] =0 ; idx[0 ] < num; ++idx[0 ]) {for (bit[0 ] =7 ; bit[0 ] >=0 ; bit[0 ]--) { r[idx[!d]] |= x[idx[d]] &1 << bit[d] ?1 << bit[!d] :0 ;Signature · 1 line
2.20.1
Quoted 6 lines · Peter Maydell
In the
stripe8()function we use a variable length array; however we know that the maximum length required isMAX_NUM_BUSSES. Use a fixed-length array and an assert instead.Signed-off-by Peter Maydell <[email protected]>
Who's tree should this go through?
Alistair
Quoted 29 lines
--- hw/ssi/xilinx_spips.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)hw/ssi/xilinx_spips.c +4
-3@@ -429,12 +429,14 @@ static void xlnx_zynqmp_qspips_reset(DeviceState *d)static inline void stripe8 (uint8_t *x,int num,bool dir) { -uint8_t r[num]; -memset (r,0 ,sizeof (uint8_t ) * num); +uint8_t r[MAX_NUM_BUSSES ];int idx[2 ] = {0 ,0 };int bit[2 ] = {0 ,7 };int d = dir; +assert (num <=MAX_NUM_BUSSES ); +memset (r,0 ,sizeof (uint8_t ) * num); +for (idx[0 ] =0 ; idx[0 ] < num; ++idx[0 ]) {for (bit[0 ] =7 ; bit[0 ] >=0 ; bit[0 ]--) { r[idx[!d]] |= x[idx[d]] &1 << bit[d] ?1 << bit[!d] :0 ; --2.20.1
Quoted 9 lines · Peter Maydell
In the
stripe8()function we use a variable length array; however we know that the maximum length required isMAX_NUM_BUSSES. Use a fixed-length array and an assert instead.Signed-off-by Peter Maydell <[email protected]>--- hw/ssi/xilinx_spips.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
I really think is a good idea to remove variable length arrays!
Thanks,
Stefano
Quoted 12 lines · Stefano Garzarella
Quoted 9 lines · Peter Maydell
In the
stripe8()function we use a variable length array; however we know that the maximum length required isMAX_NUM_BUSSES. Use a fixed-length array and an assert instead.Signed-off-by Peter Maydell <[email protected]>--- hw/ssi/xilinx_spips.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
Quoted 3 lines
I really think is a good idea to remove variable length arrays!
Reviewed-by Stefano Garzarella <[email protected]>
Yeah; we have some but not a vast number, so I thought I'd whittle down a few easy candidates. Feel free to have a look at some yourself :-)
thanks
-- PMM
Quoted 13 lines · Peter Maydell
Quoted 12 lines · Stefano Garzarella
Quoted 9 lines · Peter Maydell
In the
stripe8()function we use a variable length array; however we know that the maximum length required isMAX_NUM_BUSSES. Use a fixed-length array and an assert instead.Signed-off-by Peter Maydell <[email protected]>--- hw/ssi/xilinx_spips.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
Quoted 7 lines
Quoted 3 lines
I really think is a good idea to remove variable length arrays!
Reviewed-by Stefano Garzarella <[email protected]>Yeah; we have some but not a vast number, so I thought I'd whittle down a few easy candidates. Feel free to have a look at some yourself :-)
I'll take a look for others candidates :)
Thanks,
Stefano