aic7xxx/aic79xx: remove VLAs
Subsystems (2)
PATCH 1/1 aic7xxx/aic79xx: remove VLAs
In preparation to enabling -Wvla, remove VLAs and replace them with fixed-length arrays instead.
The arrays fixed here, using the number of constant sections, aren't really VLAs, but they appear so to the compiler. Since we know at build-time how many critical sections there are, we might as well use a pre-processor-level constant instead.
This was prompted by https://lkml.org/lkml/2018/3/7/621
--- drivers/scsi/aic7xxx/aic79xx_core.c | 8 ++++---- drivers/scsi/aic7xxx/aic79xx_seq.h_shipped | 3 +-- drivers/scsi/aic7xxx/aic7xxx_core.c | 8 ++++---- drivers/scsi/aic7xxx/aic7xxx_seq.h_shipped | 3 +-- drivers/scsi/aic7xxx/aicasm/aicasm.c | 6 ++++-- 5 files changed, 14 insertions(+), 14 deletions(-)
drivers/scsi/aic7xxx/aic79xx_core.c +4 -4
@@ -9338,9 +9338,9 @@ ahd_dumpseq(struct ahd_softc* ahd)static void ahd_loadseq (struct ahd_softc *ahd) { -struct cs cs_table[num_critical_sections]; -u_int begin_set[num_critical_sections]; -u_int end_set[num_critical_sections]; +struct cs cs_table[NUM_CRITICAL_SECTIONS ]; +u_int begin_set[NUM_CRITICAL_SECTIONS ]; +u_int end_set[NUM_CRITICAL_SECTIONS ];const struct patch *cur_patch;u_int cs_count;u_int cur_cs;
@@ -9456,7 +9456,7 @@ ahd_loadseq(struct ahd_softc *ahd)* Move through the CS table until we find a CS * that might apply to this instruction. */ -for (; cur_cs < num_critical_sections; cur_cs++) { +for (; cur_cs <NUM_CRITICAL_SECTIONS ; cur_cs++) {if (critical_sections[cur_cs].end <= i) {if (begin_set[cs_count] == TRUE && end_set[cs_count] == FALSE) {
drivers/scsi/aic7xxx/aic79xx_seq.h_shipped +1 -2
@@ -1186,5 +1186,4 @@ static const struct cs { { 759, 763 } }; -static const int num_critical_sections = sizeof(critical_sections) - / sizeof(*critical_sections); +#define NUM_CRITICAL_SECTIONS 14
drivers/scsi/aic7xxx/aic7xxx_core.c +4 -4
@@ -6848,9 +6848,9 @@ ahc_dumpseq(struct ahc_softc* ahc)static int ahc_loadseq (struct ahc_softc *ahc) { -struct cs cs_table[num_critical_sections]; -u_int begin_set[num_critical_sections]; -u_int end_set[num_critical_sections]; +struct cs cs_table[NUM_CRITICAL_SECTIONS ]; +u_int begin_set[NUM_CRITICAL_SECTIONS ]; +u_int end_set[NUM_CRITICAL_SECTIONS ];const struct patch *cur_patch;u_int cs_count;u_int cur_cs;
@@ -6915,7 +6915,7 @@ ahc_loadseq(struct ahc_softc *ahc)* Move through the CS table until we find a CS * that might apply to this instruction. */ -for (; cur_cs < num_critical_sections; cur_cs++) { +for (; cur_cs <NUM_CRITICAL_SECTIONS ; cur_cs++) {if (critical_sections[cur_cs].end <= i) {if (begin_set[cs_count] == TRUE && end_set[cs_count] == FALSE) {
drivers/scsi/aic7xxx/aic7xxx_seq.h_shipped +1 -2
@@ -1304,5 +1304,4 @@ static const struct cs { { 875, 877 } }; -static const int num_critical_sections = sizeof(critical_sections) - / sizeof(*critical_sections); +#define NUM_CRITICAL_SECTIONS 7
drivers/scsi/aic7xxx/aicasm/aicasm.c +4 -2
@@ -353,6 +353,7 @@ output_code()critical_section_t *cs;symbol_node_t *cur_node;int instrcount; +int num_critical_sections; instrcount =0 ; fprintf(ofile,
@@ -440,19 +441,20 @@ output_code()" uint16_t end;\n" "} critical_sections[] = {\n"); + num_critical_sections =0 ;for (cs =TAILQ_FIRST (&cs_tailq); cs !=NULL ; cs =TAILQ_NEXT (cs, links)) {fprintf (ofile,"%s\t{ %d, %d }" , cs ==TAILQ_FIRST (&cs_tailq) ?"" :",\n" , cs->begin_addr, cs->end_addr); + num_critical_sections++; }fprintf (ofile,"\n};\n\n" );fprintf (ofile, -"static const int num_critical_sections = sizeof(critical_sections)\n" -" / sizeof(*critical_sections);\n" ); +"#define NUM_CRITICAL_SECTIONS %d\n" , num_critical_sections);fprintf (stderr,"%s: %d instructions used\n" , appname, instrcount); }
Signature · 1 line
2.11.0
Quoted 50 lines · Stephen Kitt
In preparation to enabling -Wvla, remove VLAs and replace them with fixed-length arrays instead.
The arrays fixed here, using the number of constant sections, aren't really VLAs, but they appear so to the compiler. Since we know at build-time how many critical sections there are, we might as well use a pre-processor-level constant instead.
This was prompted by https://lkml.org/lkml/2018/3/7/621
Signed-off-by Stephen Kitt <[email protected]>--- drivers/scsi/aic7xxx/aic79xx_core.c | 8 ++++---- drivers/scsi/aic7xxx/aic79xx_seq.h_shipped | 3 +-- drivers/scsi/aic7xxx/aic7xxx_core.c | 8 ++++---- drivers/scsi/aic7xxx/aic7xxx_seq.h_shipped | 3 +-- drivers/scsi/aic7xxx/aicasm/aicasm.c | 6 ++++-- 5 files changed, 14 insertions(+), 14 deletions(-)drivers/scsi/aic7xxx/aic79xx_core.c +4
-4@@ -9338,9 +9338,9 @@ ahd_dumpseq(struct ahd_softc* ahd)static void ahd_loadseq (struct ahd_softc *ahd) { -struct cs cs_table[num_critical_sections]; -u_int begin_set[num_critical_sections]; -u_int end_set[num_critical_sections]; +struct cs cs_table[NUM_CRITICAL_SECTIONS ]; +u_int begin_set[NUM_CRITICAL_SECTIONS ]; +u_int end_set[NUM_CRITICAL_SECTIONS ];const struct patch *cur_patch;u_int cs_count;u_int cur_cs;@@ -9456,7 +9456,7 @@ ahd_loadseq(struct ahd_softc *ahd)* Move through the CS table until we find a CS * that might apply to this instruction. */ -for (; cur_cs < num_critical_sections; cur_cs++) { +for (; cur_cs <NUM_CRITICAL_SECTIONS ; cur_cs++) {if (critical_sections[cur_cs].end <= i) {if (begin_set[cs_count] == TRUE && end_set[cs_count] == FALSE) {drivers/scsi/aic7xxx/aic79xx_seq.h_shipped +0
-0
drivers/scsi/aic7xxx/aic79xx_seq.h_shipped static const struct cs { · line 1189
Quoted 6 lines
drivers/scsi/aic7xxx/aic79xx_seq.h_shipped +1
-2@@ -1186,5 +1186,4 @@ static const struct cs { { 759, 763 } }; -static const int num_critical_sections = sizeof(critical_sections) - / sizeof(*critical_sections); +#define NUM_CRITICAL_SECTIONS 14
The compiler doesn't treat "const" as a literal, hence the need to change this. However, you can still use the sizeof (actually, this is exactly ARRAY_SIZE()). Perhaps:
#define NUM_CRITICAL_SECTIONS ARRAY_SIZE(critical_sections)
?
Otherwise, looks great!
-Kees
Signature · 2 lines
Kees Cook Pixel Security
Quoted 9 lines · Kees Cook
drivers/scsi/aic7xxx/aic79xx_seq.h_shipped static const struct cs { · line 1189
Quoted 3 lines · Stephen Kitt
drivers/scsi/aic7xxx/aic79xx_seq.h_shipped +1
-2-static const int num_critical_sections = sizeof(critical_sections) - / sizeof(*critical_sections); +#define NUM_CRITICAL_SECTIONS 14The compiler doesn't treat "const" as a literal, hence the need to change this. However, you can still use the sizeof (actually, this is exactly
ARRAY_SIZE()). Perhaps:
Quoted 5 lines
#define
NUM_CRITICAL_SECTIONSARRAY_SIZE(critical_sections)?
Otherwise, looks great!
Thanks, v2 incoming...
Regards,
Stephen
PATCH v2 1/1 aic7xxx/aic79xx: remove VLAs
In reply to Kees CookIn preparation to enabling -Wvla, remove VLAs and replace them with fixed-length arrays instead.
The arrays fixed here, using the number of constant sections, aren't really VLAs, but they appear so to the compiler. Replace the array sizes with a pre-processor-level constant instead using ARRAY_SIZE.
This was prompted by https://lkml.org/lkml/2018/3/7/621
--- drivers/scsi/aic7xxx/aic79xx_core.c | 8 ++++---- drivers/scsi/aic7xxx/aic79xx_seq.h_shipped | 3 +-- drivers/scsi/aic7xxx/aic7xxx_core.c | 8 ++++---- drivers/scsi/aic7xxx/aic7xxx_seq.h_shipped | 3 +-- drivers/scsi/aic7xxx/aicasm/aicasm.c | 3 +-- 5 files changed, 11 insertions(+), 14 deletions(-)
drivers/scsi/aic7xxx/aic79xx_core.c +4 -4
@@ -9338,9 +9338,9 @@ ahd_dumpseq(struct ahd_softc* ahd)static void ahd_loadseq (struct ahd_softc *ahd) { -struct cs cs_table[num_critical_sections]; -u_int begin_set[num_critical_sections]; -u_int end_set[num_critical_sections]; +struct cs cs_table[NUM_CRITICAL_SECTIONS ]; +u_int begin_set[NUM_CRITICAL_SECTIONS ]; +u_int end_set[NUM_CRITICAL_SECTIONS ];const struct patch *cur_patch;u_int cs_count;u_int cur_cs;
@@ -9456,7 +9456,7 @@ ahd_loadseq(struct ahd_softc *ahd)* Move through the CS table until we find a CS * that might apply to this instruction. */ -for (; cur_cs < num_critical_sections; cur_cs++) { +for (; cur_cs <NUM_CRITICAL_SECTIONS ; cur_cs++) {if (critical_sections[cur_cs].end <= i) {if (begin_set[cs_count] == TRUE && end_set[cs_count] == FALSE) {
drivers/scsi/aic7xxx/aic79xx_seq.h_shipped +1 -2
@@ -1186,5 +1186,4 @@ static const struct cs { { 759, 763 } }; -static const int num_critical_sections = sizeof(critical_sections) - / sizeof(*critical_sections); +#define NUM_CRITICAL_SECTIONS ARRAY_SIZE(critical_sections)
drivers/scsi/aic7xxx/aic7xxx_core.c +4 -4
@@ -6848,9 +6848,9 @@ ahc_dumpseq(struct ahc_softc* ahc)static int ahc_loadseq (struct ahc_softc *ahc) { -struct cs cs_table[num_critical_sections]; -u_int begin_set[num_critical_sections]; -u_int end_set[num_critical_sections]; +struct cs cs_table[NUM_CRITICAL_SECTIONS ]; +u_int begin_set[NUM_CRITICAL_SECTIONS ]; +u_int end_set[NUM_CRITICAL_SECTIONS ];const struct patch *cur_patch;u_int cs_count;u_int cur_cs;
@@ -6915,7 +6915,7 @@ ahc_loadseq(struct ahc_softc *ahc)* Move through the CS table until we find a CS * that might apply to this instruction. */ -for (; cur_cs < num_critical_sections; cur_cs++) { +for (; cur_cs <NUM_CRITICAL_SECTIONS ; cur_cs++) {if (critical_sections[cur_cs].end <= i) {if (begin_set[cs_count] == TRUE && end_set[cs_count] == FALSE) {
drivers/scsi/aic7xxx/aic7xxx_seq.h_shipped +1 -2
@@ -1304,5 +1304,4 @@ static const struct cs { { 875, 877 } }; -static const int num_critical_sections = sizeof(critical_sections) - / sizeof(*critical_sections); +#define NUM_CRITICAL_SECTIONS ARRAY_SIZE(critical_sections)
drivers/scsi/aic7xxx/aicasm/aicasm.c +1 -2
@@ -451,8 +451,7 @@ output_code()fprintf (ofile,"\n};\n\n" );fprintf (ofile, -"static const int num_critical_sections = sizeof(critical_sections)\n" -" / sizeof(*critical_sections);\n" ); +"#define NUM_CRITICAL_SECTIONS ARRAY_SIZE(critical_sections)\n" );fprintf (stderr,"%s: %d instructions used\n" , appname, instrcount); }
Signature · 1 line
2.11.0
Quoted 10 lines · Stephen Kitt
In preparation to enabling -Wvla, remove VLAs and replace them with fixed-length arrays instead.
The arrays fixed here, using the number of constant sections, aren't really VLAs, but they appear so to the compiler. Replace the array sizes with a pre-processor-level constant instead using
ARRAY_SIZE.This was prompted by https://lkml.org/lkml/2018/3/7/621
Signed-off-by Stephen Kitt <[email protected]>
Thanks!
-Kees
Quoted 99 lines
--- drivers/scsi/aic7xxx/aic79xx_core.c | 8 ++++---- drivers/scsi/aic7xxx/aic79xx_seq.h_shipped | 3 +-- drivers/scsi/aic7xxx/aic7xxx_core.c | 8 ++++---- drivers/scsi/aic7xxx/aic7xxx_seq.h_shipped | 3 +-- drivers/scsi/aic7xxx/aicasm/aicasm.c | 3 +-- 5 files changed, 11 insertions(+), 14 deletions(-)drivers/scsi/aic7xxx/aic79xx_core.c +4
-4@@ -9338,9 +9338,9 @@ ahd_dumpseq(struct ahd_softc* ahd)static void ahd_loadseq (struct ahd_softc *ahd) { -struct cs cs_table[num_critical_sections]; -u_int begin_set[num_critical_sections]; -u_int end_set[num_critical_sections]; +struct cs cs_table[NUM_CRITICAL_SECTIONS ]; +u_int begin_set[NUM_CRITICAL_SECTIONS ]; +u_int end_set[NUM_CRITICAL_SECTIONS ];const struct patch *cur_patch;u_int cs_count;u_int cur_cs;@@ -9456,7 +9456,7 @@ ahd_loadseq(struct ahd_softc *ahd)* Move through the CS table until we find a CS * that might apply to this instruction. */ -for (; cur_cs < num_critical_sections; cur_cs++) { +for (; cur_cs <NUM_CRITICAL_SECTIONS ; cur_cs++) {if (critical_sections[cur_cs].end <= i) {if (begin_set[cs_count] == TRUE && end_set[cs_count] == FALSE) {drivers/scsi/aic7xxx/aic79xx_seq.h_shipped +1
-2@@ -1186,5 +1186,4 @@ static const struct cs { { 759, 763 } }; -static const int num_critical_sections = sizeof(critical_sections) - / sizeof(*critical_sections); +#define NUM_CRITICAL_SECTIONS ARRAY_SIZE(critical_sections)drivers/scsi/aic7xxx/aic7xxx_core.c +4
-4@@ -6848,9 +6848,9 @@ ahc_dumpseq(struct ahc_softc* ahc)static int ahc_loadseq (struct ahc_softc *ahc) { -struct cs cs_table[num_critical_sections]; -u_int begin_set[num_critical_sections]; -u_int end_set[num_critical_sections]; +struct cs cs_table[NUM_CRITICAL_SECTIONS ]; +u_int begin_set[NUM_CRITICAL_SECTIONS ]; +u_int end_set[NUM_CRITICAL_SECTIONS ];const struct patch *cur_patch;u_int cs_count;u_int cur_cs;@@ -6915,7 +6915,7 @@ ahc_loadseq(struct ahc_softc *ahc)* Move through the CS table until we find a CS * that might apply to this instruction. */ -for (; cur_cs < num_critical_sections; cur_cs++) { +for (; cur_cs <NUM_CRITICAL_SECTIONS ; cur_cs++) {if (critical_sections[cur_cs].end <= i) {if (begin_set[cs_count] == TRUE && end_set[cs_count] == FALSE) {drivers/scsi/aic7xxx/aic7xxx_seq.h_shipped +1
-2@@ -1304,5 +1304,4 @@ static const struct cs { { 875, 877 } }; -static const int num_critical_sections = sizeof(critical_sections) - / sizeof(*critical_sections); +#define NUM_CRITICAL_SECTIONS ARRAY_SIZE(critical_sections)drivers/scsi/aic7xxx/aicasm/aicasm.c +1
-3@@ -451,8 +451,7 @@ output_code()fprintf (ofile,"\n};\n\n" );fprintf (ofile, -"static const int num_critical_sections = sizeof(critical_sections)\n" -" / sizeof(*critical_sections);\n" ); +"#define NUM_CRITICAL_SECTIONS ARRAY_SIZE(critical_sections)\n" );fprintf (stderr,"%s: %d instructions used\n" , appname, instrcount); } --2.11.0
Signature · 2 lines
Kees Cook Pixel Security
Martin K. Petersen
AppliedStephen,
Quoted 6 lines
In preparation to enabling -Wvla, remove VLAs and replace them with fixed-length arrays instead.
The arrays fixed here, using the number of constant sections, aren't really VLAs, but they appear so to the compiler. Replace the array sizes with a pre-processor-level constant instead using
ARRAY_SIZE.
Applied to 4.17/scsi-queue.
Signature · 1 line
Martin K. Petersen Oracle Linux Engineering