scsi: aic7xxx: aic79xx: remove VLAs
authorStephen Kitt <steve@sk2.org>
Thu, 8 Mar 2018 20:51:58 +0000 (21:51 +0100)
committerMartin K. Petersen <martin.petersen@oracle.com>
Thu, 15 Mar 2018 04:34:26 +0000 (00:34 -0400)
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 <steve@sk2.org>
Reviewed-by: Kees Cook <keescook@chromium.org>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
drivers/scsi/aic7xxx/aic79xx_core.c
drivers/scsi/aic7xxx/aic79xx_seq.h_shipped
drivers/scsi/aic7xxx/aic7xxx_core.c
drivers/scsi/aic7xxx/aic7xxx_seq.h_shipped
drivers/scsi/aic7xxx/aicasm/aicasm.c

index b560f396ee99c6665013283059ef8137be1e927e..034f4eebb1603f6271c929e51a304660fae6ac30 100644 (file)
@@ -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) {
index 4b51e232392ff8b3278a34c7c7e810e3ebf84d57..fd64a950ee44790cacee11cb8ba6af35d198428e 100644 (file)
@@ -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)
index 6612ff3b2e8322c9b657ad3bd37c9d5861c6bf58..e97eceacf522f822f201dd9216dea7e635fd44ce 100644 (file)
@@ -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) {
index 07e93fbae70661b2eee2518b0fcaf70e61241c9c..f37362bc8ecef30c090b92206d7c430e858ee307 100644 (file)
@@ -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)
index 21ac265280bf2f6d001b06daa0365f80f8f6976e..5f474e490f3e3993fa4ee1ce607add6de5c32456 100644 (file)
@@ -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);
 }