Skip to contentSkip to conversation

Strict disable implicit fallthrough

RFC PATCH Superseded Emmanouil Pitsidianakis 8 participants 92 messages Oct 13, 2023 – Oct 19, 2023 2 messages not in the archive Page 3 of 3

Subsystems (8)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#60 lore raw

RFC PATCH v2 50/78 hw/audio: add fallthrough pseudo-keyword

In reply to Emmanouil Pitsidianakis

In preparation of raising -Wimplicit-fallthrough to 5, replace all fall-through comments with the fallthrough attribute pseudo-keyword.

---
 hw/audio/asc.c        | 2 +-
 hw/audio/cs4231a.c    | 2 +-
 hw/audio/gusemu_hal.c | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)
hw/audio/asc.c +1 -1
index 0f36b4ce9b..336da09509 100644
@@ -154,126 +154,126 @@ static uint8_t asc_fifo_get(ASCFIFOState *fs)
 static int generate_fifo(ASCState *s, int maxsamples)
 {
     int64_t now = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);
     uint8_t *buf = s->mixbuf;
     int i, wcount = 0;
 
     while (wcount < maxsamples) {
         uint8_t val;
         int16_t d, f0, f1;
         int32_t t;
         int shift, filter;
         bool hasdata = false;
 
         for (i = 0; i < 2; i++) {
             ASCFIFOState *fs = &s->fifos[i];
 
             switch (fs->extregs[ASC_EXTREGS_FIFOCTRL] & 0x83) {
             case 0x82:
                 /*
                  * CD-XA BRR mode: decompress 15 bytes into 28 16-bit
                  * samples
                  */
                 if (!fs->cnt) {
                     val = 0x80;
                     break;
                 }
 
                 if (fs->xa_cnt == -1) {
                     /* Start of packet, get flags */
                     fs->xa_flags = asc_fifo_get(fs);
                     fs->xa_cnt = 0;
                 }
 
                 shift = fs->xa_flags & 0xf;
                 filter = fs->xa_flags >> 4;
                 f0 = (int8_t)fs->extregs[ASC_EXTREGS_CDXA_DECOMP_FILT +
                                  (filter << 1) + 1];
                 f1 = (int8_t)fs->extregs[ASC_EXTREGS_CDXA_DECOMP_FILT +
                                  (filter << 1)];
 
                 if ((fs->xa_cnt & 1) == 0) {
                     if (!fs->cnt) {
                         val = 0x80;
                         break;
                     }
 
                     fs->xa_val = asc_fifo_get(fs);
                     d = (fs->xa_val & 0xf) << 12;
                 } else {
                     d = (fs->xa_val & 0xf0) << 8;
                 }
                 t = (d >> shift) + (((fs->xa_last[0] * f0) +
                                      (fs->xa_last[1] * f1) + 32) >> 6);
                 if (t < -32768) {
                     t = -32768;
                 } else if (t > 32767) {
                     t = 32767;
                 }
 
                 /*
                  * CD-XA BRR generates 16-bit signed output, so convert to
                  * 8-bit before writing to buffer. Does real hardware do the
                  * same?
                  */
                 val = (uint8_t)(t / 256) ^ 0x80;
                 hasdata = true;
                 fs->xa_cnt++;
 
                 fs->xa_last[1] = fs->xa_last[0];
                 fs->xa_last[0] = (int16_t)t;
 
                 if (fs->xa_cnt == 28) {
                     /* End of packet */
                     fs->xa_cnt = -1;
                 }
                 break;
 
             default:
-                /* fallthrough */
+                fallthrough;
             case 0x80:
                 /* Raw mode */
                 if (fs->cnt) {
                     val = asc_fifo_get(fs);
                     hasdata = true;
                 } else {
                     val = 0x80;
                 }
                 break;
             }
 
             buf[wcount * 2 + i] = val;
         }
 
         if (!hasdata) {
             break;
         }
 
         wcount++;
     }
 
     /*
      * MacOS (un)helpfully leaves the FIFO engine running even when it has
      * finished writing out samples, but still expects the FIFO empty
      * interrupts to be generated for each FIFO cycle (without these interrupts
      * MacOS will freeze)
      */
     if (s->fifos[0].cnt == 0 && s->fifos[1].cnt == 0) {
         if (!s->fifo_empty_ns) {
             /* FIFO has completed first empty cycle */
             s->fifo_empty_ns = now;
         } else if (now > (s->fifo_empty_ns + ASC_FIFO_CYCLE_TIME)) {
             /* FIFO has completed entire cycle with no data */
             s->fifos[0].int_status |= ASC_FIFO_STATUS_HALF_FULL |
                                       ASC_FIFO_STATUS_FULL_EMPTY;
             s->fifos[1].int_status |= ASC_FIFO_STATUS_HALF_FULL |
                                       ASC_FIFO_STATUS_FULL_EMPTY;
             s->fifo_empty_ns = now;
             asc_raise_irq(s);
         }
     } else {
         /* FIFO contains data, reset empty time */
         s->fifo_empty_ns = 0;
     }
 
     return wcount;
 }
hw/audio/cs4231a.c +1 -1
index 3aa105748d..3bf0116c68 100644
@@ -272,90 +272,90 @@ static void cs_audio_callback (void *opaque, int free)
 static void cs_reset_voices (CSState *s, uint32_t val)
 {
     int xtal;
     struct audsettings as;
     IsaDmaClass *k = ISADMA_GET_CLASS(s->isa_dma);
 
 #ifdef DEBUG_XLAW
     if (val == 0 || val == 32)
         val = (1 << 4) | (1 << 5);
 #endif
 
     xtal = val & 1;
     as.freq = freqs[xtal][(val >> 1) & 7];
 
     if (as.freq == -1) {
         lerr ("unsupported frequency (val=%#x)\n", val);
         goto error;
     }
 
     as.nchannels = (val & (1 << 4)) ? 2 : 1;
     as.endianness = 0;
     s->tab = NULL;
 
     switch ((val >> 5) & ((s->dregs[MODE_And_ID] & MODE2) ? 7 : 3)) {
     case 0:
         as.fmt = AUDIO_FORMAT_U8;
         s->shift = as.nchannels == 2;
         break;
 
     case 1:
         s->tab = MuLawDecompressTable;
         goto x_law;
     case 3:
         s->tab = ALawDecompressTable;
     x_law:
         as.fmt = AUDIO_FORMAT_S16;
         as.endianness = AUDIO_HOST_ENDIANNESS;
         s->shift = as.nchannels == 2;
         break;
 
     case 6:
         as.endianness = 1;
-        /* fall through */
+        fallthrough;
     case 2:
         as.fmt = AUDIO_FORMAT_S16;
         s->shift = as.nchannels;
         break;
 
     case 7:
     case 4:
         lerr ("attempt to use reserved format value (%#x)\n", val);
         goto error;
 
     case 5:
         lerr ("ADPCM 4 bit IMA compatible format is not supported\n");
         goto error;
     }
 
     s->voice = AUD_open_out (
         &s->card,
         s->voice,
         "cs4231a",
         s,
         cs_audio_callback,
         &as
         );
 
     if (s->dregs[Interface_Configuration] & PEN) {
         if (!s->dma_running) {
             k->hold_DREQ(s->isa_dma, s->dma);
             AUD_set_active_out (s->voice, 1);
             s->transferred = 0;
         }
         s->dma_running = 1;
     }
     else {
         if (s->dma_running) {
             k->release_DREQ(s->isa_dma, s->dma);
             AUD_set_active_out (s->voice, 0);
         }
         s->dma_running = 0;
     }
     return;
 
  error:
     if (s->dma_running) {
         k->release_DREQ(s->isa_dma, s->dma);
         AUD_set_active_out (s->voice, 0);
     }
 }
hw/audio/gusemu_hal.c +1 -1
index f159978b49..76dd906ea1 100644
@@ -190,311 +190,311 @@ unsigned int gus_read(GUSEmuState * state, int port, int size)
 void gus_write(GUSEmuState * state, int port, int size, unsigned int data)
 {
     uint8_t        *gusptr;
     gusptr = state->gusdatapos;
     GUSregd(portaccesses)++;
 
     switch (port & 0xff0f)
     {
     case 0x200:                 /* MixerCtrlReg */
         GUSregb(MixerCtrlReg2x0) = (uint8_t) data;
         break;
     case 0x206:                 /* IRQstatReg / SB2x6IRQ */
         if (GUSregb(GUS45TimerCtrl) & 0x20) /* SB IRQ enabled? -> set 2x6IRQ bit */
         {
             GUSregb(TimerStatus2x8) |= 0x08;
             GUSregb(IRQStatReg2x6) = 0x10;
             GUS_irqrequest(state, state->gusirq, 1);
         }
         break;
     case 0x308:                /* AdLib 388h */
     case 0x208:                /* AdLibCommandReg */
         GUSregb(AdLibCommand2xA) = (uint8_t) data;
         break;
     case 0x309:                /* AdLib 389h */
     case 0x209:                /* AdLibDataReg */
         if ((GUSregb(AdLibCommand2xA) == 0x04) && (!(GUSregb(GUS45TimerCtrl) & 1))) /* GUS auto timer mode enabled? */
         {
             if (data & 0x80)
                 GUSregb(TimerStatus2x8) &= 0x1f; /* AdLib IRQ reset? -> clear maskable adl. timer int regs */
             else
                 GUSregb(TimerDataReg2x9) = (uint8_t) data;
         }
         else
         {
             GUSregb(AdLibData2x9) = (uint8_t) data;
             if (GUSregb(GUS45TimerCtrl) & 0x02)
             {
                 GUSregb(TimerStatus2x8) |= 0x01;
                 GUSregb(IRQStatReg2x6) = 0x10;
                 GUS_irqrequest(state, state->gusirq, 1);
             }
         }
         break;
     case 0x20A:
         GUSregb(AdLibStatus2x8) = (uint8_t) data;
         break;                 /* AdLibStatus2x8 */
     case 0x20B:                /* GUS hidden registers */
         switch (GUSregb(RegCtrl_2xF) & 0x7)
         {
         case 0:
             if (GUSregb(MixerCtrlReg2x0) & 0x40)
                 GUSregb(IRQ_2xB) = (uint8_t) data; /* control register select bit */
             else
                 GUSregb(DMA_2xB) = (uint8_t) data;
             break;
             /* case 1-4: general purpose emulation regs */
         case 5:                                    /* clear stat reg 2xF */
             GUSregb(StatRead_2xF) = 0; /* ToDo: is this identical with GUS classic? */
             if (!GUSregb(IRQStatReg2x6))
                 GUS_irqclear(state, state->gusirq);
             break;
         case 6:                                    /* Jumper reg (Joystick/MIDI enable) */
             GUSregb(Jumper_2xB) = (uint8_t) data;
             break;
         default:;
         }
         break;
     case 0x20C:                /* SB2xCd */
         if (GUSregb(GUS45TimerCtrl) & 0x20)
         {
             GUSregb(TimerStatus2x8) |= 0x10; /* SB IRQ enabled? -> set 2xCIRQ bit */
             GUSregb(IRQStatReg2x6) = 0x10;
             GUS_irqrequest(state, state->gusirq, 1);
         }
-        /* fall through */
+        fallthrough;
     case 0x20D:                /* SB2xCd no IRQ */
         GUSregb(SB2xCd) = (uint8_t) data;
         break;
     case 0x20E:                /* SB2xE */
         GUSregb(SB2xE) = (uint8_t) data;
         break;
     case 0x20F:
         GUSregb(RegCtrl_2xF) = (uint8_t) data;
         break;                 /* CtrlReg2xF */
     case 0x302:                /* VoiceSelReg */
         GUSregb(VoiceSelReg3x2) = (uint8_t) data;
         break;
     case 0x303:                /* FunkSelReg */
         GUSregb(FunkSelReg3x3) = (uint8_t) data;
         if ((uint8_t) data == 0x8f) /* set irqstatreg, get voicereg and clear IRQ */
         {
             int             voice;
             if (GUSregd(voicewavetableirq)) /* WavetableIRQ */
             {
                 for (voice = 0; voice < 31; voice++)
                 {
                     if (GUSregd(voicewavetableirq) & (1 << voice))
                     {
                         GUSregd(voicewavetableirq) ^= (1 << voice); /* clear IRQ bit */
                         GUSregb(voice << 5) &= 0x7f; /* clear voice reg irq bit */
                         if (!GUSregd(voicewavetableirq))
                             GUSregb(IRQStatReg2x6) &= 0xdf;
                         if (!GUSregb(IRQStatReg2x6))
                             GUS_irqclear(state, state->gusirq);
                         GUSregb(SynVoiceIRQ8f) = voice | 0x60; /* (bit==0 => IRQ wartend) */
                         return;
                     }
                 }
             }
             else if (GUSregd(voicevolrampirq)) /* VolRamp IRQ */
             {
                 for (voice = 0; voice < 31; voice++)
                 {
                     if (GUSregd(voicevolrampirq) & (1 << voice))
                     {
                         GUSregd(voicevolrampirq) ^= (1 << voice); /* clear IRQ bit */
                         GUSregb((voice << 5) + VSRVolRampControl) &= 0x7f; /* clear voice volume reg irq bit */
                         if (!GUSregd(voicevolrampirq))
                             GUSregb(IRQStatReg2x6) &= 0xbf;
                         if (!GUSregb(IRQStatReg2x6))
                             GUS_irqclear(state, state->gusirq);
                         GUSregb(SynVoiceIRQ8f) = voice | 0x80; /* (bit==0 => IRQ wartend) */
                         return;
                     }
                 }
             }
             GUSregb(SynVoiceIRQ8f) = 0xe8; /* kein IRQ wartet */
         }
         break;
     case 0x304:
     case 0x305:
         {
             uint16_t         writedata = (uint16_t) data;
             uint16_t         readmask = 0x0000;
             if (size == 1)
             {
                 readmask = 0xff00;
                 writedata &= 0xff;
                 if ((port & 0xff0f) == 0x305)
                 {
                     writedata = (uint16_t) (writedata << 8);
                     readmask = 0x00ff;
                 }
             }
             switch (GUSregb(FunkSelReg3x3))
             {
                 /* voice specific functions */
             case 0x00:
             case 0x01:
             case 0x02:
             case 0x03:
             case 0x04:
             case 0x05:
             case 0x06:
             case 0x07:
             case 0x08:
             case 0x09:
             case 0x0a:
             case 0x0b:
             case 0x0c:
             case 0x0d:
                 {
                     int             offset;
                     if (!(GUSregb(GUS4cReset) & 0x01))
                         break;  /* reset flag active? */
                     offset = 2 * (GUSregb(FunkSelReg3x3) & 0x0f);
                     offset += (GUSregb(VoiceSelReg3x2) & 0x1f) << 5; /*  = Voice*32 + Function*2 */
                     GUSregw(offset) = (uint16_t) ((GUSregw(offset) & readmask) | writedata);
                 }
                 break;
                 /* voice unspecific functions */
             case 0x0e:         /* NumVoices */
                 GUSregb(NumVoices) = (uint8_t) data;
                 break;
             /* case 0x0f:      */ /* read only */
                 /* common functions */
             case 0x41:         /* DramDMAContrReg */
                 GUSregb(GUS41DMACtrl) = (uint8_t) data;
                 if (data & 0x01)
                     GUS_dmarequest(state);
                 break;
             case 0x42:         /* DramDMAmemPosReg */
                 GUSregw(GUS42DMAStart) = (GUSregw(GUS42DMAStart) & readmask) | writedata;
                 GUSregb(GUS50DMAHigh) &= 0xf; /* compatibility stuff... */
                 break;
             case 0x43:         /* DRAMaddrLo */
                 GUSregd(GUSDRAMPOS24bit) =
                     (GUSregd(GUSDRAMPOS24bit) & (readmask | 0xff0000)) | writedata;
                 break;
             case 0x44:         /* DRAMaddrHi */
                 GUSregd(GUSDRAMPOS24bit) =
                     (GUSregd(GUSDRAMPOS24bit) & 0xffff) | ((data & 0x0f) << 16);
                 break;
             case 0x45:         /* TCtrlReg */
                 GUSregb(GUS45TimerCtrl) = (uint8_t) data;
                 if (!(data & 0x20))
                     GUSregb(TimerStatus2x8) &= 0xe7;    /* sb IRQ dis? -> clear 2x8/2xC sb IRQ flags */
                 if (!(data & 0x02))
                     GUSregb(TimerStatus2x8) &= 0xfe;    /* adlib data IRQ dis? -> clear 2x8 adlib IRQ flag */
                 if (!(GUSregb(TimerStatus2x8) & 0x19))
                     GUSregb(IRQStatReg2x6) &= 0xef;     /* 0xe6; $$clear IRQ if both IRQ bits are inactive or cleared */
                 /* catch up delayed timer IRQs: */
                 if ((GUSregw(TimerIRQs) > 1) && (GUSregb(TimerDataReg2x9) & 3))
                 {
                     if (GUSregb(TimerDataReg2x9) & 1)   /* start timer 1 (80us decrement rate) */
                     {
                         if (!(GUSregb(TimerDataReg2x9) & 0x40))
                             GUSregb(TimerStatus2x8) |= 0xc0;    /* maskable bits */
                         if (data & 4) /* timer1 irq enable */
                         {
                             GUSregb(TimerStatus2x8) |= 4;       /* nonmaskable bit */
                             GUSregb(IRQStatReg2x6) |= 4;        /* timer 1 irq pending */
                         }
                     }
                     if (GUSregb(TimerDataReg2x9) & 2)   /* start timer 2 (320us decrement rate) */
                     {
                         if (!(GUSregb(TimerDataReg2x9) & 0x20))
                             GUSregb(TimerStatus2x8) |= 0xa0;    /* maskable bits */
                         if (data & 8) /* timer2 irq enable */
                         {
                             GUSregb(TimerStatus2x8) |= 2;       /* nonmaskable bit */
                             GUSregb(IRQStatReg2x6) |= 8;        /* timer 2 irq pending */
                         }
                     }
                     GUSregw(TimerIRQs)--;
                     if (GUSregw(BusyTimerIRQs) > 1)
                         GUSregw(BusyTimerIRQs)--;
                     else
                         GUSregw(BusyTimerIRQs) =
                             GUS_irqrequest(state, state->gusirq, GUSregw(TimerIRQs));
                 }
                 else
                     GUSregw(TimerIRQs) = 0;
 
                 if (!(data & 0x04))
                 {
                     GUSregb(TimerStatus2x8) &= 0xfb; /* clear non-maskable timer1 bit */
                     GUSregb(IRQStatReg2x6)  &= 0xfb;
                 }
                 if (!(data & 0x08))
                 {
                     GUSregb(TimerStatus2x8) &= 0xfd; /* clear non-maskable timer2 bit */
                     GUSregb(IRQStatReg2x6)  &= 0xf7;
                 }
                 if (!GUSregb(IRQStatReg2x6))
                     GUS_irqclear(state, state->gusirq);
                 break;
             case 0x46:          /* Counter1 */
                 GUSregb(GUS46Counter1) = (uint8_t) data;
                 break;
             case 0x47:          /* Counter2 */
                 GUSregb(GUS47Counter2) = (uint8_t) data;
                 break;
             /* case 0x48:       */ /* sampling freq reg not emulated (same as interwave) */
             case 0x49:          /* SampCtrlReg */
                 GUSregb(GUS49SampCtrl) = (uint8_t) data;
                 break;
             /* case 0x4b:       */ /* joystick trim not emulated */
             case 0x4c:          /* GUSreset */
                 GUSregb(GUS4cReset) = (uint8_t) data;
                 if (!(GUSregb(GUS4cReset) & 1)) /* reset... */
                 {
                     GUSregd(voicewavetableirq) = 0;
                     GUSregd(voicevolrampirq) = 0;
                     GUSregw(TimerIRQs) = 0;
                     GUSregw(BusyTimerIRQs) = 0;
                     GUSregb(NumVoices) = 0xcd;
                     GUSregb(IRQStatReg2x6) = 0;
                     GUSregb(TimerStatus2x8) = 0;
                     GUSregb(AdLibData2x9) = 0;
                     GUSregb(TimerDataReg2x9) = 0;
                     GUSregb(GUS41DMACtrl) = 0;
                     GUSregb(GUS45TimerCtrl) = 0;
                     GUSregb(GUS49SampCtrl) = 0;
                     GUSregb(GUS4cReset) &= 0xf9; /* clear IRQ and DAC enable bits */
                     GUS_irqclear(state, state->gusirq);
                 }
                 /* IRQ enable bit checked elsewhere */
                 /* EnableDAC bit may be used by external callers */
                 break;
             }
         }
         break;
     case 0x307:                /* DRAMaccess */
         {
             uint8_t        *adr;
             adr = state->himemaddr + (GUSregd(GUSDRAMPOS24bit) & 0xfffff);
             *adr = (uint8_t) data;
         }
         break;
     }
 }
 
 /* Attention when breaking up a single DMA transfer to multiple ones:
  * it may lead to multiple terminal count interrupts and broken transfers:
  *
  * 1. Whenever you transfer a piece of data, the gusemu callback is invoked
  * 2. The callback may generate a TC irq (if the register was set up to do so)
  * 3. The irq may result in the program using the GUS to reprogram the GUS
  *
  * Some programs also decide to upload by just checking if TC occurs
  * (via interrupt or a cleared GUS dma flag)
  * and then start the next transfer, without checking DMA state
  *
  * Thus: Always make sure to set the TC flag correctly!
  *
  * Note that the genuine GUS had a granularity of 16 bytes/words for low/high DMA
  * while later cards had atomic granularity provided by an additional GUS50DMAHigh register
  * GUSemu also uses this register to support byte-granular transfers for better compatibility
  * with emulators other than GUSemu32
  */
Signature · 1 line
2.39.2
#61 lore raw

RFC PATCH v2 51/78 chardev: add fallthrough pseudo-keyword

In reply to Emmanouil Pitsidianakis

In preparation of raising -Wimplicit-fallthrough to 5, replace all fall-through comments with the fallthrough attribute pseudo-keyword.

---
 chardev/char-socket.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
chardev/char-socket.c +1 -1
index 73947da188..1562e066a4 100644
@@ -549,34 +549,34 @@ static int tcp_chr_sync_read(Chardev *chr, const uint8_t *buf, int len)
 static char *qemu_chr_compute_filename(SocketChardev *s)
 {
     struct sockaddr_storage *ss = &s->sioc->localAddr;
     struct sockaddr_storage *ps = &s->sioc->remoteAddr;
     socklen_t ss_len = s->sioc->localAddrLen;
     socklen_t ps_len = s->sioc->remoteAddrLen;
     char shost[NI_MAXHOST], sserv[NI_MAXSERV];
     char phost[NI_MAXHOST], pserv[NI_MAXSERV];
     const char *left = "", *right = "";
 
     switch (ss->ss_family) {
     case AF_UNIX:
         return g_strdup_printf("unix:%s%s",
                                ((struct sockaddr_un *)(ss))->sun_path,
                                s->is_listen ? ",server=on" : "");
     case AF_INET6:
         left  = "[";
         right = "]";
-        /* fall through */
+        fallthrough;
     case AF_INET:
         getnameinfo((struct sockaddr *) ss, ss_len, shost, sizeof(shost),
                     sserv, sizeof(sserv), NI_NUMERICHOST | NI_NUMERICSERV);
         getnameinfo((struct sockaddr *) ps, ps_len, phost, sizeof(phost),
                     pserv, sizeof(pserv), NI_NUMERICHOST | NI_NUMERICSERV);
         return g_strdup_printf("%s:%s%s%s:%s%s <-> %s%s%s:%s",
                                qemu_chr_socket_protocol(s),
                                left, shost, right, sserv,
                                s->is_listen ? ",server=on" : "",
                                left, phost, right, pserv);
 
     default:
         return g_strdup_printf("unknown");
     }
 }
Signature · 1 line
2.39.2
#62 lore raw

RFC PATCH v2 52/78 hw/char: add fallthrough pseudo-keyword

In reply to Emmanouil Pitsidianakis

In preparation of raising -Wimplicit-fallthrough to 5, replace all fall-through comments with the fallthrough attribute pseudo-keyword.

---
 hw/char/nrf51_uart.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
hw/char/nrf51_uart.c +2 -2
index dfe2276d71..3e2b35c7ad 100644
@@ -113,79 +113,79 @@ static void uart_cancel_transmit(NRF51UARTState *s)
 static void uart_write(void *opaque, hwaddr addr,
                        uint64_t value, unsigned int size)
 {
     NRF51UARTState *s = NRF51_UART(opaque);
 
     trace_nrf51_uart_write(addr, value, size);
 
     if (!s->enabled && (addr != A_UART_ENABLE)) {
         return;
     }
 
     switch (addr) {
     case A_UART_TXD:
         if (!s->pending_tx_byte && s->tx_started) {
             s->reg[R_UART_TXD] = value;
             s->pending_tx_byte = true;
             uart_transmit(NULL, G_IO_OUT, s);
         }
         break;
     case A_UART_INTEN:
         s->reg[R_UART_INTEN] = value;
         break;
     case A_UART_INTENSET:
         s->reg[R_UART_INTEN] |= value;
         break;
     case A_UART_INTENCLR:
         s->reg[R_UART_INTEN] &= ~value;
         break;
     case A_UART_TXDRDY ... A_UART_RXTO:
         s->reg[addr / 4] = value;
         break;
     case A_UART_ERRORSRC:
         s->reg[addr / 4] &= ~value;
         break;
     case A_UART_RXD:
         break;
     case A_UART_RXDRDY:
         if (value == 0) {
             s->reg[R_UART_RXDRDY] = 0;
         }
         break;
     case A_UART_STARTTX:
         if (value == 1) {
             s->tx_started = true;
         }
         break;
     case A_UART_STARTRX:
         if (value == 1) {
             s->rx_started = true;
         }
         break;
     case A_UART_ENABLE:
         if (value) {
             if (value == 4) {
                 s->enabled = true;
             }
             break;
         }
         s->enabled = false;
         value = 1;
-        /* fall through */
+        fallthrough;
     case A_UART_SUSPEND:
     case A_UART_STOPTX:
         if (value == 1) {
             s->tx_started = false;
         }
-        /* fall through */
+        fallthrough;
     case A_UART_STOPRX:
         if (addr != A_UART_STOPTX && value == 1) {
             s->rx_started = false;
             s->reg[R_UART_RXTO] = 1;
         }
         break;
     default:
         s->reg[addr / 4] = value;
         break;
     }
     nrf51_uart_update_irq(s);
 }
Signature · 1 line
2.39.2
#63 lore raw

RFC PATCH v2 53/78 nbd: add fallthrough pseudo-keyword

In reply to Emmanouil Pitsidianakis

In preparation of raising -Wimplicit-fallthrough to 5, replace all fall-through comments with the fallthrough attribute pseudo-keyword.

---
 nbd/client.c | 4 ++--
 nbd/common.c | 2 +-
 qemu-nbd.c   | 4 ++--
 3 files changed, 5 insertions(+), 5 deletions(-)
nbd/client.c +2 -2
index 29ffc609a4..04507249b2 100644
@@ -1014,102 +1014,102 @@ static int nbd_negotiate_finish_oldstyle(QIOChannel *ioc, NBDExportInfo *info,
 /*
  * nbd_receive_negotiate:
  * Connect to server, complete negotiation, and move into transmission phase.
  * Returns: negative errno: failure talking to server
  *          0: server is connected
  */
 int nbd_receive_negotiate(QIOChannel *ioc, QCryptoTLSCreds *tlscreds,
                           const char *hostname, QIOChannel **outioc,
                           NBDExportInfo *info, Error **errp)
 {
     ERRP_GUARD();
     int result;
     bool zeroes;
     bool base_allocation = info->base_allocation;
 
     assert(info->name && strlen(info->name) <= NBD_MAX_STRING_SIZE);
     trace_nbd_receive_negotiate_name(info->name);
 
     result = nbd_start_negotiate(ioc, tlscreds, hostname, outioc,
                                  info->mode, &zeroes, errp);
     if (result < 0) {
         return result;
     }
 
     info->mode = result;
     info->base_allocation = false;
     if (tlscreds && *outioc) {
         ioc = *outioc;
     }
 
     switch (info->mode) {
     case NBD_MODE_EXTENDED:
     case NBD_MODE_STRUCTURED:
         if (base_allocation) {
             result = nbd_negotiate_simple_meta_context(ioc, info, errp);
             if (result < 0) {
                 return -EINVAL;
             }
             info->base_allocation = result == 1;
         }
-        /* fall through */
+        fallthrough;
     case NBD_MODE_SIMPLE:
         /* Try NBD_OPT_GO first - if it works, we are done (it
          * also gives us a good message if the server requires
          * TLS).  If it is not available, fall back to
          * NBD_OPT_LIST for nicer error messages about a missing
          * export, then use NBD_OPT_EXPORT_NAME.  */
         result = nbd_opt_info_or_go(ioc, NBD_OPT_GO, info, errp);
         if (result < 0) {
             return -EINVAL;
         }
         if (result > 0) {
             return 0;
         }
         /* Check our desired export is present in the
          * server export list. Since NBD_OPT_EXPORT_NAME
          * cannot return an error message, running this
          * query gives us better error reporting if the
          * export name is not available.
          */
         if (nbd_receive_query_exports(ioc, info->name, errp) < 0) {
             return -EINVAL;
         }
-        /* fall through */
+        fallthrough;
     case NBD_MODE_EXPORT_NAME:
         /* write the export name request */
         if (nbd_send_option_request(ioc, NBD_OPT_EXPORT_NAME, -1, info->name,
                                     errp) < 0) {
             return -EINVAL;
         }
 
         /* Read the response */
         if (nbd_read64(ioc, &info->size, "export length", errp) < 0) {
             return -EINVAL;
         }
 
         if (nbd_read16(ioc, &info->flags, "export flags", errp) < 0) {
             return -EINVAL;
         }
         break;
     case NBD_MODE_OLDSTYLE:
         if (*info->name) {
             error_setg(errp, "Server does not support non-empty export names");
             return -EINVAL;
         }
         if (nbd_negotiate_finish_oldstyle(ioc, info, errp) < 0) {
             return -EINVAL;
         }
         break;
     default:
         g_assert_not_reached();
     }
 
     trace_nbd_receive_negotiate_size_flags(info->size, info->flags);
     if (zeroes && nbd_drop(ioc, 124, errp) < 0) {
         error_prepend(errp, "Failed to read reserved block: ");
         return -EINVAL;
     }
     return 0;
 }
 
 /* Clean up result of nbd_receive_export_list */
nbd/common.c +1 -1
index 3247c1d618..1140ea0888 100644
@@ -222,37 +222,37 @@ const char *nbd_err_lookup(int err)
 int nbd_errno_to_system_errno(int err)
 {
     int ret;
     switch (err) {
     case NBD_SUCCESS:
         ret = 0;
         break;
     case NBD_EPERM:
         ret = EPERM;
         break;
     case NBD_EIO:
         ret = EIO;
         break;
     case NBD_ENOMEM:
         ret = ENOMEM;
         break;
     case NBD_ENOSPC:
         ret = ENOSPC;
         break;
     case NBD_EOVERFLOW:
         ret = EOVERFLOW;
         break;
     case NBD_ENOTSUP:
         ret = ENOTSUP;
         break;
     case NBD_ESHUTDOWN:
         ret = ESHUTDOWN;
         break;
     default:
         trace_nbd_unknown_error(err);
-        /* fallthrough */
+        fallthrough;
     case NBD_EINVAL:
         ret = EINVAL;
         break;
     }
     return ret;
 }
qemu-nbd.c +2 -2
index 186e6468b1..41e50208a5 100644
@@ -528,704 +528,704 @@ static void qemu_nbd_shutdown(void)
 int main(int argc, char **argv)
 {
     BlockBackend *blk;
     BlockDriverState *bs;
     uint64_t dev_offset = 0;
     bool readonly = false;
     bool disconnect = false;
     const char *bindto = NULL;
     const char *port = NULL;
     char *sockpath = NULL;
     QemuOpts *sn_opts = NULL;
     const char *sn_id_or_name = NULL;
     const char *sopt = "hVb:o:p:rsnc:dvk:e:f:tl:x:T:D:AB:L";
     struct option lopt[] = {
         { "help", no_argument, NULL, 'h' },
         { "version", no_argument, NULL, 'V' },
         { "bind", required_argument, NULL, 'b' },
         { "port", required_argument, NULL, 'p' },
         { "socket", required_argument, NULL, 'k' },
         { "offset", required_argument, NULL, 'o' },
         { "read-only", no_argument, NULL, 'r' },
         { "allocation-depth", no_argument, NULL, 'A' },
         { "bitmap", required_argument, NULL, 'B' },
         { "connect", required_argument, NULL, 'c' },
         { "disconnect", no_argument, NULL, 'd' },
         { "list", no_argument, NULL, 'L' },
         { "snapshot", no_argument, NULL, 's' },
         { "load-snapshot", required_argument, NULL, 'l' },
         { "nocache", no_argument, NULL, 'n' },
         { "cache", required_argument, NULL, QEMU_NBD_OPT_CACHE },
         { "aio", required_argument, NULL, QEMU_NBD_OPT_AIO },
         { "discard", required_argument, NULL, QEMU_NBD_OPT_DISCARD },
         { "detect-zeroes", required_argument, NULL,
           QEMU_NBD_OPT_DETECT_ZEROES },
         { "shared", required_argument, NULL, 'e' },
         { "format", required_argument, NULL, 'f' },
         { "persistent", no_argument, NULL, 't' },
         { "verbose", no_argument, NULL, 'v' },
         { "object", required_argument, NULL, QEMU_NBD_OPT_OBJECT },
         { "export-name", required_argument, NULL, 'x' },
         { "description", required_argument, NULL, 'D' },
         { "tls-creds", required_argument, NULL, QEMU_NBD_OPT_TLSCREDS },
         { "tls-hostname", required_argument, NULL, QEMU_NBD_OPT_TLSHOSTNAME },
         { "tls-authz", required_argument, NULL, QEMU_NBD_OPT_TLSAUTHZ },
         { "image-opts", no_argument, NULL, QEMU_NBD_OPT_IMAGE_OPTS },
         { "trace", required_argument, NULL, 'T' },
         { "fork", no_argument, NULL, QEMU_NBD_OPT_FORK },
         { "pid-file", required_argument, NULL, QEMU_NBD_OPT_PID_FILE },
         { "selinux-label", required_argument, NULL,
           QEMU_NBD_OPT_SELINUX_LABEL },
         { NULL, 0, NULL, 0 }
     };
     int ch;
     int opt_ind = 0;
     int flags = BDRV_O_RDWR;
     int ret = 0;
     bool seen_cache = false;
     bool seen_discard = false;
     bool seen_aio = false;
     pthread_t client_thread;
     const char *fmt = NULL;
     Error *local_err = NULL;
     BlockdevDetectZeroesOptions detect_zeroes = BLOCKDEV_DETECT_ZEROES_OPTIONS_OFF;
     QDict *options = NULL;
     const char *export_name = NULL; /* defaults to "" later for server mode */
     const char *export_description = NULL;
     BlockDirtyBitmapOrStrList *bitmaps = NULL;
     bool alloc_depth = false;
     const char *tlscredsid = NULL;
     const char *tlshostname = NULL;
     bool imageOpts = false;
     bool writethrough = false; /* Client will flush as needed. */
     bool list = false;
     unsigned socket_activation;
     const char *pid_file_name = NULL;
     const char *selinux_label = NULL;
     BlockExportOptions *export_opts;
     struct NbdClientOpts opts = {
         .fork_process = false,
         .verbose = false,
         .device = NULL,
         .srcpath = NULL,
         .saddr = NULL,
         .old_stderr = STDOUT_FILENO,
     };
 
 #ifdef CONFIG_POSIX
     os_setup_early_signal_handling();
     os_setup_signal_handling();
 #endif
 
     socket_init();
     error_init(argv[0]);
     module_call_init(MODULE_INIT_TRACE);
     qcrypto_init(&error_fatal);
 
     module_call_init(MODULE_INIT_QOM);
     qemu_add_opts(&qemu_trace_opts);
     qemu_init_exec_dir(argv[0]);
 
     while ((ch = getopt_long(argc, argv, sopt, lopt, &opt_ind)) != -1) {
         switch (ch) {
         case 's':
             flags |= BDRV_O_SNAPSHOT;
             break;
         case 'n':
             optarg = (char *) "none";
-            /* fallthrough */
+            fallthrough;
         case QEMU_NBD_OPT_CACHE:
             if (seen_cache) {
                 error_report("-n and --cache can only be specified once");
                 exit(EXIT_FAILURE);
             }
             seen_cache = true;
             if (bdrv_parse_cache_mode(optarg, &flags, &writethrough) == -1) {
                 error_report("Invalid cache mode `%s'", optarg);
                 exit(EXIT_FAILURE);
             }
             break;
         case QEMU_NBD_OPT_AIO:
             if (seen_aio) {
                 error_report("--aio can only be specified once");
                 exit(EXIT_FAILURE);
             }
             seen_aio = true;
             if (bdrv_parse_aio(optarg, &flags) < 0) {
                 error_report("Invalid aio mode '%s'", optarg);
                 exit(EXIT_FAILURE);
             }
             break;
         case QEMU_NBD_OPT_DISCARD:
             if (seen_discard) {
                 error_report("--discard can only be specified once");
                 exit(EXIT_FAILURE);
             }
             seen_discard = true;
             if (bdrv_parse_discard_flags(optarg, &flags) == -1) {
                 error_report("Invalid discard mode `%s'", optarg);
                 exit(EXIT_FAILURE);
             }
             break;
         case QEMU_NBD_OPT_DETECT_ZEROES:
             detect_zeroes =
                 qapi_enum_parse(&BlockdevDetectZeroesOptions_lookup,
                                 optarg,
                                 BLOCKDEV_DETECT_ZEROES_OPTIONS_OFF,
                                 &local_err);
             if (local_err) {
                 error_reportf_err(local_err,
                                   "Failed to parse detect_zeroes mode: ");
                 exit(EXIT_FAILURE);
             }
             if (detect_zeroes == BLOCKDEV_DETECT_ZEROES_OPTIONS_UNMAP &&
                 !(flags & BDRV_O_UNMAP)) {
                 error_report("setting detect-zeroes to unmap is not allowed "
                              "without setting discard operation to unmap");
                 exit(EXIT_FAILURE);
             }
             break;
         case 'b':
             bindto = optarg;
             break;
         case 'p':
             port = optarg;
             break;
         case 'o':
             if (qemu_strtou64(optarg, NULL, 0, &dev_offset) < 0) {
                 error_report("Invalid offset '%s'", optarg);
                 exit(EXIT_FAILURE);
             }
             break;
         case 'l':
             if (strstart(optarg, SNAPSHOT_OPT_BASE, NULL)) {
                 sn_opts = qemu_opts_parse_noisily(&internal_snapshot_opts,
                                                   optarg, false);
                 if (!sn_opts) {
                     error_report("Failed in parsing snapshot param `%s'",
                                  optarg);
                     exit(EXIT_FAILURE);
                 }
             } else {
                 sn_id_or_name = optarg;
             }
-            /* fall through */
+            fallthrough;
         case 'r':
             readonly = true;
             flags &= ~BDRV_O_RDWR;
             break;
         case 'A':
             alloc_depth = true;
             break;
         case 'B':
             {
                 BlockDirtyBitmapOrStr *el = g_new(BlockDirtyBitmapOrStr, 1);
                 *el = (BlockDirtyBitmapOrStr) {
                     .type = QTYPE_QSTRING,
                     .u.local = g_strdup(optarg),
                 };
                 QAPI_LIST_PREPEND(bitmaps, el);
             }
             break;
         case 'k':
             sockpath = optarg;
             if (sockpath[0] != '/') {
                 error_report("socket path must be absolute");
                 exit(EXIT_FAILURE);
             }
             break;
         case 'd':
             disconnect = true;
             break;
         case 'c':
             opts.device = optarg;
             break;
         case 'e':
             if (qemu_strtoi(optarg, NULL, 0, &shared) < 0 ||
                 shared < 0) {
                 error_report("Invalid shared device number '%s'", optarg);
                 exit(EXIT_FAILURE);
             }
             break;
         case 'f':
             fmt = optarg;
             break;
         case 't':
             persistent = 1;
             break;
         case 'x':
             export_name = optarg;
             if (strlen(export_name) > NBD_MAX_STRING_SIZE) {
                 error_report("export name '%s' too long", export_name);
                 exit(EXIT_FAILURE);
             }
             break;
         case 'D':
             export_description = optarg;
             if (strlen(export_description) > NBD_MAX_STRING_SIZE) {
                 error_report("export description '%s' too long",
                              export_description);
                 exit(EXIT_FAILURE);
             }
             break;
         case 'v':
             opts.verbose = true;
             break;
         case 'V':
             version(argv[0]);
             exit(0);
             break;
         case 'h':
             usage(argv[0]);
             exit(0);
             break;
         case '?':
             error_report("Try `%s --help' for more information.", argv[0]);
             exit(EXIT_FAILURE);
         case QEMU_NBD_OPT_OBJECT:
             user_creatable_process_cmdline(optarg);
             break;
         case QEMU_NBD_OPT_TLSCREDS:
             tlscredsid = optarg;
             break;
         case QEMU_NBD_OPT_TLSHOSTNAME:
             tlshostname = optarg;
             break;
         case QEMU_NBD_OPT_IMAGE_OPTS:
             imageOpts = true;
             break;
         case 'T':
             trace_opt_parse(optarg);
             break;
         case QEMU_NBD_OPT_TLSAUTHZ:
             tlsauthz = optarg;
             break;
         case QEMU_NBD_OPT_FORK:
             opts.fork_process = true;
             break;
         case 'L':
             list = true;
             break;
         case QEMU_NBD_OPT_PID_FILE:
             pid_file_name = optarg;
             break;
         case QEMU_NBD_OPT_SELINUX_LABEL:
             selinux_label = optarg;
             break;
         }
     }
 
     if (list) {
         if (argc != optind) {
             error_report("List mode is incompatible with a file name");
             exit(EXIT_FAILURE);
         }
         if (export_name || export_description || dev_offset ||
             opts.device || disconnect || fmt || sn_id_or_name || bitmaps ||
             alloc_depth || seen_aio || seen_discard || seen_cache) {
             error_report("List mode is incompatible with per-device settings");
             exit(EXIT_FAILURE);
         }
         if (opts.fork_process) {
             error_report("List mode is incompatible with forking");
             exit(EXIT_FAILURE);
         }
     } else if ((argc - optind) != 1) {
         error_report("Invalid number of arguments");
         error_printf("Try `%s --help' for more information.\n", argv[0]);
         exit(EXIT_FAILURE);
     } else if (!export_name) {
         export_name = "";
     }
 
     if (!trace_init_backends()) {
         exit(1);
     }
     trace_init_file();
     qemu_set_log(LOG_TRACE, &error_fatal);
 
     socket_activation = check_socket_activation();
     if (socket_activation == 0) {
         if (!sockpath) {
             setup_address_and_port(&bindto, &port);
         }
     } else {
         /* Using socket activation - check user didn't use -p etc. */
         const char *err_msg = socket_activation_validate_opts(opts.device,
                                                               sockpath,
                                                               bindto, port,
                                                               selinux_label,
                                                               list);
         if (err_msg != NULL) {
             error_report("%s", err_msg);
             exit(EXIT_FAILURE);
         }
 
         /* qemu-nbd can only listen on a single socket.  */
         if (socket_activation > 1) {
             error_report("qemu-nbd does not support socket activation with %s > 1",
                          "LISTEN_FDS");
             exit(EXIT_FAILURE);
         }
     }
 
     if (tlscredsid) {
         if (opts.device) {
             error_report("TLS is not supported with a host device");
             exit(EXIT_FAILURE);
         }
         if (tlsauthz && list) {
             error_report("TLS authorization is incompatible with export list");
             exit(EXIT_FAILURE);
         }
         if (tlshostname && !list) {
             error_report("TLS hostname is only supported with export list");
             exit(EXIT_FAILURE);
         }
         tlscreds = nbd_get_tls_creds(tlscredsid, list, &local_err);
         if (local_err) {
             error_reportf_err(local_err, "Failed to get TLS creds: ");
             exit(EXIT_FAILURE);
         }
     } else {
         if (tlsauthz) {
             error_report("--tls-authz is not permitted without --tls-creds");
             exit(EXIT_FAILURE);
         }
         if (tlshostname) {
             error_report("--tls-hostname is not permitted without --tls-creds");
             exit(EXIT_FAILURE);
         }
     }
 
     if (selinux_label) {
 #ifdef CONFIG_SELINUX
         if (sockpath == NULL && opts.device == NULL) {
             error_report("--selinux-label is not permitted without --socket");
             exit(EXIT_FAILURE);
         }
 #else
         error_report("SELinux support not enabled in this binary");
         exit(EXIT_FAILURE);
 #endif
     }
 
     if (list) {
         opts.saddr = nbd_build_socket_address(sockpath, bindto, port);
         return qemu_nbd_client_list(opts.saddr, tlscreds,
                                     tlshostname ? tlshostname : bindto);
     }
 
 #if !HAVE_NBD_DEVICE
     if (disconnect || opts.device) {
         error_report("Kernel /dev/nbdN support not available");
         exit(EXIT_FAILURE);
     }
 #else /* HAVE_NBD_DEVICE */
     if (disconnect) {
         int nbdfd = open(argv[optind], O_RDWR);
         if (nbdfd < 0) {
             error_report("Cannot open %s: %s", argv[optind],
                          strerror(errno));
             exit(EXIT_FAILURE);
         }
         nbd_disconnect(nbdfd);
 
         close(nbdfd);
 
         printf("%s disconnected\n", argv[optind]);
 
         return 0;
     }
 #endif
 
     if ((opts.device && !opts.verbose) || opts.fork_process) {
 #ifndef WIN32
         g_autoptr(GError) err = NULL;
         int stderr_fd[2];
         pid_t pid;
 
         if (!g_unix_open_pipe(stderr_fd, FD_CLOEXEC, &err)) {
             error_report("Error setting up communication pipe: %s",
                          err->message);
             exit(EXIT_FAILURE);
         }
 
         /* Now daemonize, but keep a communication channel open to
          * print errors and exit with the proper status code.
          */
         pid = fork();
         if (pid < 0) {
             error_report("Failed to fork: %s", strerror(errno));
             exit(EXIT_FAILURE);
         } else if (pid == 0) {
             int saved_errno;
 
             close(stderr_fd[0]);
 
             /* Remember parent's stderr if we will be restoring it. */
             if (opts.verbose /* fork_process is set */) {
                 opts.old_stderr = dup(STDERR_FILENO);
                 if (opts.old_stderr < 0) {
                     error_report("Could not dup original stderr: %s",
                                  strerror(errno));
                     exit(EXIT_FAILURE);
                 }
             }
 
             ret = qemu_daemon(1, 0);
             saved_errno = errno;    /* dup2 will overwrite error below */
 
             /* Temporarily redirect stderr to the parent's pipe...  */
             if (dup2(stderr_fd[1], STDERR_FILENO) < 0) {
                 char str[256];
                 snprintf(str, sizeof(str),
                          "%s: Failed to link stderr to the pipe: %s\n",
                          g_get_prgname(), strerror(errno));
                 /*
                  * We are unable to use error_report() here as we need to get
                  * stderr pointed to the parent's pipe. Write to that pipe
                  * manually.
                  */
                 ret = write(stderr_fd[1], str, strlen(str));
                 exit(EXIT_FAILURE);
             }
 
             if (ret < 0) {
                 error_report("Failed to daemonize: %s", strerror(saved_errno));
                 exit(EXIT_FAILURE);
             }
 
             /* ... close the descriptor we inherited and go on.  */
             close(stderr_fd[1]);
         } else {
             bool errors = false;
             char *buf;
 
             /* In the parent.  Print error messages from the child until
              * it closes the pipe.
              */
             close(stderr_fd[1]);
             buf = g_malloc(1024);
             while ((ret = read(stderr_fd[0], buf, 1024)) > 0) {
                 errors = true;
                 ret = qemu_write_full(STDERR_FILENO, buf, ret);
                 if (ret < 0) {
                     exit(EXIT_FAILURE);
                 }
             }
             if (ret < 0) {
                 error_report("Cannot read from daemon: %s",
                              strerror(errno));
                 exit(EXIT_FAILURE);
             }
 
             /* Usually the daemon should not print any message.
              * Exit with zero status in that case.
              */
             exit(errors);
         }
 #else /* WIN32 */
         error_report("Unable to fork into background on Windows hosts");
         exit(EXIT_FAILURE);
 #endif /* WIN32 */
     }
 
     if (opts.device != NULL && sockpath == NULL) {
         sockpath = g_malloc(128);
         snprintf(sockpath, 128, SOCKET_PATH, basename(opts.device));
     }
 
     server = qio_net_listener_new();
     if (socket_activation == 0) {
         int backlog;
 
         if (persistent || shared == 0) {
             backlog = SOMAXCONN;
         } else {
             backlog = MIN(shared, SOMAXCONN);
         }
 #ifdef CONFIG_SELINUX
         if (selinux_label && setsockcreatecon_raw(selinux_label) == -1) {
             error_report("Cannot set SELinux socket create context to %s: %s",
                          selinux_label, strerror(errno));
             exit(EXIT_FAILURE);
         }
 #endif
         opts.saddr = nbd_build_socket_address(sockpath, bindto, port);
         if (qio_net_listener_open_sync(server, opts.saddr, backlog,
                                        &local_err) < 0) {
             object_unref(OBJECT(server));
             error_report_err(local_err);
             exit(EXIT_FAILURE);
         }
 #ifdef CONFIG_SELINUX
         if (selinux_label && setsockcreatecon_raw(NULL) == -1) {
             error_report("Cannot clear SELinux socket create context: %s",
                          strerror(errno));
             exit(EXIT_FAILURE);
         }
 #endif
     } else {
         size_t i;
         /* See comment in check_socket_activation above. */
         for (i = 0; i < socket_activation; i++) {
             QIOChannelSocket *sioc;
             sioc = qio_channel_socket_new_fd(FIRST_SOCKET_ACTIVATION_FD + i,
                                              &local_err);
             if (sioc == NULL) {
                 object_unref(OBJECT(server));
                 error_reportf_err(local_err,
                                   "Failed to use socket activation: ");
                 exit(EXIT_FAILURE);
             }
             qio_net_listener_add(server, sioc);
             object_unref(OBJECT(sioc));
         }
     }
 
     qemu_init_main_loop(&error_fatal);
     bdrv_init();
     atexit(qemu_nbd_shutdown);
 
     opts.srcpath = argv[optind];
     if (imageOpts) {
         QemuOpts *o;
         if (fmt) {
             error_report("--image-opts and -f are mutually exclusive");
             exit(EXIT_FAILURE);
         }
         o = qemu_opts_parse_noisily(&file_opts, opts.srcpath, true);
         if (!o) {
             qemu_opts_reset(&file_opts);
             exit(EXIT_FAILURE);
         }
         options = qemu_opts_to_qdict(o, NULL);
         qemu_opts_reset(&file_opts);
         blk = blk_new_open(NULL, NULL, options, flags, &local_err);
     } else {
         if (fmt) {
             options = qdict_new();
             qdict_put_str(options, "driver", fmt);
         }
         blk = blk_new_open(opts.srcpath, NULL, options, flags, &local_err);
     }
 
     if (!blk) {
         error_reportf_err(local_err, "Failed to blk_new_open '%s': ",
                           argv[optind]);
         exit(EXIT_FAILURE);
     }
     bs = blk_bs(blk);
 
     if (dev_offset) {
         QDict *raw_opts = qdict_new();
         qdict_put_str(raw_opts, "driver", "raw");
         qdict_put_str(raw_opts, "file", bs->node_name);
         qdict_put_int(raw_opts, "offset", dev_offset);
 
         aio_context_acquire(qemu_get_aio_context());
         bs = bdrv_open(NULL, NULL, raw_opts, flags, &error_fatal);
         aio_context_release(qemu_get_aio_context());
 
         blk_remove_bs(blk);
         blk_insert_bs(blk, bs, &error_fatal);
         bdrv_unref(bs);
     }
 
     blk_set_enable_write_cache(blk, !writethrough);
 
     if (sn_opts) {
         ret = bdrv_snapshot_load_tmp(bs,
                                      qemu_opt_get(sn_opts, SNAPSHOT_OPT_ID),
                                      qemu_opt_get(sn_opts, SNAPSHOT_OPT_NAME),
                                      &local_err);
     } else if (sn_id_or_name) {
         ret = bdrv_snapshot_load_tmp_by_id_or_name(bs, sn_id_or_name,
                                                    &local_err);
     }
     if (ret < 0) {
         error_reportf_err(local_err, "Failed to load snapshot: ");
         exit(EXIT_FAILURE);
     }
 
     bs->detect_zeroes = detect_zeroes;
 
     nbd_server_is_qemu_nbd(shared);
 
     export_opts = g_new(BlockExportOptions, 1);
     *export_opts = (BlockExportOptions) {
         .type               = BLOCK_EXPORT_TYPE_NBD,
         .id                 = g_strdup("qemu-nbd-export"),
         .node_name          = g_strdup(bdrv_get_node_name(bs)),
         .has_writethrough   = true,
         .writethrough       = writethrough,
         .has_writable       = true,
         .writable           = !readonly,
         .u.nbd = {
             .name                 = g_strdup(export_name),
             .description          = g_strdup(export_description),
             .has_bitmaps          = !!bitmaps,
             .bitmaps              = bitmaps,
             .has_allocation_depth = alloc_depth,
             .allocation_depth     = alloc_depth,
         },
     };
     blk_exp_add(export_opts, &error_fatal);
     qapi_free_BlockExportOptions(export_opts);
 
     if (opts.device) {
 #if HAVE_NBD_DEVICE
         ret = pthread_create(&client_thread, NULL, nbd_client_thread, &opts);
         if (ret != 0) {
             error_report("Failed to create client thread: %s", strerror(ret));
             exit(EXIT_FAILURE);
         }
 #endif
     } else {
         /* Shut up GCC warnings.  */
         memset(&client_thread, 0, sizeof(client_thread));
     }
 
     nbd_update_server_watch();
 
     if (pid_file_name) {
         qemu_write_pidfile(pid_file_name, &error_fatal);
     }
 
     /* now when the initialization is (almost) complete, chdir("/")
      * to free any busy filesystems */
     if (chdir("/") < 0) {
         error_report("Could not chdir to root directory: %s",
                      strerror(errno));
         exit(EXIT_FAILURE);
     }
 
     if (opts.fork_process) {
         nbd_client_release_pipe(opts.old_stderr);
     }
 
     state = RUNNING;
     do {
         main_loop_wait(false);
         if (state == TERMINATE) {
             blk_exp_close_all();
             state = TERMINATED;
         }
     } while (state != TERMINATED);
 
     blk_unref(blk);
     if (sockpath) {
         unlink(sockpath);
     }
 
     qemu_opts_del(sn_opts);
 
     if (opts.device) {
         void *result;
         pthread_join(client_thread, &result);
         ret = (intptr_t)result;
         exit(ret);
     } else {
         exit(EXIT_SUCCESS);
     }
 }
Signature · 1 line
2.39.2
#64 lore raw

RFC PATCH v2 54/78 hw/core: add fallthrough pseudo-keyword

In reply to Emmanouil Pitsidianakis

In preparation of raising -Wimplicit-fallthrough to 5, replace all fall-through comments with the fallthrough attribute pseudo-keyword.

---
 hw/core/loader.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/core/loader.c +1 -1
index 4dd5a71fb7..559d63a1e2 100644
@@ -625,138 +625,138 @@ toosmall:
 /* Load a U-Boot image.  */
 static ssize_t load_uboot_image(const char *filename, hwaddr *ep,
                                 hwaddr *loadaddr, int *is_linux,
                                 uint8_t image_type,
                                 uint64_t (*translate_fn)(void *, uint64_t),
                                 void *translate_opaque, AddressSpace *as)
 {
     int fd;
     ssize_t size;
     hwaddr address;
     uboot_image_header_t h;
     uboot_image_header_t *hdr = &h;
     uint8_t *data = NULL;
     int ret = -1;
     int do_uncompress = 0;
 
     fd = open(filename, O_RDONLY | O_BINARY);
     if (fd < 0)
         return -1;
 
     size = read(fd, hdr, sizeof(uboot_image_header_t));
     if (size < sizeof(uboot_image_header_t)) {
         goto out;
     }
 
     bswap_uboot_header(hdr);
 
     if (hdr->ih_magic != IH_MAGIC)
         goto out;
 
     if (hdr->ih_type != image_type) {
         if (!(image_type == IH_TYPE_KERNEL &&
             hdr->ih_type == IH_TYPE_KERNEL_NOLOAD)) {
             fprintf(stderr, "Wrong image type %d, expected %d\n", hdr->ih_type,
                     image_type);
             goto out;
         }
     }
 
     /* TODO: Implement other image types.  */
     switch (hdr->ih_type) {
     case IH_TYPE_KERNEL_NOLOAD:
         if (!loadaddr || *loadaddr == LOAD_UIMAGE_LOADADDR_INVALID) {
             fprintf(stderr, "this image format (kernel_noload) cannot be "
                     "loaded on this machine type");
             goto out;
         }
 
         hdr->ih_load = *loadaddr + sizeof(*hdr);
         hdr->ih_ep += hdr->ih_load;
-        /* fall through */
+        fallthrough;
     case IH_TYPE_KERNEL:
         address = hdr->ih_load;
         if (translate_fn) {
             address = translate_fn(translate_opaque, address);
         }
         if (loadaddr) {
             *loadaddr = hdr->ih_load;
         }
 
         switch (hdr->ih_comp) {
         case IH_COMP_NONE:
             break;
         case IH_COMP_GZIP:
             do_uncompress = 1;
             break;
         default:
             fprintf(stderr,
                     "Unable to load u-boot images with compression type %d\n",
                     hdr->ih_comp);
             goto out;
         }
 
         if (ep) {
             *ep = hdr->ih_ep;
         }
 
         /* TODO: Check CPU type.  */
         if (is_linux) {
             if (hdr->ih_os == IH_OS_LINUX) {
                 *is_linux = 1;
             } else if (hdr->ih_os == IH_OS_VXWORKS) {
                 /*
                  * VxWorks 7 uses the same boot interface as the Linux kernel
                  * on Arm (64-bit only), PowerPC and RISC-V architectures.
                  */
                 switch (hdr->ih_arch) {
                 case IH_ARCH_ARM64:
                 case IH_ARCH_PPC:
                 case IH_ARCH_RISCV:
                     *is_linux = 1;
                     break;
                 default:
                     *is_linux = 0;
                     break;
                 }
             } else {
                 *is_linux = 0;
             }
         }
 
         break;
     case IH_TYPE_RAMDISK:
         address = *loadaddr;
         break;
     default:
         fprintf(stderr, "Unsupported u-boot image type %d\n", hdr->ih_type);
         goto out;
     }
 
     data = g_malloc(hdr->ih_size);
 
     if (read(fd, data, hdr->ih_size) != hdr->ih_size) {
         fprintf(stderr, "Error reading file\n");
         goto out;
     }
 
     if (do_uncompress) {
         uint8_t *compressed_data;
         size_t max_bytes;
         ssize_t bytes;
 
         compressed_data = data;
         max_bytes = UBOOT_MAX_GUNZIP_BYTES;
         data = g_malloc(max_bytes);
 
         bytes = gunzip(data, max_bytes, compressed_data, hdr->ih_size);
         g_free(compressed_data);
         if (bytes < 0) {
             fprintf(stderr, "Unable to decompress gzipped image!\n");
             goto out;
         }
         hdr->ih_size = bytes;
     }
 
     rom_add_blob_fixed_as(filename, data, hdr->ih_size, address, as);
 
     ret = hdr->ih_size;
Signature · 1 line
2.39.2
#65 lore raw

RFC PATCH v2 55/78 hw/display: add fallthrough pseudo-keyword

In reply to Emmanouil Pitsidianakis

In preparation of raising -Wimplicit-fallthrough to 5, replace all fall-through comments with the fallthrough attribute pseudo-keyword.

---
 hw/display/cg3.c        | 2 +-
 hw/display/cirrus_vga.c | 2 +-
 hw/display/tcx.c        | 4 ++--
 3 files changed, 4 insertions(+), 4 deletions(-)
hw/display/cg3.c +1 -1
index 2e9656ae1c..53eb9831b2 100644
@@ -199,65 +199,65 @@ static uint64_t cg3_reg_read(void *opaque, hwaddr addr, unsigned size)
 static void cg3_reg_write(void *opaque, hwaddr addr, uint64_t val,
                           unsigned size)
 {
     CG3State *s = opaque;
     uint8_t regval;
     int i;
 
     trace_cg3_write(addr, val, size);
     switch (addr) {
     case CG3_REG_BT458_ADDR:
         s->dac_index = val;
         s->dac_state = 0;
         break;
     case CG3_REG_BT458_COLMAP:
         /* This register can be written to as either a long word or a byte */
         if (size == 1) {
             val <<= 24;
         }
 
         for (i = 0; i < size; i++) {
             regval = val >> 24;
 
             switch (s->dac_state) {
             case 0:
                 s->r[s->dac_index] = regval;
                 s->dac_state++;
                 break;
             case 1:
                 s->g[s->dac_index] = regval;
                 s->dac_state++;
                 break;
             case 2:
                 s->b[s->dac_index] = regval;
                 /* Index autoincrement */
                 s->dac_index = (s->dac_index + 1) & 0xff;
-                /* fall through */
+                fallthrough;
             default:
                 s->dac_state = 0;
                 break;
             }
             val <<= 8;
         }
         s->full_update = 1;
         break;
     case CG3_REG_FBC_CTRL:
         s->regs[0] = val;
         break;
     case CG3_REG_FBC_STATUS:
         if (s->regs[1] & CG3_SR_PENDING_INT) {
             /* clear interrupt */
             s->regs[1] &= ~CG3_SR_PENDING_INT;
             qemu_irq_lower(s->irq);
         }
         break;
     case CG3_REG_FBC_CURSTART ... CG3_REG_SIZE - 1:
         s->regs[addr - 0x10] = val;
         break;
     default:
         qemu_log_mask(LOG_UNIMP,
                   "cg3: Unimplemented register write "
                   "reg 0x%" HWADDR_PRIx " size 0x%x value 0x%" PRIx64 "\n",
                   addr, size, val);
         break;
     }
 }
hw/display/cirrus_vga.c +1 -1
index b80f98b6c4..f1513a084c 100644
@@ -1319,97 +1319,97 @@ static int cirrus_vga_read_sr(CirrusVGAState * s)
 static void cirrus_vga_write_sr(CirrusVGAState * s, uint32_t val)
 {
     switch (s->vga.sr_index) {
     case 0x00:                  // Standard VGA
     case 0x01:                  // Standard VGA
     case 0x02:                  // Standard VGA
     case 0x03:                  // Standard VGA
     case 0x04:                  // Standard VGA
         s->vga.sr[s->vga.sr_index] = val & sr_mask[s->vga.sr_index];
         if (s->vga.sr_index == 1)
             s->vga.update_retrace_info(&s->vga);
         break;
     case 0x06:                  // Unlock Cirrus extensions
         val &= 0x17;
         if (val == 0x12) {
             s->vga.sr[s->vga.sr_index] = 0x12;
         } else {
             s->vga.sr[s->vga.sr_index] = 0x0f;
         }
         break;
     case 0x10:
     case 0x30:
     case 0x50:
     case 0x70:                  // Graphics Cursor X
     case 0x90:
     case 0xb0:
     case 0xd0:
     case 0xf0:                  // Graphics Cursor X
         s->vga.sr[0x10] = val;
         s->vga.hw_cursor_x = (val << 3) | (s->vga.sr_index >> 5);
         break;
     case 0x11:
     case 0x31:
     case 0x51:
     case 0x71:                  // Graphics Cursor Y
     case 0x91:
     case 0xb1:
     case 0xd1:
     case 0xf1:                  // Graphics Cursor Y
         s->vga.sr[0x11] = val;
         s->vga.hw_cursor_y = (val << 3) | (s->vga.sr_index >> 5);
         break;
     case 0x07:                  // Extended Sequencer Mode
         cirrus_update_memory_access(s);
-        /* fall through */
+        fallthrough;
     case 0x08:                  // EEPROM Control
     case 0x09:                  // Scratch Register 0
     case 0x0a:                  // Scratch Register 1
     case 0x0b:                  // VCLK 0
     case 0x0c:                  // VCLK 1
     case 0x0d:                  // VCLK 2
     case 0x0e:                  // VCLK 3
     case 0x0f:                  // DRAM Control
     case 0x13:                  // Graphics Cursor Pattern Address
     case 0x14:                  // Scratch Register 2
     case 0x15:                  // Scratch Register 3
     case 0x16:                  // Performance Tuning Register
     case 0x18:                  // Signature Generator Control
     case 0x19:                  // Signature Generator Result
     case 0x1a:                  // Signature Generator Result
     case 0x1b:                  // VCLK 0 Denominator & Post
     case 0x1c:                  // VCLK 1 Denominator & Post
     case 0x1d:                  // VCLK 2 Denominator & Post
     case 0x1e:                  // VCLK 3 Denominator & Post
     case 0x1f:                  // BIOS Write Enable and MCLK select
         s->vga.sr[s->vga.sr_index] = val;
 #ifdef DEBUG_CIRRUS
         printf("cirrus: handled outport sr_index %02x, sr_value %02x\n",
                s->vga.sr_index, val);
 #endif
         break;
     case 0x12:                  // Graphics Cursor Attribute
         s->vga.sr[0x12] = val;
         s->vga.force_shadow = !!(val & CIRRUS_CURSOR_SHOW);
 #ifdef DEBUG_CIRRUS
         printf("cirrus: cursor ctl SR12=%02x (force shadow: %d)\n",
                val, s->vga.force_shadow);
 #endif
         break;
     case 0x17:                  // Configuration Readback and Extended Control
         s->vga.sr[s->vga.sr_index] = (s->vga.sr[s->vga.sr_index] & 0x38)
                                    | (val & 0xc7);
         cirrus_update_memory_access(s);
         break;
     default:
         qemu_log_mask(LOG_GUEST_ERROR,
                       "cirrus: outport sr_index 0x%02x, sr_value 0x%02x\n",
                       s->vga.sr_index, val);
         break;
     }
 }
 
 /***************************************
  *
  *  I/O access at 0x3c6
  *
  ***************************************/
hw/display/tcx.c +2 -2
index 1b27b64f6d..e21450d726 100644
@@ -381,26 +381,26 @@ static void tcx_reset(DeviceState *d)
 static uint64_t tcx_dac_readl(void *opaque, hwaddr addr,
                               unsigned size)
 {
     TCXState *s = opaque;
     uint32_t val = 0;
 
     switch (s->dac_state) {
     case 0:
         val = s->r[s->dac_index] << 24;
         s->dac_state++;
         break;
     case 1:
         val = s->g[s->dac_index] << 24;
         s->dac_state++;
         break;
     case 2:
         val = s->b[s->dac_index] << 24;
         s->dac_index = (s->dac_index + 1) & 0xff; /* Index autoincrement */
-        /* fall through */
+        fallthrough;
     default:
         s->dac_state = 0;
         break;
     }
 
     return val;
 }
@@ -408,43 +408,43 @@ static uint64_t tcx_dac_readl(void *opaque, hwaddr addr,
 static void tcx_dac_writel(void *opaque, hwaddr addr, uint64_t val,
                            unsigned size)
 {
     TCXState *s = opaque;
     unsigned index;
 
     switch (addr) {
     case 0: /* Address */
         s->dac_index = val >> 24;
         s->dac_state = 0;
         break;
     case 4:  /* Pixel colours */
     case 12: /* Overlay (cursor) colours */
         if (addr & 8) {
             index = (s->dac_index & 3) + 256;
         } else {
             index = s->dac_index;
         }
         switch (s->dac_state) {
         case 0:
             s->r[index] = val >> 24;
             update_palette_entries(s, index, index + 1);
             s->dac_state++;
             break;
         case 1:
             s->g[index] = val >> 24;
             update_palette_entries(s, index, index + 1);
             s->dac_state++;
             break;
         case 2:
             s->b[index] = val >> 24;
             update_palette_entries(s, index, index + 1);
             s->dac_index = (s->dac_index + 1) & 0xff; /* Index autoincrement */
-            /* fall through */
+            fallthrough;
         default:
             s->dac_state = 0;
             break;
         }
         break;
     default: /* Control registers */
         break;
     }
 }
Signature · 1 line
2.39.2
#66 lore raw

RFC PATCH v2 56/78 hw/input: add fallthrough pseudo-keyword

In reply to Emmanouil Pitsidianakis

In preparation of raising -Wimplicit-fallthrough to 5, replace all fall-through comments with the fallthrough attribute pseudo-keyword.

---
 hw/input/hid.c     | 3 ++-
 hw/input/tsc2005.c | 4 ++--
 hw/input/tsc210x.c | 2 +-
 3 files changed, 5 insertions(+), 4 deletions(-)
hw/input/hid.c +2 -1
index a9c7dd1ce1..15fffc5dfb 100644
@@ -250,88 +250,89 @@ static void hid_keyboard_event(DeviceState *dev, QemuConsole *src,
 static void hid_keyboard_process_keycode(HIDState *hs)
 {
     uint8_t hid_code, index, key;
     int i, keycode, slot;
 
     if (hs->n == 0) {
         return;
     }
     slot = hs->head & QUEUE_MASK; QUEUE_INCR(hs->head); hs->n--;
     keycode = hs->kbd.keycodes[slot];
 
     if (!hs->n) {
         trace_hid_kbd_queue_empty();
     }
 
     key = keycode & 0x7f;
     index = key | ((hs->kbd.modifiers & (1 << 8)) >> 1);
     hid_code = hid_usage_keys[index];
     hs->kbd.modifiers &= ~(1 << 8);
 
     switch (hid_code) {
     case 0x00:
         return;
 
     case 0xe0:
         assert(key == 0x1d);
         if (hs->kbd.modifiers & (1 << 9)) {
             /* The hid_codes for the 0xe1/0x1d scancode sequence are 0xe9/0xe0.
              * Here we're processing the second hid_code.  By dropping bit 9
              * and setting bit 8, the scancode after 0x1d will access the
              * second half of the table.
              */
             hs->kbd.modifiers ^= (1 << 8) | (1 << 9);
             return;
         }
         /* fall through to process Ctrl_L */
+        fallthrough;
     case 0xe1 ... 0xe7:
         /* Ctrl_L/Ctrl_R, Shift_L/Shift_R, Alt_L/Alt_R, Win_L/Win_R.
          * Handle releases here, or fall through to process presses.
          */
         if (keycode & (1 << 7)) {
             hs->kbd.modifiers &= ~(1 << (hid_code & 0x0f));
             return;
         }
-        /* fall through */
+        fallthrough;
     case 0xe8 ... 0xe9:
         /* USB modifiers are just 1 byte long.  Bits 8 and 9 of
          * hs->kbd.modifiers implement a state machine that detects the
          * 0xe0 and 0xe1/0x1d sequences.  These bits do not follow the
          * usual rules where bit 7 marks released keys; they are cleared
          * elsewhere in the function as the state machine dictates.
          */
         hs->kbd.modifiers |= 1 << (hid_code & 0x0f);
         return;
 
     case 0xea ... 0xef:
         abort();
 
     default:
         break;
     }
 
     if (keycode & (1 << 7)) {
         for (i = hs->kbd.keys - 1; i >= 0; i--) {
             if (hs->kbd.key[i] == hid_code) {
                 hs->kbd.key[i] = hs->kbd.key[-- hs->kbd.keys];
                 hs->kbd.key[hs->kbd.keys] = 0x00;
                 break;
             }
         }
         if (i < 0) {
             return;
         }
     } else {
         for (i = hs->kbd.keys - 1; i >= 0; i--) {
             if (hs->kbd.key[i] == hid_code) {
                 break;
             }
         }
         if (i < 0) {
             if (hs->kbd.keys < sizeof(hs->kbd.key)) {
                 hs->kbd.key[hs->kbd.keys++] = hid_code;
             }
         } else {
             return;
         }
     }
 }
hw/input/tsc2005.c +2 -2
index db2b80e35f..4f3f1d9d12 100644
@@ -234,70 +234,70 @@ static void tsc2005_write(TSC2005State *s, int reg, uint16_t data)
 /* This handles most of the chip's logic.  */
 static void tsc2005_pin_update(TSC2005State *s)
 {
     int64_t expires;
     bool pin_state;
 
     switch (s->pin_func) {
     case 0:
         pin_state = !s->pressure && !!s->dav;
         break;
     case 1:
     case 3:
     default:
         pin_state = !s->dav;
         break;
     case 2:
         pin_state = !s->pressure;
     }
 
     if (pin_state != s->irq) {
         s->irq = pin_state;
         qemu_set_irq(s->pint, s->irq);
     }
 
     switch (s->nextfunction) {
     case TSC_MODE_XYZ_SCAN:
     case TSC_MODE_XY_SCAN:
         if (!s->host_mode && s->dav)
             s->enabled = false;
         if (!s->pressure)
             return;
-        /* Fall through */
+        fallthrough;
     case TSC_MODE_AUX_SCAN:
         break;
 
     case TSC_MODE_X:
     case TSC_MODE_Y:
     case TSC_MODE_Z:
         if (!s->pressure)
             return;
-        /* Fall through */
+        fallthrough;
     case TSC_MODE_AUX:
     case TSC_MODE_TEMP1:
     case TSC_MODE_TEMP2:
     case TSC_MODE_X_TEST:
     case TSC_MODE_Y_TEST:
     case TSC_MODE_TS_TEST:
         if (s->dav)
             s->enabled = false;
         break;
 
     case TSC_MODE_RESERVED:
     case TSC_MODE_XX_DRV:
     case TSC_MODE_YY_DRV:
     case TSC_MODE_YX_DRV:
     default:
         return;
     }
 
     if (!s->enabled || s->busy)
         return;
 
     s->busy = true;
     s->precision = s->nextprecision;
     s->function = s->nextfunction;
     s->pdst = !s->pnd0;	/* Synchronised on internal clock */
     expires = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) +
         (NANOSECONDS_PER_SECOND >> 7);
     timer_mod(s->timer, expires);
 }
hw/input/tsc210x.c +1 -1
index 950506fb38..9ae426e1a6 100644
@@ -774,70 +774,70 @@ static void tsc2102_audio_register_write(
 /* This handles most of the chip logic.  */
 static void tsc210x_pin_update(TSC210xState *s)
 {
     int64_t expires;
     bool pin_state;
 
     switch (s->pin_func) {
     case 0:
         pin_state = s->pressure;
         break;
     case 1:
         pin_state = !!s->dav;
         break;
     case 2:
     default:
         pin_state = s->pressure && !s->dav;
     }
 
     if (!s->enabled)
         pin_state = false;
 
     if (pin_state != s->irq) {
         s->irq = pin_state;
         qemu_set_irq(s->pint, !s->irq);
     }
 
     switch (s->nextfunction) {
     case TSC_MODE_XY_SCAN:
     case TSC_MODE_XYZ_SCAN:
         if (!s->pressure)
             return;
         break;
 
     case TSC_MODE_X:
     case TSC_MODE_Y:
     case TSC_MODE_Z:
         if (!s->pressure)
             return;
-        /* Fall through */
+        fallthrough;
     case TSC_MODE_BAT1:
     case TSC_MODE_BAT2:
     case TSC_MODE_AUX:
     case TSC_MODE_TEMP1:
     case TSC_MODE_TEMP2:
         if (s->dav)
             s->enabled = false;
         break;
 
     case TSC_MODE_AUX_SCAN:
     case TSC_MODE_PORT_SCAN:
         break;
 
     case TSC_MODE_NO_SCAN:
     case TSC_MODE_XX_DRV:
     case TSC_MODE_YY_DRV:
     case TSC_MODE_YX_DRV:
     default:
         return;
     }
 
     if (!s->enabled || s->busy || s->dav)
         return;
 
     s->busy = true;
     s->precision = s->nextprecision;
     s->function = s->nextfunction;
     expires = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) +
         (NANOSECONDS_PER_SECOND >> 10);
     timer_mod(s->timer, expires);
 }
Signature · 1 line
2.39.2
#67 lore raw

RFC PATCH v2 57/78 hw/net: add fallthrough pseudo-keyword

In reply to Emmanouil Pitsidianakis

In preparation of raising -Wimplicit-fallthrough to 5, replace all fall-through comments with the fallthrough attribute pseudo-keyword.

---
 hw/net/cadence_gem.c     | 4 ++--
 hw/net/can/can_sja1000.c | 4 ++--
 hw/net/igb_core.c        | 2 +-
 hw/net/igbvf.c           | 2 +-
 hw/net/imx_fec.c         | 2 +-
 hw/net/net_rx_pkt.c      | 2 +-
 hw/net/pcnet.c           | 2 +-
 hw/net/rtl8139.c         | 6 ++++--
 hw/net/xilinx_ethlite.c  | 2 +-
 9 files changed, 14 insertions(+), 12 deletions(-)
hw/net/cadence_gem.c +2 -2
index f445d8bb5e..a59991af5b 100644
@@ -748,119 +748,119 @@ static int gem_mac_address_filter(CadenceGEMState *s, const uint8_t *packet)
 /* Figure out which queue the received data should be sent to */
 static int get_queue_from_screen(CadenceGEMState *s, uint8_t *rxbuf_ptr,
                                  unsigned rxbufsize)
 {
     uint32_t reg;
     bool matched, mismatched;
     int i, j;
 
     for (i = 0; i < s->num_type1_screeners; i++) {
         reg = s->regs[GEM_SCREENING_TYPE1_REGISTER_0 + i];
         matched = false;
         mismatched = false;
 
         /* Screening is based on UDP Port */
         if (reg & GEM_ST1R_UDP_PORT_MATCH_ENABLE) {
             uint16_t udp_port = rxbuf_ptr[14 + 22] << 8 | rxbuf_ptr[14 + 23];
             if (udp_port == extract32(reg, GEM_ST1R_UDP_PORT_MATCH_SHIFT,
                                            GEM_ST1R_UDP_PORT_MATCH_WIDTH)) {
                 matched = true;
             } else {
                 mismatched = true;
             }
         }
 
         /* Screening is based on DS/TC */
         if (reg & GEM_ST1R_DSTC_ENABLE) {
             uint8_t dscp = rxbuf_ptr[14 + 1];
             if (dscp == extract32(reg, GEM_ST1R_DSTC_MATCH_SHIFT,
                                        GEM_ST1R_DSTC_MATCH_WIDTH)) {
                 matched = true;
             } else {
                 mismatched = true;
             }
         }
 
         if (matched && !mismatched) {
             return extract32(reg, GEM_ST1R_QUEUE_SHIFT, GEM_ST1R_QUEUE_WIDTH);
         }
     }
 
     for (i = 0; i < s->num_type2_screeners; i++) {
         reg = s->regs[GEM_SCREENING_TYPE2_REGISTER_0 + i];
         matched = false;
         mismatched = false;
 
         if (reg & GEM_ST2R_ETHERTYPE_ENABLE) {
             uint16_t type = rxbuf_ptr[12] << 8 | rxbuf_ptr[13];
             int et_idx = extract32(reg, GEM_ST2R_ETHERTYPE_INDEX_SHIFT,
                                         GEM_ST2R_ETHERTYPE_INDEX_WIDTH);
 
             if (et_idx > s->num_type2_screeners) {
                 qemu_log_mask(LOG_GUEST_ERROR, "Out of range ethertype "
                               "register index: %d\n", et_idx);
             }
             if (type == s->regs[GEM_SCREENING_TYPE2_ETHERTYPE_REG_0 +
                                 et_idx]) {
                 matched = true;
             } else {
                 mismatched = true;
             }
         }
 
         /* Compare A, B, C */
         for (j = 0; j < 3; j++) {
             uint32_t cr0, cr1, mask;
             uint16_t rx_cmp;
             int offset;
             int cr_idx = extract32(reg, GEM_ST2R_COMPARE_A_SHIFT + j * 6,
                                         GEM_ST2R_COMPARE_WIDTH);
 
             if (!(reg & (GEM_ST2R_COMPARE_A_ENABLE << (j * 6)))) {
                 continue;
             }
             if (cr_idx > s->num_type2_screeners) {
                 qemu_log_mask(LOG_GUEST_ERROR, "Out of range compare "
                               "register index: %d\n", cr_idx);
             }
 
             cr0 = s->regs[GEM_TYPE2_COMPARE_0_WORD_0 + cr_idx * 2];
             cr1 = s->regs[GEM_TYPE2_COMPARE_0_WORD_0 + cr_idx * 2 + 1];
             offset = extract32(cr1, GEM_T2CW1_OFFSET_VALUE_SHIFT,
                                     GEM_T2CW1_OFFSET_VALUE_WIDTH);
 
             switch (extract32(cr1, GEM_T2CW1_COMPARE_OFFSET_SHIFT,
                                    GEM_T2CW1_COMPARE_OFFSET_WIDTH)) {
             case 3: /* Skip UDP header */
                 qemu_log_mask(LOG_UNIMP, "TCP compare offsets"
                               "unimplemented - assuming UDP\n");
                 offset += 8;
-                /* Fallthrough */
+                fallthrough;
             case 2: /* skip the IP header */
                 offset += 20;
-                /* Fallthrough */
+                fallthrough;
             case 1: /* Count from after the ethertype */
                 offset += 14;
                 break;
             case 0:
                 /* Offset from start of frame */
                 break;
             }
 
             rx_cmp = rxbuf_ptr[offset] << 8 | rxbuf_ptr[offset];
             mask = extract32(cr0, 0, 16);
 
             if ((rx_cmp & mask) == (extract32(cr0, 16, 16) & mask)) {
                 matched = true;
             } else {
                 mismatched = true;
             }
         }
 
         if (matched && !mismatched) {
             return extract32(reg, GEM_ST2R_QUEUE_SHIFT, GEM_ST2R_QUEUE_WIDTH);
         }
     }
 
     /* We made it here, assume it's queue 0 */
     return 0;
 }
hw/net/can/can_sja1000.c +2 -2
index 73201f9139..14052b2700 100644
@@ -422,235 +422,235 @@ static void can_sja_update_bas_irq(CanSJA1000State *s)
 void can_sja_mem_write(CanSJA1000State *s, hwaddr addr, uint64_t val,
                        unsigned size)
 {
     qemu_can_frame   frame;
     uint32_t         tmp;
     uint8_t          tmp8, count;
 
 
     DPRINTF("write 0x%02llx addr 0x%02x\n",
             (unsigned long long)val, (unsigned int)addr);
 
     if (addr > CAN_SJA_MEM_SIZE) {
         return;
     }
 
     if (s->clock & 0x80) { /* PeliCAN Mode */
         switch (addr) {
         case SJA_MOD: /* Mode register */
             s->mode = 0x1f & val;
             if ((s->mode & 0x01) && ((val & 0x01) == 0)) {
                 /* Go to operation mode from reset mode. */
                 if (s->mode & (1 << 3)) { /* Single mode. */
                     /* For EFF */
                     can_sja_single_filter(&s->filter[0],
                         s->code_mask + 0, s->code_mask + 4, 1);
 
                     /* For SFF */
                     can_sja_single_filter(&s->filter[1],
                         s->code_mask + 0, s->code_mask + 4, 0);
 
                     can_bus_client_set_filters(&s->bus_client, s->filter, 2);
                 } else { /* Dual mode */
                     /* For EFF */
                     can_sja_dual_filter(&s->filter[0],
                         s->code_mask + 0, s->code_mask + 4, 1);
 
                     can_sja_dual_filter(&s->filter[1],
                         s->code_mask + 2, s->code_mask + 6, 1);
 
                     /* For SFF */
                     can_sja_dual_filter(&s->filter[2],
                         s->code_mask + 0, s->code_mask + 4, 0);
 
                     can_sja_dual_filter(&s->filter[3],
                         s->code_mask + 2, s->code_mask + 6, 0);
 
                     can_bus_client_set_filters(&s->bus_client, s->filter, 4);
                 }
 
                 s->rxmsg_cnt = 0;
                 s->rx_cnt = 0;
             }
             break;
 
         case SJA_CMR: /* Command register. */
             if (0x01 & val) { /* Send transmission request. */
                 buff2frame_pel(s->tx_buff, &frame);
                 if (DEBUG_FILTER) {
                     can_display_msg("[cansja]: Tx request " , &frame);
                 }
 
                 /*
                  * Clear transmission complete status,
                  * and Transmit Buffer Status.
                  * write to the backends.
                  */
                 s->status_pel &= ~(3 << 2);
 
                 can_bus_client_send(&s->bus_client, &frame, 1);
 
                 /*
                  * Set transmission complete status
                  * and Transmit Buffer Status.
                  */
                 s->status_pel |= (3 << 2);
 
                 /* Clear transmit status. */
                 s->status_pel &= ~(1 << 5);
                 s->interrupt_pel |= 0x02;
                 can_sja_update_pel_irq(s);
             }
             if (0x04 & val) { /* Release Receive Buffer */
                 if (s->rxmsg_cnt <= 0) {
                     break;
                 }
 
                 tmp8 = s->rx_buff[s->rxbuf_start]; count = 0;
                 if (tmp8 & (1 << 7)) { /* EFF */
                     count += 2;
                 }
                 count += 3;
                 if (!(tmp8 & (1 << 6))) { /* DATA */
                     count += (tmp8 & 0x0f);
                 }
 
                 if (DEBUG_FILTER) {
                     qemu_log("[cansja]: message released from "
                              "Rx FIFO cnt=%d, count=%d\n", s->rx_cnt, count);
                 }
 
                 s->rxbuf_start += count;
                 s->rxbuf_start %= SJA_RCV_BUF_LEN;
 
                 s->rx_cnt -= count;
                 s->rxmsg_cnt--;
                 if (s->rxmsg_cnt == 0) {
                     s->status_pel &= ~(1 << 0);
                     s->interrupt_pel &= ~(1 << 0);
                     can_sja_update_pel_irq(s);
                 }
             }
             if (0x08 & val) { /* Clear data overrun */
                 s->status_pel &= ~(1 << 1);
                 s->interrupt_pel &= ~(1 << 3);
                 can_sja_update_pel_irq(s);
             }
             break;
         case SJA_SR: /* Status register */
         case SJA_IR: /* Interrupt register */
             break; /* Do nothing */
         case SJA_IER: /* Interrupt enable register */
             s->interrupt_en = val;
             break;
         case 16: /* RX frame information addr16-28. */
             s->status_pel |= (1 << 5); /* Set transmit status. */
-            /* fallthrough */
+            fallthrough;
         case 17 ... 28:
             if (s->mode & 0x01) { /* Reset mode */
                 if (addr < 24) {
                     s->code_mask[addr - 16] = val;
                 }
             } else { /* Operation mode */
                 s->tx_buff[addr - 16] = val; /* Store to TX buffer directly. */
             }
             break;
         case SJA_CDR:
             s->clock = val;
             break;
         }
     } else { /* Basic Mode */
         switch (addr) {
         case SJA_BCAN_CTR: /* Control register, addr 0 */
             if ((s->control & 0x01) && ((val & 0x01) == 0)) {
                 /* Go to operation mode from reset mode. */
                 s->filter[0].can_id = (s->code << 3) & (0xff << 3);
                 tmp = (~(s->mask << 3)) & (0xff << 3);
                 tmp |= QEMU_CAN_EFF_FLAG; /* Only Basic CAN Frame. */
                 s->filter[0].can_mask = tmp;
                 can_bus_client_set_filters(&s->bus_client, s->filter, 1);
 
                 s->rxmsg_cnt = 0;
                 s->rx_cnt = 0;
             } else if (!(s->control & 0x01) && !(val & 0x01)) {
                 can_sja_software_reset(s);
             }
 
             s->control = 0x1f & val;
             break;
         case SJA_BCAN_CMR: /* Command register, addr 1 */
             if (0x01 & val) { /* Send transmission request. */
                 buff2frame_bas(s->tx_buff, &frame);
                 if (DEBUG_FILTER) {
                     can_display_msg("[cansja]: Tx request " , &frame);
                 }
 
                 /*
                  * Clear transmission complete status,
                  * and Transmit Buffer Status.
                  */
                 s->status_bas &= ~(3 << 2);
 
                 /* write to the backends. */
                 can_bus_client_send(&s->bus_client, &frame, 1);
 
                 /*
                  * Set transmission complete status,
                  * and Transmit Buffer Status.
                  */
                 s->status_bas |= (3 << 2);
 
                 /* Clear transmit status. */
                 s->status_bas &= ~(1 << 5);
                 s->interrupt_bas |= 0x02;
                 can_sja_update_bas_irq(s);
             }
             if (0x04 & val) { /* Release Receive Buffer */
                 if (s->rxmsg_cnt <= 0) {
                     break;
                 }
 
                 tmp8 = s->rx_buff[(s->rxbuf_start + 1) % SJA_RCV_BUF_LEN];
                 count = 2 + (tmp8 & 0x0f);
 
                 if (DEBUG_FILTER) {
                     qemu_log("[cansja]: message released from "
                              "Rx FIFO cnt=%d, count=%d\n", s->rx_cnt, count);
                 }
 
                 s->rxbuf_start += count;
                 s->rxbuf_start %= SJA_RCV_BUF_LEN;
                 s->rx_cnt -= count;
                 s->rxmsg_cnt--;
 
                 if (s->rxmsg_cnt == 0) {
                     s->status_bas &= ~(1 << 0);
                     s->interrupt_bas &= ~(1 << 0);
                     can_sja_update_bas_irq(s);
                 }
             }
             if (0x08 & val) { /* Clear data overrun */
                 s->status_bas &= ~(1 << 1);
                 s->interrupt_bas &= ~(1 << 3);
                 can_sja_update_bas_irq(s);
             }
             break;
         case 4:
             s->code = val;
             break;
         case 5:
             s->mask = val;
             break;
         case 10:
             s->status_bas |= (1 << 5); /* Set transmit status. */
-            /* fallthrough */
+            fallthrough;
         case 11 ... 19:
             if ((s->control & 0x01) == 0) { /* Operation mode */
                 s->tx_buff[addr - 10] = val; /* Store to TX buffer directly. */
             }
             break;
         case SJA_CDR:
             s->clock = val;
             break;
         }
     }
 }
hw/net/igb_core.c +1 -1
index f6a5e2327b..1117f7cb59 100644
@@ -1362,75 +1362,75 @@ static void
 igb_build_rx_metadata_common(IGBCore *core,
                              struct NetRxPkt *pkt,
                              bool is_eop,
                              uint32_t *status_flags,
                              uint16_t *vlan_tag)
 {
     struct virtio_net_hdr *vhdr;
     bool hasip4, hasip6, csum_valid;
     EthL4HdrProto l4hdr_proto;
 
     *status_flags = E1000_RXD_STAT_DD;
 
     /* No additional metadata needed for non-EOP descriptors */
     if (!is_eop) {
         goto func_exit;
     }
 
     *status_flags |= E1000_RXD_STAT_EOP;
 
     net_rx_pkt_get_protocols(pkt, &hasip4, &hasip6, &l4hdr_proto);
     trace_e1000e_rx_metadata_protocols(hasip4, hasip6, l4hdr_proto);
 
     /* VLAN state */
     if (net_rx_pkt_is_vlan_stripped(pkt)) {
         *status_flags |= E1000_RXD_STAT_VP;
         *vlan_tag = cpu_to_le16(net_rx_pkt_get_vlan_tag(pkt));
         trace_e1000e_rx_metadata_vlan(*vlan_tag);
     }
 
     /* RX CSO information */
     if (hasip6 && (core->mac[RFCTL] & E1000_RFCTL_IPV6_XSUM_DIS)) {
         trace_e1000e_rx_metadata_ipv6_sum_disabled();
         goto func_exit;
     }
 
     vhdr = net_rx_pkt_get_vhdr(pkt);
 
     if (!(vhdr->flags & VIRTIO_NET_HDR_F_DATA_VALID) &&
         !(vhdr->flags & VIRTIO_NET_HDR_F_NEEDS_CSUM)) {
         trace_e1000e_rx_metadata_virthdr_no_csum_info();
         igb_verify_csum_in_sw(core, pkt, status_flags, l4hdr_proto);
         goto func_exit;
     }
 
     if (igb_rx_l3_cso_enabled(core)) {
         *status_flags |= hasip4 ? E1000_RXD_STAT_IPCS : 0;
     } else {
         trace_e1000e_rx_metadata_l3_cso_disabled();
     }
 
     if (igb_rx_l4_cso_enabled(core)) {
         switch (l4hdr_proto) {
         case ETH_L4_HDR_PROTO_SCTP:
             if (!net_rx_pkt_validate_l4_csum(pkt, &csum_valid)) {
                 trace_e1000e_rx_metadata_l4_csum_validation_failed();
                 goto func_exit;
             }
             if (!csum_valid) {
                 *status_flags |= E1000_RXDEXT_STATERR_TCPE;
             }
-            /* fall through */
+            fallthrough;
         case ETH_L4_HDR_PROTO_TCP:
             *status_flags |= E1000_RXD_STAT_TCPCS;
             break;
 
         case ETH_L4_HDR_PROTO_UDP:
             *status_flags |= E1000_RXD_STAT_TCPCS | E1000_RXD_STAT_UDPCS;
             break;
 
         default:
             break;
         }
     } else {
         trace_e1000e_rx_metadata_l4_cso_disabled();
     }
hw/net/igbvf.c +1 -1
index d55e1e8a6a..ff68a4f3c5 100644
@@ -62,139 +62,139 @@ struct IgbVfState {
 static hwaddr vf_to_pf_addr(hwaddr addr, uint16_t vfn, bool write)
 {
     switch (addr) {
     case E1000_CTRL:
     case E1000_CTRL_DUP:
         return E1000_PVTCTRL(vfn);
     case E1000_EICS:
         return E1000_PVTEICS(vfn);
     case E1000_EIMS:
         return E1000_PVTEIMS(vfn);
     case E1000_EIMC:
         return E1000_PVTEIMC(vfn);
     case E1000_EIAC:
         return E1000_PVTEIAC(vfn);
     case E1000_EIAM:
         return E1000_PVTEIAM(vfn);
     case E1000_EICR:
         return E1000_PVTEICR(vfn);
     case E1000_EITR(0):
     case E1000_EITR(1):
     case E1000_EITR(2):
         return E1000_EITR(22) + (addr - E1000_EITR(0)) - vfn * 0xC;
     case E1000_IVAR0:
         return E1000_VTIVAR + vfn * 4;
     case E1000_IVAR_MISC:
         return E1000_VTIVAR_MISC + vfn * 4;
     case 0x0F04: /* PBACL */
         return E1000_PBACLR;
     case 0x0F0C: /* PSRTYPE */
         return E1000_PSRTYPE(vfn);
     case E1000_V2PMAILBOX(0):
         return E1000_V2PMAILBOX(vfn);
     case E1000_VMBMEM(0) ... E1000_VMBMEM(0) + 0x3F:
         return addr + vfn * 0x40;
     case E1000_RDBAL_A(0):
         return E1000_RDBAL(vfn);
     case E1000_RDBAL_A(1):
         return E1000_RDBAL(vfn + IGB_MAX_VF_FUNCTIONS);
     case E1000_RDBAH_A(0):
         return E1000_RDBAH(vfn);
     case E1000_RDBAH_A(1):
         return E1000_RDBAH(vfn + IGB_MAX_VF_FUNCTIONS);
     case E1000_RDLEN_A(0):
         return E1000_RDLEN(vfn);
     case E1000_RDLEN_A(1):
         return E1000_RDLEN(vfn + IGB_MAX_VF_FUNCTIONS);
     case E1000_SRRCTL_A(0):
         return E1000_SRRCTL(vfn);
     case E1000_SRRCTL_A(1):
         return E1000_SRRCTL(vfn + IGB_MAX_VF_FUNCTIONS);
     case E1000_RDH_A(0):
         return E1000_RDH(vfn);
     case E1000_RDH_A(1):
         return E1000_RDH(vfn + IGB_MAX_VF_FUNCTIONS);
     case E1000_RXCTL_A(0):
         return E1000_RXCTL(vfn);
     case E1000_RXCTL_A(1):
         return E1000_RXCTL(vfn + IGB_MAX_VF_FUNCTIONS);
     case E1000_RDT_A(0):
         return E1000_RDT(vfn);
     case E1000_RDT_A(1):
         return E1000_RDT(vfn + IGB_MAX_VF_FUNCTIONS);
     case E1000_RXDCTL_A(0):
         return E1000_RXDCTL(vfn);
     case E1000_RXDCTL_A(1):
         return E1000_RXDCTL(vfn + IGB_MAX_VF_FUNCTIONS);
     case E1000_RQDPC_A(0):
         return E1000_RQDPC(vfn);
     case E1000_RQDPC_A(1):
         return E1000_RQDPC(vfn + IGB_MAX_VF_FUNCTIONS);
     case E1000_TDBAL_A(0):
         return E1000_TDBAL(vfn);
     case E1000_TDBAL_A(1):
         return E1000_TDBAL(vfn + IGB_MAX_VF_FUNCTIONS);
     case E1000_TDBAH_A(0):
         return E1000_TDBAH(vfn);
     case E1000_TDBAH_A(1):
         return E1000_TDBAH(vfn + IGB_MAX_VF_FUNCTIONS);
     case E1000_TDLEN_A(0):
         return E1000_TDLEN(vfn);
     case E1000_TDLEN_A(1):
         return E1000_TDLEN(vfn + IGB_MAX_VF_FUNCTIONS);
     case E1000_TDH_A(0):
         return E1000_TDH(vfn);
     case E1000_TDH_A(1):
         return E1000_TDH(vfn + IGB_MAX_VF_FUNCTIONS);
     case E1000_TXCTL_A(0):
         return E1000_TXCTL(vfn);
     case E1000_TXCTL_A(1):
         return E1000_TXCTL(vfn + IGB_MAX_VF_FUNCTIONS);
     case E1000_TDT_A(0):
         return E1000_TDT(vfn);
     case E1000_TDT_A(1):
         return E1000_TDT(vfn + IGB_MAX_VF_FUNCTIONS);
     case E1000_TXDCTL_A(0):
         return E1000_TXDCTL(vfn);
     case E1000_TXDCTL_A(1):
         return E1000_TXDCTL(vfn + IGB_MAX_VF_FUNCTIONS);
     case E1000_TDWBAL_A(0):
         return E1000_TDWBAL(vfn);
     case E1000_TDWBAL_A(1):
         return E1000_TDWBAL(vfn + IGB_MAX_VF_FUNCTIONS);
     case E1000_TDWBAH_A(0):
         return E1000_TDWBAH(vfn);
     case E1000_TDWBAH_A(1):
         return E1000_TDWBAH(vfn + IGB_MAX_VF_FUNCTIONS);
     case E1000_VFGPRC:
         return E1000_PVFGPRC(vfn);
     case E1000_VFGPTC:
         return E1000_PVFGPTC(vfn);
     case E1000_VFGORC:
         return E1000_PVFGORC(vfn);
     case E1000_VFGOTC:
         return E1000_PVFGOTC(vfn);
     case E1000_VFMPRC:
         return E1000_PVFMPRC(vfn);
     case E1000_VFGPRLBC:
         return E1000_PVFGPRLBC(vfn);
     case E1000_VFGPTLBC:
         return E1000_PVFGPTLBC(vfn);
     case E1000_VFGORLBC:
         return E1000_PVFGORLBC(vfn);
     case E1000_VFGOTLBC:
         return E1000_PVFGOTLBC(vfn);
     case E1000_STATUS:
     case E1000_FRTIMER:
         if (write) {
             return HWADDR_MAX;
         }
-        /* fallthrough */
+        fallthrough;
     case 0x34E8: /* PBTWAC */
     case 0x24E8: /* PBRWAC */
         return addr;
     }
 
     trace_igbvf_wrn_io_addr_unknown(addr);
 
     return HWADDR_MAX;
 }
hw/net/imx_fec.c +1 -1
index 5d1f1f104c..a7e8b06d48 100644
@@ -888,170 +888,170 @@ static void imx_enet_write(IMXFECState *s, uint32_t index, uint32_t value)
 static void imx_eth_write(void *opaque, hwaddr offset, uint64_t value,
                            unsigned size)
 {
     IMXFECState *s = IMX_FEC(opaque);
     const bool single_tx_ring = !imx_eth_is_multi_tx_ring(s);
     uint32_t index = offset >> 2;
 
     trace_imx_eth_write(index, imx_eth_reg_name(s, index), value);
 
     switch (index) {
     case ENET_EIR:
         s->regs[index] &= ~value;
         break;
     case ENET_EIMR:
         s->regs[index] = value;
         break;
     case ENET_RDAR:
         if (s->regs[ENET_ECR] & ENET_ECR_ETHEREN) {
             if (!s->regs[index]) {
                 imx_eth_enable_rx(s, true);
             }
         } else {
             s->regs[index] = 0;
         }
         break;
     case ENET_TDAR1:
     case ENET_TDAR2:
         if (unlikely(single_tx_ring)) {
             qemu_log_mask(LOG_GUEST_ERROR,
                           "[%s]%s: trying to access TDAR2 or TDAR1\n",
                           TYPE_IMX_FEC, __func__);
             return;
         }
-        /* fall through */
+        fallthrough;
     case ENET_TDAR:
         if (s->regs[ENET_ECR] & ENET_ECR_ETHEREN) {
             s->regs[index] = ENET_TDAR_TDAR;
             imx_eth_do_tx(s, index);
         }
         s->regs[index] = 0;
         break;
     case ENET_ECR:
         if (value & ENET_ECR_RESET) {
             return imx_eth_reset(DEVICE(s));
         }
         s->regs[index] = value;
         if ((s->regs[index] & ENET_ECR_ETHEREN) == 0) {
             s->regs[ENET_RDAR] = 0;
             s->rx_descriptor = s->regs[ENET_RDSR];
             s->regs[ENET_TDAR]  = 0;
             s->regs[ENET_TDAR1] = 0;
             s->regs[ENET_TDAR2] = 0;
             s->tx_descriptor[0] = s->regs[ENET_TDSR];
             s->tx_descriptor[1] = s->regs[ENET_TDSR1];
             s->tx_descriptor[2] = s->regs[ENET_TDSR2];
         }
         break;
     case ENET_MMFR:
         s->regs[index] = value;
         if (extract32(value, 29, 1)) {
             /* This is a read operation */
             s->regs[ENET_MMFR] = deposit32(s->regs[ENET_MMFR], 0, 16,
                                            imx_phy_read(s,
                                                        extract32(value,
                                                                  18, 10)));
         } else {
             /* This is a write operation */
             imx_phy_write(s, extract32(value, 18, 10), extract32(value, 0, 16));
         }
         /* raise the interrupt as the PHY operation is done */
         s->regs[ENET_EIR] |= ENET_INT_MII;
         break;
     case ENET_MSCR:
         s->regs[index] = value & 0xfe;
         break;
     case ENET_MIBC:
         /* TODO: Implement MIB.  */
         s->regs[index] = (value & 0x80000000) ? 0xc0000000 : 0;
         break;
     case ENET_RCR:
         s->regs[index] = value & 0x07ff003f;
         /* TODO: Implement LOOP mode.  */
         break;
     case ENET_TCR:
         /* We transmit immediately, so raise GRA immediately.  */
         s->regs[index] = value;
         if (value & 1) {
             s->regs[ENET_EIR] |= ENET_INT_GRA;
         }
         break;
     case ENET_PALR:
         s->regs[index] = value;
         s->conf.macaddr.a[0] = value >> 24;
         s->conf.macaddr.a[1] = value >> 16;
         s->conf.macaddr.a[2] = value >> 8;
         s->conf.macaddr.a[3] = value;
         break;
     case ENET_PAUR:
         s->regs[index] = (value | 0x0000ffff) & 0xffff8808;
         s->conf.macaddr.a[4] = value >> 24;
         s->conf.macaddr.a[5] = value >> 16;
         break;
     case ENET_OPD:
         s->regs[index] = (value & 0x0000ffff) | 0x00010000;
         break;
     case ENET_IAUR:
     case ENET_IALR:
     case ENET_GAUR:
     case ENET_GALR:
         /* TODO: implement MAC hash filtering.  */
         break;
     case ENET_TFWR:
         if (s->is_fec) {
             s->regs[index] = value & 0x3;
         } else {
             s->regs[index] = value & 0x13f;
         }
         break;
     case ENET_RDSR:
         if (s->is_fec) {
             s->regs[index] = value & ~3;
         } else {
             s->regs[index] = value & ~7;
         }
         s->rx_descriptor = s->regs[index];
         break;
     case ENET_TDSR:
         if (s->is_fec) {
             s->regs[index] = value & ~3;
         } else {
             s->regs[index] = value & ~7;
         }
         s->tx_descriptor[0] = s->regs[index];
         break;
     case ENET_TDSR1:
         if (unlikely(single_tx_ring)) {
             qemu_log_mask(LOG_GUEST_ERROR,
                           "[%s]%s: trying to access TDSR1\n",
                           TYPE_IMX_FEC, __func__);
             return;
         }
 
         s->regs[index] = value & ~7;
         s->tx_descriptor[1] = s->regs[index];
         break;
     case ENET_TDSR2:
         if (unlikely(single_tx_ring)) {
             qemu_log_mask(LOG_GUEST_ERROR,
                           "[%s]%s: trying to access TDSR2\n",
                           TYPE_IMX_FEC, __func__);
             return;
         }
 
         s->regs[index] = value & ~7;
         s->tx_descriptor[2] = s->regs[index];
         break;
     case ENET_MRBR:
         s->regs[index] = value & 0x00003ff0;
         break;
     default:
         if (s->is_fec) {
             imx_fec_write(s, index, value);
         } else {
             imx_enet_write(s, index, value);
         }
         return;
     }
 
     imx_eth_update(s);
 }
hw/net/net_rx_pkt.c +1 -1
index 32e5f3f9cf..52e2432c9b 100644
@@ -591,36 +591,36 @@ _net_rx_pkt_validate_sctp_sum(struct NetRxPkt *pkt)
 bool net_rx_pkt_validate_l4_csum(struct NetRxPkt *pkt, bool *csum_valid)
 {
     uint32_t csum;
 
     trace_net_rx_pkt_l4_csum_validate_entry();
 
     if (pkt->hasip4 && pkt->ip4hdr_info.fragment) {
         trace_net_rx_pkt_l4_csum_validate_ip4_fragment();
         return false;
     }
 
     switch (pkt->l4hdr_info.proto) {
     case ETH_L4_HDR_PROTO_UDP:
         if (pkt->l4hdr_info.hdr.udp.uh_sum == 0) {
             trace_net_rx_pkt_l4_csum_validate_udp_with_no_checksum();
             return false;
         }
-        /* fall through */
+        fallthrough;
     case ETH_L4_HDR_PROTO_TCP:
         csum = _net_rx_pkt_calc_l4_csum(pkt);
         *csum_valid = ((csum == 0) || (csum == 0xFFFF));
         break;
 
     case ETH_L4_HDR_PROTO_SCTP:
         *csum_valid = _net_rx_pkt_validate_sctp_sum(pkt);
         break;
 
     default:
         trace_net_rx_pkt_l4_csum_validate_not_xxp();
         return false;
     }
 
     trace_net_rx_pkt_l4_csum_validate_csum(*csum_valid);
 
     return true;
 }
hw/net/pcnet.c +1 -1
index 02828ae716..a32174ef93 100644
@@ -1474,47 +1474,47 @@ static uint32_t pcnet_csr_readw(PCNetState *s, uint32_t rap)
 static void pcnet_bcr_writew(PCNetState *s, uint32_t rap, uint32_t val)
 {
     rap &= 127;
 #ifdef PCNET_DEBUG_BCR
     printf("pcnet_bcr_writew rap=%d val=0x%04x\n", rap, val);
 #endif
     switch (rap) {
     case BCR_SWS:
         if (!(CSR_STOP(s) || CSR_SPND(s)))
             return;
         val &= ~0x0300;
         switch (val & 0x00ff) {
         case 0:
             val |= 0x0200;
             break;
         case 1:
             val |= 0x0100;
             break;
         case 2:
         case 3:
             val |= 0x0300;
             break;
         default:
             qemu_log_mask(LOG_GUEST_ERROR, "pcnet: Bad SWSTYLE=0x%02x\n",
                           val & 0xff);
             val = 0x0200;
             break;
         }
 #ifdef PCNET_DEBUG
        printf("BCR_SWS=0x%04x\n", val);
 #endif
-        /* fall through */
+       fallthrough;
     case BCR_LNKST:
     case BCR_LED1:
     case BCR_LED2:
     case BCR_LED3:
     case BCR_MC:
     case BCR_FDC:
     case BCR_BSBC:
     case BCR_EECAS:
     case BCR_PLAT:
         s->bcr[rap] = val;
         break;
     default:
         break;
     }
 }
hw/net/rtl8139.c +4 -2
index 4525fda383..42f19618b1 100644
@@ -2435,29 +2435,31 @@ static void rtl8139_TxStatus_write(RTL8139State *s, uint32_t txRegOffset, uint32
 static uint32_t rtl8139_TxStatus_TxAddr_read(RTL8139State *s, uint32_t regs[],
                                              uint32_t base, uint8_t addr,
                                              int size)
 {
     uint32_t reg = (addr - base) / 4;
     uint32_t offset = addr & 0x3;
     uint32_t ret = 0;
 
     if (addr & (size - 1)) {
         DPRINTF("not implemented read for TxStatus/TxAddr "
                 "addr=0x%x size=0x%x\n", addr, size);
         return ret;
     }
 
     switch (size) {
-    case 1: /* fall through */
-    case 2: /* fall through */
+    case 1:
+        fallthrough;
+    case 2:
+        fallthrough;
     case 4:
         ret = (regs[reg] >> offset * 8) & (((uint64_t)1 << (size * 8)) - 1);
         DPRINTF("TxStatus/TxAddr[%d] read addr=0x%x size=0x%x val=0x%08x\n",
                 reg, addr, size, ret);
         break;
     default:
         DPRINTF("unsupported size 0x%x of TxStatus/TxAddr reading\n", size);
         break;
     }
 
     return ret;
 }
hw/net/xilinx_ethlite.c +1 -1
index 89f4f3b254..5ae4032ec2 100644
@@ -113,55 +113,55 @@ static void
 eth_write(void *opaque, hwaddr addr,
           uint64_t val64, unsigned int size)
 {
     struct xlx_ethlite *s = opaque;
     unsigned int base = 0;
     uint32_t value = val64;
 
     addr >>= 2;
     switch (addr) 
     {
         case R_TX_CTRL0:
         case R_TX_CTRL1:
             if (addr == R_TX_CTRL1)
                 base = 0x800 / 4;
 
             D(qemu_log("%s addr=" HWADDR_FMT_plx " val=%x\n",
                        __func__, addr * 4, value));
             if ((value & (CTRL_P | CTRL_S)) == CTRL_S) {
                 qemu_send_packet(qemu_get_queue(s->nic),
                                  (void *) &s->regs[base],
                                  s->regs[base + R_TX_LEN0]);
                 D(qemu_log("eth_tx %d\n", s->regs[base + R_TX_LEN0]));
                 if (s->regs[base + R_TX_CTRL0] & CTRL_I)
                     eth_pulse_irq(s);
             } else if ((value & (CTRL_P | CTRL_S)) == (CTRL_P | CTRL_S)) {
                 memcpy(&s->conf.macaddr.a[0], &s->regs[base], 6);
                 if (s->regs[base + R_TX_CTRL0] & CTRL_I)
                     eth_pulse_irq(s);
             }
 
             /* We are fast and get ready pretty much immediately so
                we actually never flip the S nor P bits to one.  */
             s->regs[addr] = value & ~(CTRL_P | CTRL_S);
             break;
 
         /* Keep these native.  */
         case R_RX_CTRL0:
         case R_RX_CTRL1:
             if (!(value & CTRL_S)) {
                 qemu_flush_queued_packets(qemu_get_queue(s->nic));
             }
-            /* fall through */
+            fallthrough;
         case R_TX_LEN0:
         case R_TX_LEN1:
         case R_TX_GIE0:
             D(qemu_log("%s addr=" HWADDR_FMT_plx " val=%x\n",
                        __func__, addr * 4, value));
             s->regs[addr] = value;
             break;
 
         default:
             s->regs[addr] = tswap32(value);
             break;
     }
 }
Signature · 1 line
2.39.2
#68 lore raw

RFC PATCH v2 58/78 hw/ppc: add fallthrough pseudo-keyword

In reply to Emmanouil Pitsidianakis

In preparation of raising -Wimplicit-fallthrough to 5, replace all fall-through comments with the fallthrough attribute pseudo-keyword.

---
 hw/ppc/pnv_bmc.c      | 2 +-
 hw/ppc/spapr_events.c | 1 +
 2 files changed, 2 insertions(+), 1 deletion(-)
hw/ppc/pnv_bmc.c +1 -1
index 99f1e8d7f9..9bff7d03cb 100644
@@ -172,69 +172,69 @@ static int hiomap_erase(PnvPnor *pnor, uint32_t offset, uint32_t size)
 static void hiomap_cmd(IPMIBmcSim *ibs, uint8_t *cmd, unsigned int cmd_len,
                        RspBuffer *rsp)
 {
     PnvPnor *pnor = PNV_PNOR(object_property_get_link(OBJECT(ibs), "pnor",
                                                       &error_abort));
     uint32_t pnor_size = pnor->size;
     uint32_t pnor_addr = PNOR_SPI_OFFSET;
     bool readonly = false;
 
     rsp_buffer_push(rsp, cmd[2]);
     rsp_buffer_push(rsp, cmd[3]);
 
     switch (cmd[2]) {
     case HIOMAP_C_MARK_DIRTY:
     case HIOMAP_C_FLUSH:
     case HIOMAP_C_ACK:
         break;
 
     case HIOMAP_C_ERASE:
         if (hiomap_erase(pnor, blocks_to_bytes(cmd[5] << 8 | cmd[4]),
                         blocks_to_bytes(cmd[7] << 8 | cmd[6]))) {
             rsp_buffer_set_error(rsp, IPMI_CC_UNSPECIFIED);
         }
         break;
 
     case HIOMAP_C_GET_INFO:
         rsp_buffer_push(rsp, 2);  /* Version 2 */
         rsp_buffer_push(rsp, BLOCK_SHIFT); /* block size */
         rsp_buffer_push(rsp, 0);  /* Timeout */
         rsp_buffer_push(rsp, 0);  /* Timeout */
         break;
 
     case HIOMAP_C_GET_FLASH_INFO:
         rsp_buffer_push(rsp, bytes_to_blocks(pnor_size) & 0xFF);
         rsp_buffer_push(rsp, bytes_to_blocks(pnor_size) >> 8);
         rsp_buffer_push(rsp, 0x01);  /* erase size */
         rsp_buffer_push(rsp, 0x00);  /* erase size */
         break;
 
     case HIOMAP_C_CREATE_READ_WINDOW:
         readonly = true;
-        /* Fall through */
+        fallthrough;
 
     case HIOMAP_C_CREATE_WRITE_WINDOW:
         memory_region_set_readonly(&pnor->mmio, readonly);
         memory_region_set_enabled(&pnor->mmio, true);
 
         rsp_buffer_push(rsp, bytes_to_blocks(pnor_addr) & 0xFF);
         rsp_buffer_push(rsp, bytes_to_blocks(pnor_addr) >> 8);
         rsp_buffer_push(rsp, bytes_to_blocks(pnor_size) & 0xFF);
         rsp_buffer_push(rsp, bytes_to_blocks(pnor_size) >> 8);
         rsp_buffer_push(rsp, 0x00); /* offset */
         rsp_buffer_push(rsp, 0x00); /* offset */
         break;
 
     case HIOMAP_C_CLOSE_WINDOW:
         memory_region_set_enabled(&pnor->mmio, false);
         break;
 
     case HIOMAP_C_DEVICE_NAME:
     case HIOMAP_C_RESET:
     case HIOMAP_C_LOCK:
     default:
         qemu_log_mask(LOG_GUEST_ERROR, "HIOMAP: unknown command %02X\n", cmd[2]);
         break;
     }
 }
 
 #define HIOMAP   0x5a
hw/ppc/spapr_events.c +1 -0
index 4508e40814..9d51746daf 100644
@@ -411,25 +411,26 @@ static const SpaprEventSource *
 rtas_event_log_to_source(SpaprMachineState *spapr, int log_type)
 {
     const SpaprEventSource *source;
 
     g_assert(spapr->event_sources);
 
     switch (log_type) {
     case RTAS_LOG_TYPE_HOTPLUG:
         source = spapr_event_sources_get_source(spapr->event_sources,
                                                 EVENT_CLASS_HOT_PLUG);
         if (spapr_ovec_test(spapr->ov5_cas, OV5_HP_EVT)) {
             g_assert(source->enabled);
             break;
         }
         /* fall through back to epow for legacy hotplug interrupt source */
+        fallthrough;
     case RTAS_LOG_TYPE_EPOW:
         source = spapr_event_sources_get_source(spapr->event_sources,
                                                 EVENT_CLASS_EPOW);
         break;
     default:
         source = NULL;
     }
 
     return source;
 }
Signature · 1 line
2.39.2
Reviewed-by on v2 58/78
#69 lore raw

Re: [RFC PATCH v2 58/78] hw/ppc: add fallthrough pseudo-keyword

Quoted 4 lines · Emmanouil Pitsidianakis

In preparation of raising -Wimplicit-fallthrough to 5, replace all fall-through comments with the fallthrough attribute pseudo-keyword.

One question below, may be Cedric knows better who introduced initial code.

Quoted 63 lines
---
  hw/ppc/pnv_bmc.c      | 2 +-
  hw/ppc/spapr_events.c | 1 +
  2 files changed, 2 insertions(+), 1 deletion(-)
hw/ppc/pnv_bmc.c +1 -1
index 99f1e8d7f9..9bff7d03cb 100644
@@ -172,69 +172,69 @@ static int hiomap_erase(PnvPnor *pnor, uint32_t offset, uint32_t size)
  static void hiomap_cmd(IPMIBmcSim *ibs, uint8_t *cmd, unsigned int cmd_len,
                         RspBuffer *rsp)
  {
      PnvPnor *pnor = PNV_PNOR(object_property_get_link(OBJECT(ibs), "pnor",
                                                        &error_abort));
      uint32_t pnor_size = pnor->size;
      uint32_t pnor_addr = PNOR_SPI_OFFSET;
      bool readonly = false;
 
      rsp_buffer_push(rsp, cmd[2]);
      rsp_buffer_push(rsp, cmd[3]);
 
      switch (cmd[2]) {
      case HIOMAP_C_MARK_DIRTY:
      case HIOMAP_C_FLUSH:
      case HIOMAP_C_ACK:
          break;
 
      case HIOMAP_C_ERASE:
          if (hiomap_erase(pnor, blocks_to_bytes(cmd[5] << 8 | cmd[4]),
                          blocks_to_bytes(cmd[7] << 8 | cmd[6]))) {
              rsp_buffer_set_error(rsp, IPMI_CC_UNSPECIFIED);
          }
          break;
 
      case HIOMAP_C_GET_INFO:
          rsp_buffer_push(rsp, 2);  /* Version 2 */
          rsp_buffer_push(rsp, BLOCK_SHIFT); /* block size */
          rsp_buffer_push(rsp, 0);  /* Timeout */
          rsp_buffer_push(rsp, 0);  /* Timeout */
          break;
 
      case HIOMAP_C_GET_FLASH_INFO:
          rsp_buffer_push(rsp, bytes_to_blocks(pnor_size) & 0xFF);
          rsp_buffer_push(rsp, bytes_to_blocks(pnor_size) >> 8);
          rsp_buffer_push(rsp, 0x01);  /* erase size */
          rsp_buffer_push(rsp, 0x00);  /* erase size */
          break;
 
      case HIOMAP_C_CREATE_READ_WINDOW:
          readonly = true;
-        /* Fall through */
+        fallthrough;
 
      case HIOMAP_C_CREATE_WRITE_WINDOW:
          memory_region_set_readonly(&pnor->mmio, readonly);
          memory_region_set_enabled(&pnor->mmio, true);
 
          rsp_buffer_push(rsp, bytes_to_blocks(pnor_addr) & 0xFF);
          rsp_buffer_push(rsp, bytes_to_blocks(pnor_addr) >> 8);
          rsp_buffer_push(rsp, bytes_to_blocks(pnor_size) & 0xFF);
          rsp_buffer_push(rsp, bytes_to_blocks(pnor_size) >> 8);
          rsp_buffer_push(rsp, 0x00); /* offset */

hw/ppc/pnv_bmc.c static int hiomap_erase(PnvPnor *pnor, uint32_t offset, uint32_t size) · line 233

Quoted 10 lines
hw/ppc/pnv_bmc.c +0 -0
          rsp_buffer_push(rsp, 0x00); /* offset */
          break;
 
      case HIOMAP_C_CLOSE_WINDOW:
          memory_region_set_enabled(&pnor->mmio, false);
          break;
 
      case HIOMAP_C_DEVICE_NAME:
      case HIOMAP_C_RESET:
      case HIOMAP_C_LOCK:

Do we need a break here ?
Otherwise above 3 case statements doesnt add any value.

Quoted 38 lines
hw/ppc/pnv_bmc.c +0 -0
      default:
          qemu_log_mask(LOG_GUEST_ERROR, "HIOMAP: unknown command %02X\n", cmd[2]);
          break;
      }
  }
 
  #define HIOMAP   0x5a
hw/ppc/spapr_events.c +1 -0
index 4508e40814..9d51746daf 100644
@@ -411,25 +411,26 @@ static const SpaprEventSource *
  rtas_event_log_to_source(SpaprMachineState *spapr, int log_type)
  {
      const SpaprEventSource *source;
 
      g_assert(spapr->event_sources);
 
      switch (log_type) {
      case RTAS_LOG_TYPE_HOTPLUG:
          source = spapr_event_sources_get_source(spapr->event_sources,
                                                  EVENT_CLASS_HOT_PLUG);
          if (spapr_ovec_test(spapr->ov5_cas, OV5_HP_EVT)) {
              g_assert(source->enabled);
              break;
          }
          /* fall through back to epow for legacy hotplug interrupt source */
+        fallthrough;
      case RTAS_LOG_TYPE_EPOW:
          source = spapr_event_sources_get_source(spapr->event_sources,
                                                  EVENT_CLASS_EPOW);
          break;
      default:
          source = NULL;
      }
 
      return source;
  }
#70 lore raw

Re: [RFC PATCH v2 58/78] hw/ppc: add fallthrough pseudo-keyword

Quoted 70 lines · Harsh Prateek Bora
Quoted 4 lines · Emmanouil Pitsidianakis

In preparation of raising -Wimplicit-fallthrough to 5, replace all fall-through comments with the fallthrough attribute pseudo-keyword.

One question below, may be Cedric knows better who introduced initial code.

Quoted 58 lines

---
  hw/ppc/pnv_bmc.c      | 2 +-
  hw/ppc/spapr_events.c | 1 +

  2 files changed, 2 insertions(+), 1 deletion(-)
hw/ppc/pnv_bmc.c +0 -0
index 99f1e8d7f9..9bff7d03cb 100644
@@ -172,69 +172,69 @@ static int hiomap_erase(PnvPnor *pnor, uint32_t offset, uint32_t size)
   static void hiomap_cmd(IPMIBmcSim *ibs, uint8_t *cmd, unsigned int cmd_len,
                          RspBuffer *rsp)
   {
       PnvPnor *pnor = PNV_PNOR(object_property_get_link(OBJECT(ibs), "pnor",
                                                         &error_abort));
       uint32_t pnor_size = pnor->size;
       uint32_t pnor_addr = PNOR_SPI_OFFSET;
       bool readonly = false;
       rsp_buffer_push(rsp, cmd[2]);
       rsp_buffer_push(rsp, cmd[3]);
       switch (cmd[2]) {

      case HIOMAP_C_MARK_DIRTY:
      case HIOMAP_C_FLUSH:
      case HIOMAP_C_ACK:
          break;
      case HIOMAP_C_ERASE:
          if (hiomap_erase(pnor, blocks_to_bytes(cmd[5] << 8 | cmd[4]), blocks_to_bytes(cmd[7] << 8 | cmd[6]))) { rsp_buffer_set_error(rsp, IPMI_CC_UNSPECIFIED); }
          break;
      case HIOMAP_C_GET_INFO:
          rsp_buffer_push(rsp, 2);  /* Version 2 */ rsp_buffer_push(rsp, BLOCK_SHIFT); /* block size */ rsp_buffer_push(rsp, 0);  /* Timeout */ rsp_buffer_push(rsp, 0);  /* Timeout */
          break;
      case HIOMAP_C_GET_FLASH_INFO:
          rsp_buffer_push(rsp, bytes_to_blocks(pnor_size) & 0xFF); rsp_buffer_push(rsp, bytes_to_blocks(pnor_size) >> 8); rsp_buffer_push(rsp, 0x01);  /* erase size */ rsp_buffer_push(rsp, 0x00);  /* erase size */ break;
      case HIOMAP_C_CREATE_READ_WINDOW:
          readonly = true;
-        /* Fall through */
+        fallthrough;
      case HIOMAP_C_CREATE_WRITE_WINDOW:
          memory_region_set_readonly(&pnor->mmio, readonly); memory_region_set_enabled(&pnor->mmio, true); rsp_buffer_push(rsp, bytes_to_blocks(pnor_addr) & 0xFF); rsp_buffer_push(rsp, bytes_to_blocks(pnor_addr) >> 8); rsp_buffer_push(rsp, bytes_to_blocks(pnor_size) & 0xFF); rsp_buffer_push(rsp, bytes_to_blocks(pnor_size) >> 8); rsp_buffer_push(rsp, 0x00); /* offset */ rsp_buffer_push(rsp, 0x00); /* offset */
          break;
      case HIOMAP_C_CLOSE_WINDOW:

Quoted 8 lines
Quoted 5 lines

          memory_region_set_enabled(&pnor->mmio, false); break;
      case HIOMAP_C_DEVICE_NAME:
      case HIOMAP_C_RESET:
      case HIOMAP_C_LOCK:

Do we need a break here ?
Otherwise above 3 case statements doesnt add any value.

Indeed. These came from ca661fae81d3 ("ppc/pnv: Add HIOMAP commands"). The RESET command is implemented in skiboot. DEVICE_NAME and LOCK seem not. Something to check.

Thanks,

C.

Quoted 35 lines
Quoted 35 lines

      default:
          qemu_log_mask(LOG_GUEST_ERROR, "HIOMAP: unknown command %02X\n", cmd[2]); break;
      }
  }
  #define HIOMAP   0x5a

hw/ppc/spapr_events.c +0 -0
index 4508e40814..9d51746daf 100644
@@ -411,25 +411,26 @@ static const SpaprEventSource *
   rtas_event_log_to_source(SpaprMachineState *spapr, int log_type)
   {
       const SpaprEventSource *source;
       g_assert(spapr->event_sources);
       switch (log_type) {

      case RTAS_LOG_TYPE_HOTPLUG:
          source = spapr_event_sources_get_source(spapr->event_sources, EVENT_CLASS_HOT_PLUG); if (spapr_ovec_test(spapr->ov5_cas, OV5_HP_EVT)) { g_assert(source->enabled);
              break;
          }
          /* fall through back to epow for legacy hotplug interrupt source */ +        fallthrough;
      case RTAS_LOG_TYPE_EPOW:
          source = spapr_event_sources_get_source(spapr->event_sources, EVENT_CLASS_EPOW); break;
      default:
          source = NULL;
      }
      return source;
  }

#71 lore raw

RFC PATCH v2 59/78 hw/intc: add fallthrough pseudo-keyword

In reply to Emmanouil Pitsidianakis

In preparation of raising -Wimplicit-fallthrough to 5, replace all fall-through comments with the fallthrough attribute pseudo-keyword.

---
 hw/intc/apic.c          |  2 +-
 hw/intc/arm_gicv3_kvm.c | 16 ++++++++--------
 hw/intc/armv7m_nvic.c   | 12 ++++++------
 hw/intc/xilinx_intc.c   |  2 +-
 4 files changed, 16 insertions(+), 16 deletions(-)
hw/intc/apic.c +1 -1
index ac3d47d231..30f341c722 100644
@@ -172,21 +172,21 @@ static void apic_local_deliver(APICCommonState *s, int vector)
 void apic_deliver_pic_intr(DeviceState *dev, int level)
 {
     APICCommonState *s = APIC(dev);
 
     if (level) {
         apic_local_deliver(s, APIC_LVT_LINT0);
     } else {
         uint32_t lvt = s->lvt[APIC_LVT_LINT0];
 
         switch ((lvt >> 8) & 7) {
         case APIC_DM_FIXED:
             if (!(lvt & APIC_LVT_LEVEL_TRIGGER))
                 break;
             apic_reset_bit(s->irr, lvt & 0xff);
-            /* fall through */
+            fallthrough;
         case APIC_DM_EXTINT:
             apic_update_irq(s);
             break;
         }
     }
 }
hw/intc/arm_gicv3_kvm.c +8 -8
index 72ad916d3d..782cef3390 100644
@@ -323,186 +323,186 @@ static void kvm_arm_gicv3_check(GICv3State *s)
 static void kvm_arm_gicv3_put(GICv3State *s)
 {
     uint32_t regl, regh, reg;
     uint64_t reg64, redist_typer;
     int ncpu, i;
 
     kvm_arm_gicv3_check(s);
 
     kvm_gicr_access(s, GICR_TYPER, 0, &regl, false);
     kvm_gicr_access(s, GICR_TYPER + 4, 0, &regh, false);
     redist_typer = ((uint64_t)regh << 32) | regl;
 
     reg = s->gicd_ctlr;
     kvm_gicd_access(s, GICD_CTLR, &reg, true);
 
     if (redist_typer & GICR_TYPER_PLPIS) {
         /*
          * Restore base addresses before LPIs are potentially enabled by
          * GICR_CTLR write
          */
         for (ncpu = 0; ncpu < s->num_cpu; ncpu++) {
             GICv3CPUState *c = &s->cpu[ncpu];
 
             reg64 = c->gicr_propbaser;
             regl = (uint32_t)reg64;
             kvm_gicr_access(s, GICR_PROPBASER, ncpu, &regl, true);
             regh = (uint32_t)(reg64 >> 32);
             kvm_gicr_access(s, GICR_PROPBASER + 4, ncpu, &regh, true);
 
             reg64 = c->gicr_pendbaser;
             regl = (uint32_t)reg64;
             kvm_gicr_access(s, GICR_PENDBASER, ncpu, &regl, true);
             regh = (uint32_t)(reg64 >> 32);
             kvm_gicr_access(s, GICR_PENDBASER + 4, ncpu, &regh, true);
         }
     }
 
     /* Redistributor state (one per CPU) */
 
     for (ncpu = 0; ncpu < s->num_cpu; ncpu++) {
         GICv3CPUState *c = &s->cpu[ncpu];
 
         reg = c->gicr_ctlr;
         kvm_gicr_access(s, GICR_CTLR, ncpu, &reg, true);
 
         reg = c->gicr_statusr[GICV3_NS];
         kvm_gicr_access(s, GICR_STATUSR, ncpu, &reg, true);
 
         reg = c->gicr_waker;
         kvm_gicr_access(s, GICR_WAKER, ncpu, &reg, true);
 
         reg = c->gicr_igroupr0;
         kvm_gicr_access(s, GICR_IGROUPR0, ncpu, &reg, true);
 
         reg = ~0;
         kvm_gicr_access(s, GICR_ICENABLER0, ncpu, &reg, true);
         reg = c->gicr_ienabler0;
         kvm_gicr_access(s, GICR_ISENABLER0, ncpu, &reg, true);
 
         /* Restore config before pending so we treat level/edge correctly */
         reg = half_shuffle32(c->edge_trigger >> 16) << 1;
         kvm_gicr_access(s, GICR_ICFGR1, ncpu, &reg, true);
 
         reg = c->level;
         kvm_gic_line_level_access(s, 0, ncpu, &reg, true);
 
         reg = ~0;
         kvm_gicr_access(s, GICR_ICPENDR0, ncpu, &reg, true);
         reg = c->gicr_ipendr0;
         kvm_gicr_access(s, GICR_ISPENDR0, ncpu, &reg, true);
 
         reg = ~0;
         kvm_gicr_access(s, GICR_ICACTIVER0, ncpu, &reg, true);
         reg = c->gicr_iactiver0;
         kvm_gicr_access(s, GICR_ISACTIVER0, ncpu, &reg, true);
 
         for (i = 0; i < GIC_INTERNAL; i += 4) {
             reg = c->gicr_ipriorityr[i] |
                 (c->gicr_ipriorityr[i + 1] << 8) |
                 (c->gicr_ipriorityr[i + 2] << 16) |
                 (c->gicr_ipriorityr[i + 3] << 24);
             kvm_gicr_access(s, GICR_IPRIORITYR + i, ncpu, &reg, true);
         }
     }
 
     /* Distributor state (shared between all CPUs */
     reg = s->gicd_statusr[GICV3_NS];
     kvm_gicd_access(s, GICD_STATUSR, &reg, true);
 
     /* s->enable bitmap -> GICD_ISENABLERn */
     kvm_dist_putbmp(s, GICD_ISENABLER, GICD_ICENABLER, s->enabled);
 
     /* s->group bitmap -> GICD_IGROUPRn */
     kvm_dist_putbmp(s, GICD_IGROUPR, 0, s->group);
 
     /* Restore targets before pending to ensure the pending state is set on
      * the appropriate CPU interfaces in the kernel
      */
 
     /* s->gicd_irouter[irq] -> GICD_IROUTERn
      * We can't use kvm_dist_put() here because the registers are 64-bit
      */
     for (i = GIC_INTERNAL; i < s->num_irq; i++) {
         uint32_t offset;
 
         offset = GICD_IROUTER + (sizeof(uint32_t) * i);
         reg = (uint32_t)s->gicd_irouter[i];
         kvm_gicd_access(s, offset, &reg, true);
 
         offset = GICD_IROUTER + (sizeof(uint32_t) * i) + 4;
         reg = (uint32_t)(s->gicd_irouter[i] >> 32);
         kvm_gicd_access(s, offset, &reg, true);
     }
 
     /* s->trigger bitmap -> GICD_ICFGRn
      * (restore configuration registers before pending IRQs so we treat
      * level/edge correctly)
      */
     kvm_dist_put_edge_trigger(s, GICD_ICFGR, s->edge_trigger);
 
     /* s->level bitmap ->  line_level */
     kvm_gic_put_line_level_bmp(s, s->level);
 
     /* s->pending bitmap -> GICD_ISPENDRn */
     kvm_dist_putbmp(s, GICD_ISPENDR, GICD_ICPENDR, s->pending);
 
     /* s->active bitmap -> GICD_ISACTIVERn */
     kvm_dist_putbmp(s, GICD_ISACTIVER, GICD_ICACTIVER, s->active);
 
     /* s->gicd_ipriority[] -> GICD_IPRIORITYRn */
     kvm_dist_put_priority(s, GICD_IPRIORITYR, s->gicd_ipriority);
 
     /* CPU Interface state (one per CPU) */
 
     for (ncpu = 0; ncpu < s->num_cpu; ncpu++) {
         GICv3CPUState *c = &s->cpu[ncpu];
         int num_pri_bits;
 
         kvm_gicc_access(s, ICC_SRE_EL1, ncpu, &c->icc_sre_el1, true);
         kvm_gicc_access(s, ICC_CTLR_EL1, ncpu,
                         &c->icc_ctlr_el1[GICV3_NS], true);
         kvm_gicc_access(s, ICC_IGRPEN0_EL1, ncpu,
                         &c->icc_igrpen[GICV3_G0], true);
         kvm_gicc_access(s, ICC_IGRPEN1_EL1, ncpu,
                         &c->icc_igrpen[GICV3_G1NS], true);
         kvm_gicc_access(s, ICC_PMR_EL1, ncpu, &c->icc_pmr_el1, true);
         kvm_gicc_access(s, ICC_BPR0_EL1, ncpu, &c->icc_bpr[GICV3_G0], true);
         kvm_gicc_access(s, ICC_BPR1_EL1, ncpu, &c->icc_bpr[GICV3_G1NS], true);
 
         num_pri_bits = ((c->icc_ctlr_el1[GICV3_NS] &
                         ICC_CTLR_EL1_PRIBITS_MASK) >>
                         ICC_CTLR_EL1_PRIBITS_SHIFT) + 1;
 
         switch (num_pri_bits) {
         case 7:
             reg64 = c->icc_apr[GICV3_G0][3];
             kvm_gicc_access(s, ICC_AP0R_EL1(3), ncpu, &reg64, true);
             reg64 = c->icc_apr[GICV3_G0][2];
             kvm_gicc_access(s, ICC_AP0R_EL1(2), ncpu, &reg64, true);
-            /* fall through */
+            fallthrough;
         case 6:
             reg64 = c->icc_apr[GICV3_G0][1];
             kvm_gicc_access(s, ICC_AP0R_EL1(1), ncpu, &reg64, true);
-            /* fall through */
+            fallthrough;
         default:
             reg64 = c->icc_apr[GICV3_G0][0];
             kvm_gicc_access(s, ICC_AP0R_EL1(0), ncpu, &reg64, true);
         }
 
         switch (num_pri_bits) {
         case 7:
             reg64 = c->icc_apr[GICV3_G1NS][3];
             kvm_gicc_access(s, ICC_AP1R_EL1(3), ncpu, &reg64, true);
             reg64 = c->icc_apr[GICV3_G1NS][2];
             kvm_gicc_access(s, ICC_AP1R_EL1(2), ncpu, &reg64, true);
-            /* fall through */
+            fallthrough;
         case 6:
             reg64 = c->icc_apr[GICV3_G1NS][1];
             kvm_gicc_access(s, ICC_AP1R_EL1(1), ncpu, &reg64, true);
-            /* fall through */
+            fallthrough;
         default:
             reg64 = c->icc_apr[GICV3_G1NS][0];
             kvm_gicc_access(s, ICC_AP1R_EL1(0), ncpu, &reg64, true);
         }
     }
 }
@@ -510,156 +510,156 @@ static void kvm_arm_gicv3_put(GICv3State *s)
 static void kvm_arm_gicv3_get(GICv3State *s)
 {
     uint32_t regl, regh, reg;
     uint64_t reg64, redist_typer;
     int ncpu, i;
 
     kvm_arm_gicv3_check(s);
 
     kvm_gicr_access(s, GICR_TYPER, 0, &regl, false);
     kvm_gicr_access(s, GICR_TYPER + 4, 0, &regh, false);
     redist_typer = ((uint64_t)regh << 32) | regl;
 
     kvm_gicd_access(s, GICD_CTLR, &reg, false);
     s->gicd_ctlr = reg;
 
     /* Redistributor state (one per CPU) */
 
     for (ncpu = 0; ncpu < s->num_cpu; ncpu++) {
         GICv3CPUState *c = &s->cpu[ncpu];
 
         kvm_gicr_access(s, GICR_CTLR, ncpu, &reg, false);
         c->gicr_ctlr = reg;
 
         kvm_gicr_access(s, GICR_STATUSR, ncpu, &reg, false);
         c->gicr_statusr[GICV3_NS] = reg;
 
         kvm_gicr_access(s, GICR_WAKER, ncpu, &reg, false);
         c->gicr_waker = reg;
 
         kvm_gicr_access(s, GICR_IGROUPR0, ncpu, &reg, false);
         c->gicr_igroupr0 = reg;
         kvm_gicr_access(s, GICR_ISENABLER0, ncpu, &reg, false);
         c->gicr_ienabler0 = reg;
         kvm_gicr_access(s, GICR_ICFGR1, ncpu, &reg, false);
         c->edge_trigger = half_unshuffle32(reg >> 1) << 16;
         kvm_gic_line_level_access(s, 0, ncpu, &reg, false);
         c->level = reg;
         kvm_gicr_access(s, GICR_ISPENDR0, ncpu, &reg, false);
         c->gicr_ipendr0 = reg;
         kvm_gicr_access(s, GICR_ISACTIVER0, ncpu, &reg, false);
         c->gicr_iactiver0 = reg;
 
         for (i = 0; i < GIC_INTERNAL; i += 4) {
             kvm_gicr_access(s, GICR_IPRIORITYR + i, ncpu, &reg, false);
             c->gicr_ipriorityr[i] = extract32(reg, 0, 8);
             c->gicr_ipriorityr[i + 1] = extract32(reg, 8, 8);
             c->gicr_ipriorityr[i + 2] = extract32(reg, 16, 8);
             c->gicr_ipriorityr[i + 3] = extract32(reg, 24, 8);
         }
     }
 
     if (redist_typer & GICR_TYPER_PLPIS) {
         for (ncpu = 0; ncpu < s->num_cpu; ncpu++) {
             GICv3CPUState *c = &s->cpu[ncpu];
 
             kvm_gicr_access(s, GICR_PROPBASER, ncpu, &regl, false);
             kvm_gicr_access(s, GICR_PROPBASER + 4, ncpu, &regh, false);
             c->gicr_propbaser = ((uint64_t)regh << 32) | regl;
 
             kvm_gicr_access(s, GICR_PENDBASER, ncpu, &regl, false);
             kvm_gicr_access(s, GICR_PENDBASER + 4, ncpu, &regh, false);
             c->gicr_pendbaser = ((uint64_t)regh << 32) | regl;
         }
     }
 
     /* Distributor state (shared between all CPUs */
 
     kvm_gicd_access(s, GICD_STATUSR, &reg, false);
     s->gicd_statusr[GICV3_NS] = reg;
 
     /* GICD_IGROUPRn -> s->group bitmap */
     kvm_dist_getbmp(s, GICD_IGROUPR, s->group);
 
     /* GICD_ISENABLERn -> s->enabled bitmap */
     kvm_dist_getbmp(s, GICD_ISENABLER, s->enabled);
 
     /* Line level of irq */
     kvm_gic_get_line_level_bmp(s, s->level);
     /* GICD_ISPENDRn -> s->pending bitmap */
     kvm_dist_getbmp(s, GICD_ISPENDR, s->pending);
 
     /* GICD_ISACTIVERn -> s->active bitmap */
     kvm_dist_getbmp(s, GICD_ISACTIVER, s->active);
 
     /* GICD_ICFGRn -> s->trigger bitmap */
     kvm_dist_get_edge_trigger(s, GICD_ICFGR, s->edge_trigger);
 
     /* GICD_IPRIORITYRn -> s->gicd_ipriority[] */
     kvm_dist_get_priority(s, GICD_IPRIORITYR, s->gicd_ipriority);
 
     /* GICD_IROUTERn -> s->gicd_irouter[irq] */
     for (i = GIC_INTERNAL; i < s->num_irq; i++) {
         uint32_t offset;
 
         offset = GICD_IROUTER + (sizeof(uint32_t) * i);
         kvm_gicd_access(s, offset, &regl, false);
         offset = GICD_IROUTER + (sizeof(uint32_t) * i) + 4;
         kvm_gicd_access(s, offset, &regh, false);
         s->gicd_irouter[i] = ((uint64_t)regh << 32) | regl;
     }
 
     /*****************************************************************
      * CPU Interface(s) State
      */
 
     for (ncpu = 0; ncpu < s->num_cpu; ncpu++) {
         GICv3CPUState *c = &s->cpu[ncpu];
         int num_pri_bits;
 
         kvm_gicc_access(s, ICC_SRE_EL1, ncpu, &c->icc_sre_el1, false);
         kvm_gicc_access(s, ICC_CTLR_EL1, ncpu,
                         &c->icc_ctlr_el1[GICV3_NS], false);
         kvm_gicc_access(s, ICC_IGRPEN0_EL1, ncpu,
                         &c->icc_igrpen[GICV3_G0], false);
         kvm_gicc_access(s, ICC_IGRPEN1_EL1, ncpu,
                         &c->icc_igrpen[GICV3_G1NS], false);
         kvm_gicc_access(s, ICC_PMR_EL1, ncpu, &c->icc_pmr_el1, false);
         kvm_gicc_access(s, ICC_BPR0_EL1, ncpu, &c->icc_bpr[GICV3_G0], false);
         kvm_gicc_access(s, ICC_BPR1_EL1, ncpu, &c->icc_bpr[GICV3_G1NS], false);
         num_pri_bits = ((c->icc_ctlr_el1[GICV3_NS] &
                         ICC_CTLR_EL1_PRIBITS_MASK) >>
                         ICC_CTLR_EL1_PRIBITS_SHIFT) + 1;
 
         switch (num_pri_bits) {
         case 7:
             kvm_gicc_access(s, ICC_AP0R_EL1(3), ncpu, &reg64, false);
             c->icc_apr[GICV3_G0][3] = reg64;
             kvm_gicc_access(s, ICC_AP0R_EL1(2), ncpu, &reg64, false);
             c->icc_apr[GICV3_G0][2] = reg64;
-            /* fall through */
+            fallthrough;
         case 6:
             kvm_gicc_access(s, ICC_AP0R_EL1(1), ncpu, &reg64, false);
             c->icc_apr[GICV3_G0][1] = reg64;
-            /* fall through */
+            fallthrough;
         default:
             kvm_gicc_access(s, ICC_AP0R_EL1(0), ncpu, &reg64, false);
             c->icc_apr[GICV3_G0][0] = reg64;
         }
 
         switch (num_pri_bits) {
         case 7:
             kvm_gicc_access(s, ICC_AP1R_EL1(3), ncpu, &reg64, false);
             c->icc_apr[GICV3_G1NS][3] = reg64;
             kvm_gicc_access(s, ICC_AP1R_EL1(2), ncpu, &reg64, false);
             c->icc_apr[GICV3_G1NS][2] = reg64;
-            /* fall through */
+            fallthrough;
         case 6:
             kvm_gicc_access(s, ICC_AP1R_EL1(1), ncpu, &reg64, false);
             c->icc_apr[GICV3_G1NS][1] = reg64;
-            /* fall through */
+            fallthrough;
         default:
             kvm_gicc_access(s, ICC_AP1R_EL1(0), ncpu, &reg64, false);
             c->icc_apr[GICV3_G1NS][0] = reg64;
         }
     }
 }
hw/intc/armv7m_nvic.c +6 -6
index 03b6b8c986..72d3ae985e 100644
@@ -2209,128 +2209,128 @@ static int shpr_bank(NVICState *s, int exc, MemTxAttrs attrs)
 static MemTxResult nvic_sysreg_read(void *opaque, hwaddr addr,
                                     uint64_t *data, unsigned size,
                                     MemTxAttrs attrs)
 {
     NVICState *s = (NVICState *)opaque;
     uint32_t offset = addr;
     unsigned i, startvec, end;
     uint32_t val;
 
     if (attrs.user && !nvic_user_access_ok(s, addr, attrs)) {
         /* Generate BusFault for unprivileged accesses */
         return MEMTX_ERROR;
     }
 
     switch (offset) {
     /* reads of set and clear both return the status */
     case 0x100 ... 0x13f: /* NVIC Set enable */
         offset += 0x80;
-        /* fall through */
+        fallthrough;
     case 0x180 ... 0x1bf: /* NVIC Clear enable */
         val = 0;
         startvec = 8 * (offset - 0x180) + NVIC_FIRST_IRQ; /* vector # */
 
         for (i = 0, end = size * 8; i < end && startvec + i < s->num_irq; i++) {
             if (s->vectors[startvec + i].enabled &&
                 (attrs.secure || s->itns[startvec + i])) {
                 val |= (1 << i);
             }
         }
         break;
     case 0x200 ... 0x23f: /* NVIC Set pend */
         offset += 0x80;
-        /* fall through */
+        fallthrough;
     case 0x280 ... 0x2bf: /* NVIC Clear pend */
         val = 0;
         startvec = 8 * (offset - 0x280) + NVIC_FIRST_IRQ; /* vector # */
         for (i = 0, end = size * 8; i < end && startvec + i < s->num_irq; i++) {
             if (s->vectors[startvec + i].pending &&
                 (attrs.secure || s->itns[startvec + i])) {
                 val |= (1 << i);
             }
         }
         break;
     case 0x300 ... 0x33f: /* NVIC Active */
         val = 0;
 
         if (!arm_feature(&s->cpu->env, ARM_FEATURE_V7)) {
             break;
         }
 
         startvec = 8 * (offset - 0x300) + NVIC_FIRST_IRQ; /* vector # */
 
         for (i = 0, end = size * 8; i < end && startvec + i < s->num_irq; i++) {
             if (s->vectors[startvec + i].active &&
                 (attrs.secure || s->itns[startvec + i])) {
                 val |= (1 << i);
             }
         }
         break;
     case 0x400 ... 0x5ef: /* NVIC Priority */
         val = 0;
         startvec = offset - 0x400 + NVIC_FIRST_IRQ; /* vector # */
 
         for (i = 0; i < size && startvec + i < s->num_irq; i++) {
             if (attrs.secure || s->itns[startvec + i]) {
                 val |= s->vectors[startvec + i].prio << (8 * i);
             }
         }
         break;
     case 0xd18 ... 0xd1b: /* System Handler Priority (SHPR1) */
         if (!arm_feature(&s->cpu->env, ARM_FEATURE_M_MAIN)) {
             val = 0;
             break;
         }
-        /* fall through */
+        fallthrough;
     case 0xd1c ... 0xd23: /* System Handler Priority (SHPR2, SHPR3) */
         val = 0;
         for (i = 0; i < size; i++) {
             unsigned hdlidx = (offset - 0xd14) + i;
             int sbank = shpr_bank(s, hdlidx, attrs);
 
             if (sbank < 0) {
                 continue;
             }
             val = deposit32(val, i * 8, 8, get_prio(s, hdlidx, sbank));
         }
         break;
     case 0xd28 ... 0xd2b: /* Configurable Fault Status (CFSR) */
         if (!arm_feature(&s->cpu->env, ARM_FEATURE_M_MAIN)) {
             val = 0;
             break;
         };
         /*
          * The BFSR bits [15:8] are shared between security states
          * and we store them in the NS copy. They are RAZ/WI for
          * NS code if AIRCR.BFHFNMINS is 0.
          */
         val = s->cpu->env.v7m.cfsr[attrs.secure];
         if (!attrs.secure &&
             !(s->cpu->env.v7m.aircr & R_V7M_AIRCR_BFHFNMINS_MASK)) {
             val &= ~R_V7M_CFSR_BFSR_MASK;
         } else {
             val |= s->cpu->env.v7m.cfsr[M_REG_NS] & R_V7M_CFSR_BFSR_MASK;
         }
         val = extract32(val, (offset - 0xd28) * 8, size * 8);
         break;
     case 0xfe0 ... 0xfff: /* ID.  */
         if (offset & 3) {
             val = 0;
         } else {
             val = nvic_id[(offset - 0xfe0) >> 2];
         }
         break;
     default:
         if (size == 4) {
             val = nvic_readl(s, offset, attrs);
         } else {
             qemu_log_mask(LOG_GUEST_ERROR,
                           "NVIC: Bad read of size %d at offset 0x%x\n",
                           size, offset);
             val = 0;
         }
     }
 
     trace_nvic_sysreg_read(addr, val, size);
     *data = val;
     return MEMTX_OK;
 }
@@ -2338,126 +2338,126 @@ static MemTxResult nvic_sysreg_read(void *opaque, hwaddr addr,
 static MemTxResult nvic_sysreg_write(void *opaque, hwaddr addr,
                                      uint64_t value, unsigned size,
                                      MemTxAttrs attrs)
 {
     NVICState *s = (NVICState *)opaque;
     uint32_t offset = addr;
     unsigned i, startvec, end;
     unsigned setval = 0;
 
     trace_nvic_sysreg_write(addr, value, size);
 
     if (attrs.user && !nvic_user_access_ok(s, addr, attrs)) {
         /* Generate BusFault for unprivileged accesses */
         return MEMTX_ERROR;
     }
 
     switch (offset) {
     case 0x100 ... 0x13f: /* NVIC Set enable */
         offset += 0x80;
         setval = 1;
-        /* fall through */
+        fallthrough;
     case 0x180 ... 0x1bf: /* NVIC Clear enable */
         startvec = 8 * (offset - 0x180) + NVIC_FIRST_IRQ;
 
         for (i = 0, end = size * 8; i < end && startvec + i < s->num_irq; i++) {
             if (value & (1 << i) &&
                 (attrs.secure || s->itns[startvec + i])) {
                 s->vectors[startvec + i].enabled = setval;
             }
         }
         nvic_irq_update(s);
         goto exit_ok;
     case 0x200 ... 0x23f: /* NVIC Set pend */
         /* the special logic in armv7m_nvic_set_pending()
          * is not needed since IRQs are never escalated
          */
         offset += 0x80;
         setval = 1;
-        /* fall through */
+        fallthrough;
     case 0x280 ... 0x2bf: /* NVIC Clear pend */
         startvec = 8 * (offset - 0x280) + NVIC_FIRST_IRQ; /* vector # */
 
         for (i = 0, end = size * 8; i < end && startvec + i < s->num_irq; i++) {
             /*
              * Note that if the input line is still held high and the interrupt
              * is not active then rule R_CVJS requires that the Pending state
              * remains set; in that case we mustn't let it be cleared.
              */
             if (value & (1 << i) &&
                 (attrs.secure || s->itns[startvec + i]) &&
                 !(setval == 0 && s->vectors[startvec + i].level &&
                   !s->vectors[startvec + i].active)) {
                 s->vectors[startvec + i].pending = setval;
             }
         }
         nvic_irq_update(s);
         goto exit_ok;
     case 0x300 ... 0x33f: /* NVIC Active */
         goto exit_ok; /* R/O */
     case 0x400 ... 0x5ef: /* NVIC Priority */
         startvec = (offset - 0x400) + NVIC_FIRST_IRQ; /* vector # */
 
         for (i = 0; i < size && startvec + i < s->num_irq; i++) {
             if (attrs.secure || s->itns[startvec + i]) {
                 set_prio(s, startvec + i, false, (value >> (i * 8)) & 0xff);
             }
         }
         nvic_irq_update(s);
         goto exit_ok;
     case 0xd18 ... 0xd1b: /* System Handler Priority (SHPR1) */
         if (!arm_feature(&s->cpu->env, ARM_FEATURE_M_MAIN)) {
             goto exit_ok;
         }
-        /* fall through */
+        fallthrough;
     case 0xd1c ... 0xd23: /* System Handler Priority (SHPR2, SHPR3) */
         for (i = 0; i < size; i++) {
             unsigned hdlidx = (offset - 0xd14) + i;
             int newprio = extract32(value, i * 8, 8);
             int sbank = shpr_bank(s, hdlidx, attrs);
 
             if (sbank < 0) {
                 continue;
             }
             set_prio(s, hdlidx, sbank, newprio);
         }
         nvic_irq_update(s);
         goto exit_ok;
     case 0xd28 ... 0xd2b: /* Configurable Fault Status (CFSR) */
         if (!arm_feature(&s->cpu->env, ARM_FEATURE_M_MAIN)) {
             goto exit_ok;
         }
         /* All bits are W1C, so construct 32 bit value with 0s in
          * the parts not written by the access size
          */
         value <<= ((offset - 0xd28) * 8);
 
         if (!attrs.secure &&
             !(s->cpu->env.v7m.aircr & R_V7M_AIRCR_BFHFNMINS_MASK)) {
             /* BFSR bits are RAZ/WI for NS if BFHFNMINS is set */
             value &= ~R_V7M_CFSR_BFSR_MASK;
         }
 
         s->cpu->env.v7m.cfsr[attrs.secure] &= ~value;
         if (attrs.secure) {
             /* The BFSR bits [15:8] are shared between security states
              * and we store them in the NS copy.
              */
             s->cpu->env.v7m.cfsr[M_REG_NS] &= ~(value & R_V7M_CFSR_BFSR_MASK);
         }
         goto exit_ok;
     }
     if (size == 4) {
         nvic_writel(s, offset, value, attrs);
         goto exit_ok;
     }
     qemu_log_mask(LOG_GUEST_ERROR,
                   "NVIC: Bad write of size %d at offset 0x%x\n", size, offset);
     /* This is UNPREDICTABLE; treat as RAZ/WI */
 
  exit_ok:
     if (tcg_enabled()) {
         /* Ensure any changes made are reflected in the cached hflags. */
         arm_rebuild_hflags(&s->cpu->env);
     }
     return MEMTX_OK;
 }
hw/intc/xilinx_intc.c +1 -1
index 6e5012e66e..245f452898 100644
@@ -108,34 +108,34 @@ static uint64_t pic_read(void *opaque, hwaddr addr, unsigned int size)
 static void pic_write(void *opaque, hwaddr addr,
                       uint64_t val64, unsigned int size)
 {
     XpsIntc *p = opaque;
     uint32_t value = val64;
 
     addr >>= 2;
     D(qemu_log("%s addr=%x val=%x\n", __func__, addr * 4, value));
     switch (addr) 
     {
         case R_IAR:
             p->regs[R_ISR] &= ~value; /* ACK.  */
             break;
         case R_SIE:
             p->regs[R_IER] |= value;  /* Atomic set ie.  */
             break;
         case R_CIE:
             p->regs[R_IER] &= ~value; /* Atomic clear ie.  */
             break;
         case R_MER:
             p->regs[R_MER] = value & 0x3;
             break;
         case R_ISR:
             if ((p->regs[R_MER] & 2)) {
                 break;
             }
-            /* fallthrough */
+            fallthrough;
         default:
             if (addr < ARRAY_SIZE(p->regs))
                 p->regs[addr] = value;
             break;
     }
     update_irq(p);
 }
Signature · 1 line
2.39.2
#72 lore raw

RFC PATCH v2 60/78 qga: add fallthrough pseudo-keyword

In reply to Emmanouil Pitsidianakis

In preparation of raising -Wimplicit-fallthrough to 5, replace all fall-through comments with the fallthrough attribute pseudo-keyword.

---
 qga/main.c                  | 2 +-
 qga/vss-win32/requester.cpp | 1 +
 2 files changed, 2 insertions(+), 1 deletion(-)
qga/main.c +1 -1
index 8668b9f3d3..40471e8a0b 100644
@@ -644,37 +644,37 @@ end:
 /* false return signals GAChannel to close the current client connection */
 static gboolean channel_event_cb(GIOCondition condition, gpointer data)
 {
     GAState *s = data;
     gchar buf[QGA_READ_COUNT_DEFAULT + 1];
     gsize count;
     GIOStatus status = ga_channel_read(s->channel, buf, QGA_READ_COUNT_DEFAULT, &count);
     switch (status) {
     case G_IO_STATUS_ERROR:
         g_warning("error reading channel");
         stop_agent(s, false);
         return false;
     case G_IO_STATUS_NORMAL:
         buf[count] = 0;
         g_debug("read data, count: %d, data: %s", (int)count, buf);
         json_message_parser_feed(&s->parser, (char *)buf, (int)count);
         break;
     case G_IO_STATUS_EOF:
         g_debug("received EOF");
         if (!s->virtio) {
             return false;
         }
-        /* fall through */
+        fallthrough;
     case G_IO_STATUS_AGAIN:
         /* virtio causes us to spin here when no process is attached to
          * host-side chardev. sleep a bit to mitigate this
          */
         if (s->virtio) {
             g_usleep(G_USEC_PER_SEC / 10);
         }
         return true;
     default:
         g_warning("unknown channel read status, closing");
         return false;
     }
     return true;
 }
qga/vss-win32/requester.cpp +1 -0
index 9884c65e70..36fa4fdf28 100644
@@ -563,72 +563,73 @@ out1:
 void requester_thaw(int *num_vols, void *mountpints, ErrorSet *errset)
 {
     qga_debug_begin;
     COMPointer<IVssAsync> pAsync;
 
     if (!vss_ctx.hEventThaw) {
         /*
          * In this case, DoSnapshotSet is aborted or not started,
          * and no volumes must be frozen. We return without an error.
          */
         *num_vols = 0;
         qga_debug("finished, no volumes were frozen");
 
         return;
     }
 
     /* Tell the provider that the snapshot is finished. */
     SetEvent(vss_ctx.hEventThaw);
 
     assert(vss_ctx.pVssbc);
     assert(vss_ctx.pAsyncSnapshot);
 
     HRESULT hr = WaitForAsync(vss_ctx.pAsyncSnapshot);
     switch (hr) {
     case VSS_S_ASYNC_FINISHED:
         hr = vss_ctx.pVssbc->BackupComplete(pAsync.replace());
         if (SUCCEEDED(hr)) {
             hr = WaitForAsync(pAsync);
         }
         if (FAILED(hr)) {
             err_set(errset, hr, "failed to complete backup");
         }
         break;
 
     case (HRESULT)VSS_E_OBJECT_NOT_FOUND:
         /*
          * On Windows earlier than 2008 SP2 which does not support
          * VSS_VOLSNAP_ATTR_NO_AUTORECOVERY context, the final commit is not
          * skipped and VSS is aborted by VSS_E_OBJECT_NOT_FOUND. However, as
          * the system had been frozen until fsfreeze-thaw command was issued,
          * we ignore this error.
          */
         vss_ctx.pVssbc->AbortBackup();
         break;
 
     case VSS_E_UNEXPECTED_PROVIDER_ERROR:
         if (WaitForSingleObject(vss_ctx.hEventTimeout, 0) != WAIT_OBJECT_0) {
             err_set(errset, hr, "unexpected error in VSS provider");
             break;
         }
         /* fall through if hEventTimeout is signaled */
+        fallthrough;
 
     case (HRESULT)VSS_E_HOLD_WRITES_TIMEOUT:
         err_set(errset, hr, "couldn't hold writes: "
                 "fsfreeze is limited up to 10 seconds");
         break;
 
     default:
         err_set(errset, hr, "failed to do snapshot set");
     }
 
     if (err_is_set(errset)) {
         vss_ctx.pVssbc->AbortBackup();
     }
     *num_vols = vss_ctx.cFrozenVols;
     requester_cleanup();
 
     CoUninitialize();
     StopService();
 
     qga_debug_end;
 }
Signature · 1 line
2.39.2
#73 lore raw

RFC PATCH v2 61/78 semihosting: add fallthrough pseudo-keyword

In reply to Emmanouil Pitsidianakis

In preparation of raising -Wimplicit-fallthrough to 5, replace all fall-through comments with the fallthrough attribute pseudo-keyword.

---
 semihosting/arm-compat-semi.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
semihosting/arm-compat-semi.c +1 -1
index 329ea11260..c7d32cfca0 100644
@@ -354,446 +354,446 @@ static const uint8_t featurefile_data[] = {
 /*
  * Do a semihosting call.
  *
  * The specification always says that the "return register" either
  * returns a specific value or is corrupted, so we don't need to
  * report to our caller whether we are returning a value or trying to
  * leave the register unchanged.
  */
 void do_common_semihosting(CPUState *cs)
 {
     CPUArchState *env = cpu_env(cs);
     target_ulong args;
     target_ulong arg0, arg1, arg2, arg3;
     target_ulong ul_ret;
     char * s;
     int nr;
     int64_t elapsed;
 
     nr = common_semi_arg(cs, 0) & 0xffffffffU;
     args = common_semi_arg(cs, 1);
 
     switch (nr) {
     case TARGET_SYS_OPEN:
     {
         int ret, err = 0;
         int hostfd;
 
         GET_ARG(0);
         GET_ARG(1);
         GET_ARG(2);
         s = lock_user_string(arg0);
         if (!s) {
             goto do_fault;
         }
         if (arg1 >= 12) {
             unlock_user(s, arg0, 0);
             common_semi_cb(cs, -1, EINVAL);
             break;
         }
 
         if (strcmp(s, ":tt") == 0) {
             /*
              * We implement SH_EXT_STDOUT_STDERR, so:
              *  open for read == stdin
              *  open for write == stdout
              *  open for append == stderr
              */
             if (arg1 < 4) {
                 hostfd = STDIN_FILENO;
             } else if (arg1 < 8) {
                 hostfd = STDOUT_FILENO;
             } else {
                 hostfd = STDERR_FILENO;
             }
             ret = alloc_guestfd();
             associate_guestfd(ret, hostfd);
         } else if (strcmp(s, ":semihosting-features") == 0) {
             /* We must fail opens for modes other than 0 ('r') or 1 ('rb') */
             if (arg1 != 0 && arg1 != 1) {
                 ret = -1;
                 err = EACCES;
             } else {
                 ret = alloc_guestfd();
                 staticfile_guestfd(ret, featurefile_data,
                                    sizeof(featurefile_data));
             }
         } else {
             unlock_user(s, arg0, 0);
             semihost_sys_open(cs, common_semi_cb, arg0, arg2 + 1,
                               gdb_open_modeflags[arg1], 0644);
             break;
         }
         unlock_user(s, arg0, 0);
         common_semi_cb(cs, ret, err);
         break;
     }
 
     case TARGET_SYS_CLOSE:
         GET_ARG(0);
         semihost_sys_close(cs, common_semi_cb, arg0);
         break;
 
     case TARGET_SYS_WRITEC:
         /*
          * FIXME: the byte to be written is in a target_ulong slot,
          * which means this is wrong for a big-endian guest.
          */
         semihost_sys_write_gf(cs, common_semi_dead_cb,
                               &console_out_gf, args, 1);
         break;
 
     case TARGET_SYS_WRITE0:
         {
             ssize_t len = target_strlen(args);
             if (len < 0) {
                 common_semi_dead_cb(cs, -1, EFAULT);
             } else {
                 semihost_sys_write_gf(cs, common_semi_dead_cb,
                                       &console_out_gf, args, len);
             }
         }
         break;
 
     case TARGET_SYS_WRITE:
         GET_ARG(0);
         GET_ARG(1);
         GET_ARG(2);
         semihost_sys_write(cs, common_semi_rw_cb, arg0, arg1, arg2);
         break;
 
     case TARGET_SYS_READ:
         GET_ARG(0);
         GET_ARG(1);
         GET_ARG(2);
         semihost_sys_read(cs, common_semi_rw_cb, arg0, arg1, arg2);
         break;
 
     case TARGET_SYS_READC:
         semihost_sys_read_gf(cs, common_semi_readc_cb, &console_in_gf,
                              common_semi_stack_bottom(cs) - 1, 1);
         break;
 
     case TARGET_SYS_ISERROR:
         GET_ARG(0);
         common_semi_set_ret(cs, (target_long)arg0 < 0);
         break;
 
     case TARGET_SYS_ISTTY:
         GET_ARG(0);
         semihost_sys_isatty(cs, common_semi_istty_cb, arg0);
         break;
 
     case TARGET_SYS_SEEK:
         GET_ARG(0);
         GET_ARG(1);
         semihost_sys_lseek(cs, common_semi_seek_cb, arg0, arg1, GDB_SEEK_SET);
         break;
 
     case TARGET_SYS_FLEN:
         GET_ARG(0);
         semihost_sys_flen(cs, common_semi_flen_fstat_cb, common_semi_cb,
                           arg0, common_semi_flen_buf(cs));
         break;
 
     case TARGET_SYS_TMPNAM:
     {
         int len;
         char *p;
 
         GET_ARG(0);
         GET_ARG(1);
         GET_ARG(2);
         len = asprintf(&s, "%s/qemu-%x%02x", g_get_tmp_dir(),
                        getpid(), (int)arg1 & 0xff);
         if (len < 0) {
             common_semi_set_ret(cs, -1);
             break;
         }
 
         /* Allow for trailing NUL */
         len++;
         /* Make sure there's enough space in the buffer */
         if (len > arg2) {
             free(s);
             common_semi_set_ret(cs, -1);
             break;
         }
         p = lock_user(VERIFY_WRITE, arg0, len, 0);
         if (!p) {
             free(s);
             goto do_fault;
         }
         memcpy(p, s, len);
         unlock_user(p, arg0, len);
         free(s);
         common_semi_set_ret(cs, 0);
         break;
     }
 
     case TARGET_SYS_REMOVE:
         GET_ARG(0);
         GET_ARG(1);
         semihost_sys_remove(cs, common_semi_cb, arg0, arg1 + 1);
         break;
 
     case TARGET_SYS_RENAME:
         GET_ARG(0);
         GET_ARG(1);
         GET_ARG(2);
         GET_ARG(3);
         semihost_sys_rename(cs, common_semi_cb, arg0, arg1 + 1, arg2, arg3 + 1);
         break;
 
     case TARGET_SYS_CLOCK:
         common_semi_set_ret(cs, clock() / (CLOCKS_PER_SEC / 100));
         break;
 
     case TARGET_SYS_TIME:
         ul_ret = time(NULL);
         common_semi_cb(cs, ul_ret, ul_ret == -1 ? errno : 0);
         break;
 
     case TARGET_SYS_SYSTEM:
         GET_ARG(0);
         GET_ARG(1);
         semihost_sys_system(cs, common_semi_cb, arg0, arg1 + 1);
         break;
 
     case TARGET_SYS_ERRNO:
         common_semi_set_ret(cs, get_swi_errno(cs));
         break;
 
     case TARGET_SYS_GET_CMDLINE:
         {
             /* Build a command-line from the original argv.
              *
              * The inputs are:
              *     * arg0, pointer to a buffer of at least the size
              *               specified in arg1.
              *     * arg1, size of the buffer pointed to by arg0 in
              *               bytes.
              *
              * The outputs are:
              *     * arg0, pointer to null-terminated string of the
              *               command line.
              *     * arg1, length of the string pointed to by arg0.
              */
 
             char *output_buffer;
             size_t input_size;
             size_t output_size;
             int status = 0;
 #if !defined(CONFIG_USER_ONLY)
             const char *cmdline;
 #else
             TaskState *ts = cs->opaque;
 #endif
             GET_ARG(0);
             GET_ARG(1);
             input_size = arg1;
             /* Compute the size of the output string.  */
 #if !defined(CONFIG_USER_ONLY)
             cmdline = semihosting_get_cmdline();
             if (cmdline == NULL) {
                 cmdline = ""; /* Default to an empty line. */
             }
             output_size = strlen(cmdline) + 1; /* Count terminating 0. */
 #else
             unsigned int i;
 
             output_size = ts->info->env_strings - ts->info->arg_strings;
             if (!output_size) {
                 /*
                  * We special-case the "empty command line" case (argc==0).
                  * Just provide the terminating 0.
                  */
                 output_size = 1;
             }
 #endif
 
             if (output_size > input_size) {
                 /* Not enough space to store command-line arguments.  */
                 common_semi_cb(cs, -1, E2BIG);
                 break;
             }
 
             /* Adjust the command-line length.  */
             if (SET_ARG(1, output_size - 1)) {
                 /* Couldn't write back to argument block */
                 goto do_fault;
             }
 
             /* Lock the buffer on the ARM side.  */
             output_buffer = lock_user(VERIFY_WRITE, arg0, output_size, 0);
             if (!output_buffer) {
                 goto do_fault;
             }
 
             /* Copy the command-line arguments.  */
 #if !defined(CONFIG_USER_ONLY)
             pstrcpy(output_buffer, output_size, cmdline);
 #else
             if (output_size == 1) {
                 /* Empty command-line.  */
                 output_buffer[0] = '\0';
                 goto out;
             }
 
             if (copy_from_user(output_buffer, ts->info->arg_strings,
                                output_size)) {
                 unlock_user(output_buffer, arg0, 0);
                 goto do_fault;
             }
 
             /* Separate arguments by white spaces.  */
             for (i = 0; i < output_size - 1; i++) {
                 if (output_buffer[i] == 0) {
                     output_buffer[i] = ' ';
                 }
             }
         out:
 #endif
             /* Unlock the buffer on the ARM side.  */
             unlock_user(output_buffer, arg0, output_size);
             common_semi_cb(cs, status, 0);
         }
         break;
 
     case TARGET_SYS_HEAPINFO:
         {
             target_ulong retvals[4];
             int i;
 #ifdef CONFIG_USER_ONLY
             TaskState *ts = cs->opaque;
             target_ulong limit;
 #else
             LayoutInfo info = common_semi_find_bases(cs);
 #endif
 
             GET_ARG(0);
 
 #ifdef CONFIG_USER_ONLY
             /*
              * Some C libraries assume the heap immediately follows .bss, so
              * allocate it using sbrk.
              */
             if (!ts->heap_limit) {
                 abi_ulong ret;
 
                 ts->heap_base = do_brk(0);
                 limit = ts->heap_base + COMMON_SEMI_HEAP_SIZE;
                 /* Try a big heap, and reduce the size if that fails.  */
                 for (;;) {
                     ret = do_brk(limit);
                     if (ret >= limit) {
                         break;
                     }
                     limit = (ts->heap_base >> 1) + (limit >> 1);
                 }
                 ts->heap_limit = limit;
             }
 
             retvals[0] = ts->heap_base;
             retvals[1] = ts->heap_limit;
             retvals[2] = ts->stack_base;
             retvals[3] = 0; /* Stack limit.  */
 #else
             retvals[0] = info.heapbase;  /* Heap Base */
             retvals[1] = info.heaplimit; /* Heap Limit */
             retvals[2] = info.heaplimit; /* Stack base */
             retvals[3] = info.heapbase;  /* Stack limit.  */
 #endif
 
             for (i = 0; i < ARRAY_SIZE(retvals); i++) {
                 bool fail;
 
                 if (is_64bit_semihosting(env)) {
                     fail = put_user_u64(retvals[i], arg0 + i * 8);
                 } else {
                     fail = put_user_u32(retvals[i], arg0 + i * 4);
                 }
 
                 if (fail) {
                     /* Couldn't write back to argument block */
                     goto do_fault;
                 }
             }
             common_semi_set_ret(cs, 0);
         }
         break;
 
     case TARGET_SYS_EXIT:
     case TARGET_SYS_EXIT_EXTENDED:
     {
         uint32_t ret;
 
         if (common_semi_sys_exit_extended(cs, nr)) {
             /*
              * The A64 version of SYS_EXIT takes a parameter block,
              * so the application-exit type can return a subcode which
              * is the exit status code from the application.
              * SYS_EXIT_EXTENDED is an a new-in-v2.0 optional function
              * which allows A32/T32 guests to also provide a status code.
              */
             GET_ARG(0);
             GET_ARG(1);
 
             if (arg0 == ADP_Stopped_ApplicationExit) {
                 ret = arg1;
             } else {
                 ret = 1;
             }
         } else {
             /*
              * The A32/T32 version of SYS_EXIT specifies only
              * Stopped_ApplicationExit as normal exit, but does not
              * allow the guest to specify the exit status code.
              * Everything else is considered an error.
              */
             ret = (args == ADP_Stopped_ApplicationExit) ? 0 : 1;
         }
         gdb_exit(ret);
         exit(ret);
     }
 
     case TARGET_SYS_ELAPSED:
         elapsed = get_clock() - clock_start;
         if (sizeof(target_ulong) == 8) {
             if (SET_ARG(0, elapsed)) {
                 goto do_fault;
             }
         } else {
             if (SET_ARG(0, (uint32_t) elapsed) ||
                 SET_ARG(1, (uint32_t) (elapsed >> 32))) {
                 goto do_fault;
             }
         }
         common_semi_set_ret(cs, 0);
         break;
 
     case TARGET_SYS_TICKFREQ:
         /* qemu always uses nsec */
         common_semi_set_ret(cs, 1000000000);
         break;
 
     case TARGET_SYS_SYNCCACHE:
         /*
          * Clean the D-cache and invalidate the I-cache for the specified
          * virtual address range. This is a nop for us since we don't
          * implement caches. This is only present on A64.
          */
         if (common_semi_has_synccache(env)) {
             common_semi_set_ret(cs, 0);
             break;
         }
-        /* fall through */
+        fallthrough;
     default:
         fprintf(stderr, "qemu: Unsupported SemiHosting SWI 0x%02x\n", nr);
         cpu_dump_state(cs, stderr, 0);
         abort();
 
     do_fault:
         common_semi_cb(cs, -1, EFAULT);
         break;
     }
 }
Signature · 1 line
2.39.2
#74 lore raw

RFC PATCH v2 62/78 hw/gpio: add fallthrough pseudo-keyword

In reply to Emmanouil Pitsidianakis

In preparation of raising -Wimplicit-fallthrough to 5, replace all fall-through comments with the fallthrough attribute pseudo-keyword.

---
 hw/gpio/omap_gpio.c  | 2 +-
 hw/i2c/bitbang_i2c.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
hw/gpio/omap_gpio.c +1 -1
index a3341d70f1..82a9ea4810 100644
@@ -532,54 +532,54 @@ static uint64_t omap2_gpio_module_readp(void *opaque, hwaddr addr,
 static void omap2_gpio_module_writep(void *opaque, hwaddr addr,
                                      uint64_t value, unsigned size)
 {
     uint32_t cur = 0;
     uint32_t mask = 0xffff;
 
     if (size == 4) {
         omap2_gpio_module_write(opaque, addr, value);
         return;
     }
 
     switch (addr & ~3) {
     case 0x00:	/* GPIO_REVISION */
     case 0x14:	/* GPIO_SYSSTATUS */
     case 0x38:	/* GPIO_DATAIN */
         OMAP_RO_REG(addr);
         break;
 
     case 0x10:	/* GPIO_SYSCONFIG */
     case 0x1c:	/* GPIO_IRQENABLE1 */
     case 0x20:	/* GPIO_WAKEUPENABLE */
     case 0x2c:	/* GPIO_IRQENABLE2 */
     case 0x30:	/* GPIO_CTRL */
     case 0x34:	/* GPIO_OE */
     case 0x3c:	/* GPIO_DATAOUT */
     case 0x40:	/* GPIO_LEVELDETECT0 */
     case 0x44:	/* GPIO_LEVELDETECT1 */
     case 0x48:	/* GPIO_RISINGDETECT */
     case 0x4c:	/* GPIO_FALLINGDETECT */
     case 0x50:	/* GPIO_DEBOUNCENABLE */
     case 0x54:	/* GPIO_DEBOUNCINGTIME */
         cur = omap2_gpio_module_read(opaque, addr & ~3) &
                 ~(mask << ((addr & 3) << 3));
 
-        /* Fall through.  */
+        fallthrough;
     case 0x18:	/* GPIO_IRQSTATUS1 */
     case 0x28:	/* GPIO_IRQSTATUS2 */
     case 0x60:	/* GPIO_CLEARIRQENABLE1 */
     case 0x64:	/* GPIO_SETIRQENABLE1 */
     case 0x70:	/* GPIO_CLEARIRQENABLE2 */
     case 0x74:	/* GPIO_SETIREQNEABLE2 */
     case 0x80:	/* GPIO_CLEARWKUENA */
     case 0x84:	/* GPIO_SETWKUENA */
     case 0x90:	/* GPIO_CLEARDATAOUT */
     case 0x94:	/* GPIO_SETDATAOUT */
         value <<= (addr & 3) << 3;
         omap2_gpio_module_write(opaque, addr, cur | value);
         break;
 
     default:
         OMAP_BAD_REG(addr);
         return;
     }
 }
hw/i2c/bitbang_i2c.c +1 -1
index de5f5aacf5..3d768ae564 100644
@@ -79,99 +79,99 @@ static int bitbang_i2c_nop(bitbang_i2c_interface *i2c)
 /* Returns data line level.  */
 int bitbang_i2c_set(bitbang_i2c_interface *i2c, int line, int level)
 {
     int data;
 
     if (level != 0 && level != 1) {
         abort();
     }
 
     if (line == BITBANG_I2C_SDA) {
         if (level == i2c->last_data) {
             return bitbang_i2c_nop(i2c);
         }
         i2c->last_data = level;
         if (i2c->last_clock == 0) {
             return bitbang_i2c_nop(i2c);
         }
         if (level == 0) {
             /* START condition.  */
             bitbang_i2c_set_state(i2c, SENDING_BIT7);
             i2c->current_addr = -1;
         } else {
             /* STOP condition.  */
             bitbang_i2c_enter_stop(i2c);
         }
         return bitbang_i2c_ret(i2c, 1);
     }
 
     data = i2c->last_data;
     if (i2c->last_clock == level) {
         return bitbang_i2c_nop(i2c);
     }
     i2c->last_clock = level;
     if (level == 0) {
         /* State is set/read at the start of the clock pulse.
            release the data line at the end.  */
         return bitbang_i2c_ret(i2c, 1);
     }
     switch (i2c->state) {
     case STOPPED:
     case SENT_NACK:
         return bitbang_i2c_ret(i2c, 1);
 
     case SENDING_BIT7 ... SENDING_BIT0:
         i2c->buffer = (i2c->buffer << 1) | data;
         /* will end up in WAITING_FOR_ACK */
         bitbang_i2c_set_state(i2c, i2c->state + 1);
         return bitbang_i2c_ret(i2c, 1);
 
     case WAITING_FOR_ACK:
     {
         int ret;
 
         if (i2c->current_addr < 0) {
             i2c->current_addr = i2c->buffer;
             trace_bitbang_i2c_addr(i2c->current_addr);
             ret = i2c_start_transfer(i2c->bus, i2c->current_addr >> 1,
                                      i2c->current_addr & 1);
         } else {
             trace_bitbang_i2c_send(i2c->buffer);
             ret = i2c_send(i2c->bus, i2c->buffer);
         }
         if (ret) {
             /* NACK (either addressing a nonexistent device, or the
              * device we were sending to decided to NACK us).
              */
             bitbang_i2c_set_state(i2c, SENT_NACK);
             bitbang_i2c_enter_stop(i2c);
             return bitbang_i2c_ret(i2c, 1);
         }
         if (i2c->current_addr & 1) {
             bitbang_i2c_set_state(i2c, RECEIVING_BIT7);
         } else {
             bitbang_i2c_set_state(i2c, SENDING_BIT7);
         }
         return bitbang_i2c_ret(i2c, 0);
     }
     case RECEIVING_BIT7:
         i2c->buffer = i2c_recv(i2c->bus);
         trace_bitbang_i2c_recv(i2c->buffer);
-        /* Fall through... */
+        fallthrough;
     case RECEIVING_BIT6 ... RECEIVING_BIT0:
         data = i2c->buffer >> 7;
         /* will end up in SENDING_ACK */
         bitbang_i2c_set_state(i2c, i2c->state + 1);
         i2c->buffer <<= 1;
         return bitbang_i2c_ret(i2c, data);
 
     case SENDING_ACK:
         if (data != 0) {
             bitbang_i2c_set_state(i2c, SENT_NACK);
             i2c_nack(i2c->bus);
         } else {
             bitbang_i2c_set_state(i2c, RECEIVING_BIT7);
         }
         return bitbang_i2c_ret(i2c, 1);
     }
     abort();
 }
Signature · 1 line
2.39.2
#75 lore raw

RFC PATCH v2 63/78 hw/ipmi: add fallthrough pseudo-keyword

In reply to Emmanouil Pitsidianakis

In preparation of raising -Wimplicit-fallthrough to 5, replace all fall-through comments with the fallthrough attribute pseudo-keyword.

---
 hw/ipmi/ipmi_bmc_extern.c | 2 +-
 hw/ipmi/smbus_ipmi.c      | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)
hw/ipmi/ipmi_bmc_extern.c +1 -1
index e232d35ba2..b2ca02b21f 100644
@@ -168,15 +168,15 @@ static void extern_timeout(void *opaque)
 static void addchar(IPMIBmcExtern *ibe, unsigned char ch)
 {
     switch (ch) {
     case VM_MSG_CHAR:
     case VM_CMD_CHAR:
     case VM_ESCAPE_CHAR:
         ibe->outbuf[ibe->outlen] = VM_ESCAPE_CHAR;
         ibe->outlen++;
         ch |= 0x10;
-        /* fall through */
+        fallthrough;
     default:
         ibe->outbuf[ibe->outlen] = ch;
         ibe->outlen++;
     }
 }
hw/ipmi/smbus_ipmi.c +2 -2
index d0991ab7f9..58f5328a19 100644
@@ -207,90 +207,90 @@ static int ipmi_load_readbuf(SMBusIPMIDevice *sid)
 static int ipmi_write_data(SMBusDevice *dev, uint8_t *buf, uint8_t len)
 {
     SMBusIPMIDevice *sid = SMBUS_IPMI(dev);
     bool send = false;
     uint8_t cmd;
     int ret = 0;
 
     /* length is guaranteed to be >= 1. */
     cmd = *buf++;
     len--;
 
     /* Handle read request, which don't have any data in the write part. */
     switch (cmd) {
     case SSIF_IPMI_RESPONSE:
         sid->currblk = 0;
         ret = ipmi_load_readbuf(sid);
         break;
 
     case SSIF_IPMI_MULTI_PART_RESPONSE_MIDDLE:
         sid->currblk++;
         ret = ipmi_load_readbuf(sid);
         break;
 
     case SSIF_IPMI_MULTI_PART_RETRY:
         if (len >= 1) {
             sid->currblk = buf[0];
             ret = ipmi_load_readbuf(sid);
         } else {
             ret = -1;
         }
         break;
 
     default:
         break;
     }
 
     /* This should be a message write, make the length is there and correct. */
     if (len >= 1) {
         if (*buf != len - 1 || *buf > MAX_SSIF_IPMI_MSG_CHUNK) {
             return -1; /* Bogus message */
         }
         buf++;
         len--;
     }
 
     switch (cmd) {
     case SSIF_IPMI_REQUEST:
         send = true;
-        /* FALLTHRU */
+        fallthrough;
     case SSIF_IPMI_MULTI_PART_REQUEST_START:
         if (len < 2) {
             return -1; /* Bogus. */
         }
         memcpy(sid->inmsg, buf, len);
         sid->inlen = len;
         break;
 
     case SSIF_IPMI_MULTI_PART_REQUEST_END:
         send = true;
-        /* FALLTHRU */
+        fallthrough;
     case SSIF_IPMI_MULTI_PART_REQUEST_MIDDLE:
         if (!sid->inlen) {
             return -1; /* Bogus. */
         }
         if (sid->inlen + len > MAX_SSIF_IPMI_MSG_SIZE) {
             sid->inlen = 0; /* Discard the message. */
             return -1; /* Bogus. */
         }
         if (len < 32) {
             /*
              * Special hack, a multi-part middle that is less than 32 bytes
              * marks the end of a message.  The specification is fairly
              * confusing, so some systems to this, even sending a zero
              * length end message to mark the end.
              */
             send = true;
         }
         if (len > 0) {
             memcpy(sid->inmsg + sid->inlen, buf, len);
         }
         sid->inlen += len;
         break;
     }
 
     if (send && sid->inlen) {
         smbus_ipmi_send_msg(sid);
     }
 
     return ret;
 }
Signature · 1 line
2.39.2
#76 lore raw

RFC PATCH v2 64/78 hw/mips: add fallthrough pseudo-keyword

In reply to Emmanouil Pitsidianakis

In preparation of raising -Wimplicit-fallthrough to 5, replace all fall-through comments with the fallthrough attribute pseudo-keyword.

---
 hw/mips/boston.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
hw/mips/boston.c +6 -6
index 4e11ff6cd6..4ca53b790a 100644
@@ -164,27 +164,27 @@ static void boston_lcd_event(void *opaque, QEMUChrEvent event)
 static uint64_t boston_lcd_read(void *opaque, hwaddr addr,
                                 unsigned size)
 {
     BostonState *s = opaque;
     uint64_t val = 0;
 
     switch (size) {
     case 8:
         val |= (uint64_t)s->lcd_content[(addr + 7) & 0x7] << 56;
         val |= (uint64_t)s->lcd_content[(addr + 6) & 0x7] << 48;
         val |= (uint64_t)s->lcd_content[(addr + 5) & 0x7] << 40;
         val |= (uint64_t)s->lcd_content[(addr + 4) & 0x7] << 32;
-        /* fall through */
+        fallthrough;
     case 4:
         val |= (uint64_t)s->lcd_content[(addr + 3) & 0x7] << 24;
         val |= (uint64_t)s->lcd_content[(addr + 2) & 0x7] << 16;
-        /* fall through */
+        fallthrough;
     case 2:
         val |= (uint64_t)s->lcd_content[(addr + 1) & 0x7] << 8;
-        /* fall through */
+        fallthrough;
     case 1:
         val |= (uint64_t)s->lcd_content[(addr + 0) & 0x7];
         break;
     }
 
     return val;
 }
@@ -192,27 +192,27 @@ static uint64_t boston_lcd_read(void *opaque, hwaddr addr,
 static void boston_lcd_write(void *opaque, hwaddr addr,
                              uint64_t val, unsigned size)
 {
     BostonState *s = opaque;
 
     switch (size) {
     case 8:
         s->lcd_content[(addr + 7) & 0x7] = val >> 56;
         s->lcd_content[(addr + 6) & 0x7] = val >> 48;
         s->lcd_content[(addr + 5) & 0x7] = val >> 40;
         s->lcd_content[(addr + 4) & 0x7] = val >> 32;
-        /* fall through */
+        fallthrough;
     case 4:
         s->lcd_content[(addr + 3) & 0x7] = val >> 24;
         s->lcd_content[(addr + 2) & 0x7] = val >> 16;
-        /* fall through */
+        fallthrough;
     case 2:
         s->lcd_content[(addr + 1) & 0x7] = val >> 8;
-        /* fall through */
+        fallthrough;
     case 1:
         s->lcd_content[(addr + 0) & 0x7] = val;
         break;
     }
 
     qemu_chr_fe_printf(&s->lcd_display,
                        "\r%-8.8s", s->lcd_content);
 }
Signature · 1 line
2.39.2
#77 lore raw

RFC PATCH v2 65/78 hw/nvme: add fallthrough pseudo-keyword

In reply to Emmanouil Pitsidianakis

In preparation of raising -Wimplicit-fallthrough to 5, replace all fall-through comments with the fallthrough attribute pseudo-keyword.

---
 hw/nvme/ctrl.c | 24 ++++++++++++------------
 hw/nvme/dif.c  |  4 ++--
 2 files changed, 14 insertions(+), 14 deletions(-)
hw/nvme/ctrl.c +12 -12
index f026245d1e..acb2012fb9 100644
@@ -1912,29 +1912,29 @@ static uint16_t nvme_check_zone_read(NvmeNamespace *ns, uint64_t slba,
 static uint16_t nvme_zrm_finish(NvmeNamespace *ns, NvmeZone *zone)
 {
     switch (nvme_get_zone_state(zone)) {
     case NVME_ZONE_STATE_FULL:
         return NVME_SUCCESS;
 
     case NVME_ZONE_STATE_IMPLICITLY_OPEN:
     case NVME_ZONE_STATE_EXPLICITLY_OPEN:
         nvme_aor_dec_open(ns);
-        /* fallthrough */
+        fallthrough;
     case NVME_ZONE_STATE_CLOSED:
         nvme_aor_dec_active(ns);
 
         if (zone->d.za & NVME_ZA_ZRWA_VALID) {
             zone->d.za &= ~NVME_ZA_ZRWA_VALID;
             if (ns->params.numzrwa) {
                 ns->zns.numzrwa++;
             }
         }
 
-        /* fallthrough */
+        fallthrough;
     case NVME_ZONE_STATE_EMPTY:
         nvme_assign_zone_state(ns, zone, NVME_ZONE_STATE_FULL);
         return NVME_SUCCESS;
 
     default:
         return NVME_ZONE_INVAL_TRANSITION;
     }
 }
@@ -1942,15 +1942,15 @@ static uint16_t nvme_zrm_finish(NvmeNamespace *ns, NvmeZone *zone)
 static uint16_t nvme_zrm_close(NvmeNamespace *ns, NvmeZone *zone)
 {
     switch (nvme_get_zone_state(zone)) {
     case NVME_ZONE_STATE_EXPLICITLY_OPEN:
     case NVME_ZONE_STATE_IMPLICITLY_OPEN:
         nvme_aor_dec_open(ns);
         nvme_assign_zone_state(ns, zone, NVME_ZONE_STATE_CLOSED);
-        /* fall through */
+        fallthrough;
     case NVME_ZONE_STATE_CLOSED:
         return NVME_SUCCESS;
 
     default:
         return NVME_ZONE_INVAL_TRANSITION;
     }
 }
@@ -1958,29 +1958,29 @@ static uint16_t nvme_zrm_close(NvmeNamespace *ns, NvmeZone *zone)
 static uint16_t nvme_zrm_reset(NvmeNamespace *ns, NvmeZone *zone)
 {
     switch (nvme_get_zone_state(zone)) {
     case NVME_ZONE_STATE_EXPLICITLY_OPEN:
     case NVME_ZONE_STATE_IMPLICITLY_OPEN:
         nvme_aor_dec_open(ns);
-        /* fallthrough */
+        fallthrough;
     case NVME_ZONE_STATE_CLOSED:
         nvme_aor_dec_active(ns);
 
         if (zone->d.za & NVME_ZA_ZRWA_VALID) {
             if (ns->params.numzrwa) {
                 ns->zns.numzrwa++;
             }
         }
 
-        /* fallthrough */
+        fallthrough;
     case NVME_ZONE_STATE_FULL:
         zone->w_ptr = zone->d.zslba;
         zone->d.wp = zone->w_ptr;
         nvme_assign_zone_state(ns, zone, NVME_ZONE_STATE_EMPTY);
-        /* fallthrough */
+        fallthrough;
     case NVME_ZONE_STATE_EMPTY:
         return NVME_SUCCESS;
 
     default:
         return NVME_ZONE_INVAL_TRANSITION;
     }
 }
@@ -2010,57 +2010,57 @@ enum {
 static uint16_t nvme_zrm_open_flags(NvmeCtrl *n, NvmeNamespace *ns,
                                     NvmeZone *zone, int flags)
 {
     int act = 0;
     uint16_t status;
 
     switch (nvme_get_zone_state(zone)) {
     case NVME_ZONE_STATE_EMPTY:
         act = 1;
 
-        /* fallthrough */
+        fallthrough;
 
     case NVME_ZONE_STATE_CLOSED:
         if (n->params.auto_transition_zones) {
             nvme_zrm_auto_transition_zone(ns);
         }
         status = nvme_zns_check_resources(ns, act, 1,
                                           (flags & NVME_ZRM_ZRWA) ? 1 : 0);
         if (status) {
             return status;
         }
 
         if (act) {
             nvme_aor_inc_active(ns);
         }
 
         nvme_aor_inc_open(ns);
 
         if (flags & NVME_ZRM_AUTO) {
             nvme_assign_zone_state(ns, zone, NVME_ZONE_STATE_IMPLICITLY_OPEN);
             return NVME_SUCCESS;
         }
 
-        /* fallthrough */
+        fallthrough;
 
     case NVME_ZONE_STATE_IMPLICITLY_OPEN:
         if (flags & NVME_ZRM_AUTO) {
             return NVME_SUCCESS;
         }
 
         nvme_assign_zone_state(ns, zone, NVME_ZONE_STATE_EXPLICITLY_OPEN);
 
-        /* fallthrough */
+        fallthrough;
 
     case NVME_ZONE_STATE_EXPLICITLY_OPEN:
         if (flags & NVME_ZRM_ZRWA) {
             ns->zns.numzrwa--;
 
             zone->d.za |= NVME_ZA_ZRWA_VALID;
         }
 
         return NVME_SUCCESS;
 
     default:
         return NVME_ZONE_INVAL_TRANSITION;
     }
 }
@@ -3508,135 +3508,135 @@ static void nvme_do_write_fdp(NvmeCtrl *n, NvmeRequest *req, uint64_t slba,
 static uint16_t nvme_do_write(NvmeCtrl *n, NvmeRequest *req, bool append,
                               bool wrz)
 {
     NvmeRwCmd *rw = (NvmeRwCmd *)&req->cmd;
     NvmeNamespace *ns = req->ns;
     uint64_t slba = le64_to_cpu(rw->slba);
     uint32_t nlb = (uint32_t)le16_to_cpu(rw->nlb) + 1;
     uint16_t ctrl = le16_to_cpu(rw->control);
     uint8_t prinfo = NVME_RW_PRINFO(ctrl);
     uint64_t data_size = nvme_l2b(ns, nlb);
     uint64_t mapped_size = data_size;
     uint64_t data_offset;
     NvmeZone *zone;
     NvmeZonedResult *res = (NvmeZonedResult *)&req->cqe;
     BlockBackend *blk = ns->blkconf.blk;
     uint16_t status;
 
     if (nvme_ns_ext(ns)) {
         mapped_size += nvme_m2b(ns, nlb);
 
         if (NVME_ID_NS_DPS_TYPE(ns->id_ns.dps)) {
             bool pract = prinfo & NVME_PRINFO_PRACT;
 
             if (pract && ns->lbaf.ms == nvme_pi_tuple_size(ns)) {
                 mapped_size -= nvme_m2b(ns, nlb);
             }
         }
     }
 
     trace_pci_nvme_write(nvme_cid(req), nvme_io_opc_str(rw->opcode),
                          nvme_nsid(ns), nlb, mapped_size, slba);
 
     if (!wrz) {
         status = nvme_check_mdts(n, mapped_size);
         if (status) {
             goto invalid;
         }
     }
 
     status = nvme_check_bounds(ns, slba, nlb);
     if (status) {
         goto invalid;
     }
 
     if (ns->params.zoned) {
         zone = nvme_get_zone_by_slba(ns, slba);
         assert(zone);
 
         if (append) {
             bool piremap = !!(ctrl & NVME_RW_PIREMAP);
 
             if (unlikely(zone->d.za & NVME_ZA_ZRWA_VALID)) {
                 return NVME_INVALID_ZONE_OP | NVME_DNR;
             }
 
             if (unlikely(slba != zone->d.zslba)) {
                 trace_pci_nvme_err_append_not_at_start(slba, zone->d.zslba);
                 status = NVME_INVALID_FIELD;
                 goto invalid;
             }
 
             if (n->params.zasl &&
                 data_size > (uint64_t)n->page_size << n->params.zasl) {
                 trace_pci_nvme_err_zasl(data_size);
                 return NVME_INVALID_FIELD | NVME_DNR;
             }
 
             slba = zone->w_ptr;
             rw->slba = cpu_to_le64(slba);
             res->slba = cpu_to_le64(slba);
 
             switch (NVME_ID_NS_DPS_TYPE(ns->id_ns.dps)) {
             case NVME_ID_NS_DPS_TYPE_1:
                 if (!piremap) {
                     return NVME_INVALID_PROT_INFO | NVME_DNR;
                 }
 
-                /* fallthrough */
+                fallthrough;
 
             case NVME_ID_NS_DPS_TYPE_2:
                 if (piremap) {
                     uint32_t reftag = le32_to_cpu(rw->reftag);
                     rw->reftag = cpu_to_le32(reftag + (slba - zone->d.zslba));
                 }
 
                 break;
 
             case NVME_ID_NS_DPS_TYPE_3:
                 if (piremap) {
                     return NVME_INVALID_PROT_INFO | NVME_DNR;
                 }
 
                 break;
             }
         }
 
         status = nvme_check_zone_write(ns, zone, slba, nlb);
         if (status) {
             goto invalid;
         }
 
         status = nvme_zrm_auto(n, ns, zone);
         if (status) {
             goto invalid;
         }
 
         if (!(zone->d.za & NVME_ZA_ZRWA_VALID)) {
             zone->w_ptr += nlb;
         }
     } else if (ns->endgrp && ns->endgrp->fdp.enabled) {
         nvme_do_write_fdp(n, req, slba, nlb);
     }
 
     data_offset = nvme_l2b(ns, slba);
 
     if (NVME_ID_NS_DPS_TYPE(ns->id_ns.dps)) {
         return nvme_dif_rw(n, req);
     }
 
     if (!wrz) {
         status = nvme_map_data(n, nlb, req);
         if (status) {
             goto invalid;
         }
 
         block_acct_start(blk_get_stats(blk), &req->acct, data_size,
                          BLOCK_ACCT_WRITE);
         nvme_blk_write(blk, data_offset, BDRV_SECTOR_SIZE, nvme_rw_cb, req);
     } else {
         req->aiocb = blk_aio_pwrite_zeroes(blk, data_offset, data_size,
                                            BDRV_REQ_MAY_UNMAP, nvme_rw_cb,
                                            req);
     }
 
     return NVME_NO_COMPLETE;
@@ -3734,13 +3734,13 @@ static uint16_t nvme_finish_zone(NvmeNamespace *ns, NvmeZone *zone,
 static uint16_t nvme_offline_zone(NvmeNamespace *ns, NvmeZone *zone,
                                   NvmeZoneState state, NvmeRequest *req)
 {
     switch (state) {
     case NVME_ZONE_STATE_READ_ONLY:
         nvme_assign_zone_state(ns, zone, NVME_ZONE_STATE_OFFLINE);
-        /* fall through */
+        fallthrough;
     case NVME_ZONE_STATE_OFFLINE:
         return NVME_SUCCESS;
     default:
         return NVME_ZONE_INVAL_TRANSITION;
     }
 }
@@ -4902,39 +4902,39 @@ static uint16_t nvme_changed_nslist(NvmeCtrl *n, uint8_t rae, uint32_t buf_len,
 static uint16_t nvme_cmd_effects(NvmeCtrl *n, uint8_t csi, uint32_t buf_len,
                                  uint64_t off, NvmeRequest *req)
 {
     NvmeEffectsLog log = {};
     const uint32_t *src_iocs = NULL;
     uint32_t trans_len;
 
     if (off >= sizeof(log)) {
         trace_pci_nvme_err_invalid_log_page_offset(off, sizeof(log));
         return NVME_INVALID_FIELD | NVME_DNR;
     }
 
     switch (NVME_CC_CSS(ldl_le_p(&n->bar.cc))) {
     case NVME_CC_CSS_NVM:
         src_iocs = nvme_cse_iocs_nvm;
-        /* fall through */
+        fallthrough;
     case NVME_CC_CSS_ADMIN_ONLY:
         break;
     case NVME_CC_CSS_CSI:
         switch (csi) {
         case NVME_CSI_NVM:
             src_iocs = nvme_cse_iocs_nvm;
             break;
         case NVME_CSI_ZONED:
             src_iocs = nvme_cse_iocs_zoned;
             break;
         }
     }
 
     memcpy(log.acs, nvme_cse_acs, sizeof(nvme_cse_acs));
 
     if (src_iocs) {
         memcpy(log.iocs, src_iocs, sizeof(log.iocs));
     }
 
     trans_len = MIN(sizeof(log) - off, buf_len);
 
     return nvme_c2h(n, ((uint8_t *)&log) + off, trans_len, req);
 }
hw/nvme/dif.c +2 -2
index 01b19c3373..00dd96bdb3 100644
@@ -153,58 +153,58 @@ void nvme_dif_pract_generate_dif(NvmeNamespace *ns, uint8_t *buf, size_t len,
 static uint16_t nvme_dif_prchk_crc16(NvmeNamespace *ns, NvmeDifTuple *dif,
                                      uint8_t *buf, uint8_t *mbuf, size_t pil,
                                      uint8_t prinfo, uint16_t apptag,
                                      uint16_t appmask, uint64_t reftag)
 {
     switch (NVME_ID_NS_DPS_TYPE(ns->id_ns.dps)) {
     case NVME_ID_NS_DPS_TYPE_3:
         if (be32_to_cpu(dif->g16.reftag) != 0xffffffff) {
             break;
         }
 
-        /* fallthrough */
+        fallthrough;
     case NVME_ID_NS_DPS_TYPE_1:
     case NVME_ID_NS_DPS_TYPE_2:
         if (be16_to_cpu(dif->g16.apptag) != 0xffff) {
             break;
         }
 
         trace_pci_nvme_dif_prchk_disabled_crc16(be16_to_cpu(dif->g16.apptag),
                                                 be32_to_cpu(dif->g16.reftag));
 
         return NVME_SUCCESS;
     }
 
     if (prinfo & NVME_PRINFO_PRCHK_GUARD) {
         uint16_t crc = crc16_t10dif(0x0, buf, ns->lbasz);
 
         if (pil) {
             crc = crc16_t10dif(crc, mbuf, pil);
         }
 
         trace_pci_nvme_dif_prchk_guard_crc16(be16_to_cpu(dif->g16.guard), crc);
 
         if (be16_to_cpu(dif->g16.guard) != crc) {
             return NVME_E2E_GUARD_ERROR;
         }
     }
 
     if (prinfo & NVME_PRINFO_PRCHK_APP) {
         trace_pci_nvme_dif_prchk_apptag(be16_to_cpu(dif->g16.apptag), apptag,
                                         appmask);
 
         if ((be16_to_cpu(dif->g16.apptag) & appmask) != (apptag & appmask)) {
             return NVME_E2E_APP_ERROR;
         }
     }
 
     if (prinfo & NVME_PRINFO_PRCHK_REF) {
         trace_pci_nvme_dif_prchk_reftag_crc16(be32_to_cpu(dif->g16.reftag),
                                               reftag);
 
         if (be32_to_cpu(dif->g16.reftag) != reftag) {
             return NVME_E2E_REF_ERROR;
         }
     }
 
     return NVME_SUCCESS;
 }
@@ -212,66 +212,66 @@ static uint16_t nvme_dif_prchk_crc16(NvmeNamespace *ns, NvmeDifTuple *dif,
 static uint16_t nvme_dif_prchk_crc64(NvmeNamespace *ns, NvmeDifTuple *dif,
                                      uint8_t *buf, uint8_t *mbuf, size_t pil,
                                      uint8_t prinfo, uint16_t apptag,
                                      uint16_t appmask, uint64_t reftag)
 {
     uint64_t r = 0;
 
     r |= (uint64_t)dif->g64.sr[0] << 40;
     r |= (uint64_t)dif->g64.sr[1] << 32;
     r |= (uint64_t)dif->g64.sr[2] << 24;
     r |= (uint64_t)dif->g64.sr[3] << 16;
     r |= (uint64_t)dif->g64.sr[4] << 8;
     r |= (uint64_t)dif->g64.sr[5];
 
     switch (NVME_ID_NS_DPS_TYPE(ns->id_ns.dps)) {
     case NVME_ID_NS_DPS_TYPE_3:
         if (r != 0xffffffffffff) {
             break;
         }
 
-        /* fallthrough */
+        fallthrough;
     case NVME_ID_NS_DPS_TYPE_1:
     case NVME_ID_NS_DPS_TYPE_2:
         if (be16_to_cpu(dif->g64.apptag) != 0xffff) {
             break;
         }
 
         trace_pci_nvme_dif_prchk_disabled_crc64(be16_to_cpu(dif->g16.apptag),
                                                 r);
 
         return NVME_SUCCESS;
     }
 
     if (prinfo & NVME_PRINFO_PRCHK_GUARD) {
         uint64_t crc = crc64_nvme(~0ULL, buf, ns->lbasz);
 
         if (pil) {
             crc = crc64_nvme(~crc, mbuf, pil);
         }
 
         trace_pci_nvme_dif_prchk_guard_crc64(be64_to_cpu(dif->g64.guard), crc);
 
         if (be64_to_cpu(dif->g64.guard) != crc) {
             return NVME_E2E_GUARD_ERROR;
         }
     }
 
     if (prinfo & NVME_PRINFO_PRCHK_APP) {
         trace_pci_nvme_dif_prchk_apptag(be16_to_cpu(dif->g64.apptag), apptag,
                                         appmask);
 
         if ((be16_to_cpu(dif->g64.apptag) & appmask) != (apptag & appmask)) {
             return NVME_E2E_APP_ERROR;
         }
     }
 
     if (prinfo & NVME_PRINFO_PRCHK_REF) {
         trace_pci_nvme_dif_prchk_reftag_crc64(r, reftag);
 
         if (r != reftag) {
             return NVME_E2E_REF_ERROR;
         }
     }
 
     return NVME_SUCCESS;
 }
Signature · 1 line
2.39.2
#78 lore raw

RFC PATCH v2 66/78 hw/nvram/eeprom_at24c.c: add fallthrough pseudo-keyword

In reply to Emmanouil Pitsidianakis

In preparation of raising -Wimplicit-fallthrough to 5, replace all fall-through comments with the fallthrough attribute pseudo-keyword.

---
 hw/nvram/eeprom_at24c.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/nvram/eeprom_at24c.c +1 -1
index 3272068663..aa3685db33 100644
@@ -66,28 +66,28 @@ static
 int at24c_eeprom_event(I2CSlave *s, enum i2c_event event)
 {
     EEPROMState *ee = AT24C_EE(s);
 
     switch (event) {
     case I2C_START_SEND:
     case I2C_FINISH:
         ee->haveaddr = 0;
-        /* fallthrough */
+        fallthrough;
     case I2C_START_RECV:
         DPRINTK("clear\n");
         if (ee->blk && ee->changed) {
             int ret = blk_pwrite(ee->blk, 0, ee->rsize, ee->mem, 0);
             if (ret < 0) {
                 ERR(TYPE_AT24C_EE
                         " : failed to write backing file\n");
             }
             DPRINTK("Wrote to backing file\n");
         }
         ee->changed = false;
         break;
     case I2C_NACK:
         break;
     default:
         return -1;
     }
     return 0;
 }
Signature · 1 line
2.39.2
#79 lore raw

RFC PATCH v2 67/78 hw/pci-host/pnv_phb3.c: add fallthrough pseudo-keyword

In reply to Emmanouil Pitsidianakis

In preparation of raising -Wimplicit-fallthrough to 5, replace all fall-through comments with the fallthrough attribute pseudo-keyword.

---
 hw/pci-host/pnv_phb3.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/pci-host/pnv_phb3.c +1 -1
index c5e58f4086..6a805d3900 100644
@@ -470,121 +470,121 @@ static void pnv_phb3_update_all_msi_regions(PnvPHB3 *phb)
 void pnv_phb3_reg_write(void *opaque, hwaddr off, uint64_t val, unsigned size)
 {
     PnvPHB3 *phb = opaque;
     bool changed;
 
     /* Special case configuration data */
     if ((off & 0xfffc) == PHB_CONFIG_DATA) {
         pnv_phb3_config_write(phb, off & 0x3, size, val);
         return;
     }
 
     /* Other registers are 64-bit only */
     if (size != 8 || off & 0x7) {
         phb3_error(phb, "Invalid register access, offset: 0x%"PRIx64" size: %d",
                    off, size);
         return;
     }
 
     /* Handle masking & filtering */
     switch (off) {
     case PHB_M64_UPPER_BITS:
         val &= 0xfffc000000000000ull;
         break;
     case PHB_Q_DMA_R:
         /*
          * This is enough logic to make SW happy but we aren't actually
          * quiescing the DMAs
          */
         if (val & PHB_Q_DMA_R_AUTORESET) {
             val = 0;
         } else {
             val &= PHB_Q_DMA_R_QUIESCE_DMA;
         }
         break;
     /* LEM stuff */
     case PHB_LEM_FIR_AND_MASK:
         phb->regs[PHB_LEM_FIR_ACCUM >> 3] &= val;
         return;
     case PHB_LEM_FIR_OR_MASK:
         phb->regs[PHB_LEM_FIR_ACCUM >> 3] |= val;
         return;
     case PHB_LEM_ERROR_AND_MASK:
         phb->regs[PHB_LEM_ERROR_MASK >> 3] &= val;
         return;
     case PHB_LEM_ERROR_OR_MASK:
         phb->regs[PHB_LEM_ERROR_MASK >> 3] |= val;
         return;
     case PHB_LEM_WOF:
         val = 0;
         break;
     }
 
     /* Record whether it changed */
     changed = phb->regs[off >> 3] != val;
 
     /* Store in register cache first */
     phb->regs[off >> 3] = val;
 
     /* Handle side effects */
     switch (off) {
     case PHB_PHB3_CONFIG:
         if (changed) {
             pnv_phb3_update_all_msi_regions(phb);
         }
-        /* fall through */
+        fallthrough;
     case PHB_M32_BASE_ADDR:
     case PHB_M32_BASE_MASK:
     case PHB_M32_START_ADDR:
         if (changed) {
             pnv_phb3_check_m32(phb);
         }
         break;
     case PHB_M64_UPPER_BITS:
         if (changed) {
             pnv_phb3_check_all_m64s(phb);
         }
         break;
     case PHB_LSI_SOURCE_ID:
         if (changed) {
             pnv_phb3_lsi_src_id_write(phb, val);
         }
         break;
 
     /* IODA table accesses */
     case PHB_IODA_DATA0:
         pnv_phb3_ioda_write(phb, val);
         break;
 
     /* RTC invalidation */
     case PHB_RTC_INVALIDATE:
         pnv_phb3_rtc_invalidate(phb, val);
         break;
 
     /* FFI request */
     case PHB_FFI_REQUEST:
         pnv_phb3_msi_ffi(&phb->msis, val);
         break;
 
     /* Silent simple writes */
     case PHB_CONFIG_ADDRESS:
     case PHB_IODA_ADDR:
     case PHB_TCE_KILL:
     case PHB_TCE_SPEC_CTL:
     case PHB_PEST_BAR:
     case PHB_PELTV_BAR:
     case PHB_RTT_BAR:
     case PHB_RBA_BAR:
     case PHB_IVT_BAR:
     case PHB_FFI_LOCK:
     case PHB_LEM_FIR_ACCUM:
     case PHB_LEM_ERROR_MASK:
     case PHB_LEM_ACTION0:
     case PHB_LEM_ACTION1:
         break;
 
     /* Noise on anything else */
     default:
         qemu_log_mask(LOG_UNIMP, "phb3: reg_write 0x%"PRIx64"=%"PRIx64"\n",
                       off, val);
     }
 }
Signature · 1 line
2.39.2
#80 lore raw

RFC PATCH v2 68/78 hw/pci: add fallthrough pseudo-keyword

In reply to Emmanouil Pitsidianakis

In preparation of raising -Wimplicit-fallthrough to 5, replace all fall-through comments with the fallthrough attribute pseudo-keyword.

---
 hw/pci/pcie_aer.c | 3 ++-
 hw/pci/pcie_doe.c | 2 +-
 2 files changed, 3 insertions(+), 2 deletions(-)
hw/pci/pcie_aer.c +2 -1
index b68c7ecb49..c99ecce2a1 100644
@@ -97,71 +97,72 @@ static void aer_log_clear_all_err(PCIEAERLog *aer_log)
 int pcie_aer_init(PCIDevice *dev, uint8_t cap_ver, uint16_t offset,
                   uint16_t size, Error **errp)
 {
     pcie_add_capability(dev, PCI_EXT_CAP_ID_ERR, cap_ver,
                         offset, size);
     dev->exp.aer_cap = offset;
 
     /* clip down the value to avoid unreasonable memory usage */
     if (dev->exp.aer_log.log_max > PCIE_AER_LOG_MAX_LIMIT) {
         error_setg(errp, "Invalid aer_log_max %d. The max number of aer log "
                 "is %d", dev->exp.aer_log.log_max, PCIE_AER_LOG_MAX_LIMIT);
         return -EINVAL;
     }
     dev->exp.aer_log.log = g_malloc0(sizeof dev->exp.aer_log.log[0] *
                                         dev->exp.aer_log.log_max);
 
     pci_set_long(dev->w1cmask + offset + PCI_ERR_UNCOR_STATUS,
                  PCI_ERR_UNC_SUPPORTED);
 
     if (dev->cap_present & QEMU_PCIE_ERR_UNC_MASK) {
         pci_set_long(dev->config + offset + PCI_ERR_UNCOR_MASK,
                      PCI_ERR_UNC_MASK_DEFAULT);
         pci_set_long(dev->wmask + offset + PCI_ERR_UNCOR_MASK,
                      PCI_ERR_UNC_SUPPORTED);
     }
 
     pci_set_long(dev->config + offset + PCI_ERR_UNCOR_SEVER,
                  PCI_ERR_UNC_SEVERITY_DEFAULT);
     pci_set_long(dev->wmask + offset + PCI_ERR_UNCOR_SEVER,
                  PCI_ERR_UNC_SUPPORTED);
 
     pci_long_test_and_set_mask(dev->w1cmask + offset + PCI_ERR_COR_STATUS,
                                PCI_ERR_COR_SUPPORTED);
 
     pci_set_long(dev->config + offset + PCI_ERR_COR_MASK,
                  PCI_ERR_COR_MASK_DEFAULT);
     pci_set_long(dev->wmask + offset + PCI_ERR_COR_MASK,
                  PCI_ERR_COR_SUPPORTED);
 
     /* capabilities and control. multiple header logging is supported */
     if (dev->exp.aer_log.log_max > 0) {
         pci_set_long(dev->config + offset + PCI_ERR_CAP,
                      PCI_ERR_CAP_ECRC_GENC | PCI_ERR_CAP_ECRC_CHKC |
                      PCI_ERR_CAP_MHRC);
         pci_set_long(dev->wmask + offset + PCI_ERR_CAP,
                      PCI_ERR_CAP_ECRC_GENE | PCI_ERR_CAP_ECRC_CHKE |
                      PCI_ERR_CAP_MHRE);
     } else {
         pci_set_long(dev->config + offset + PCI_ERR_CAP,
                      PCI_ERR_CAP_ECRC_GENC | PCI_ERR_CAP_ECRC_CHKC);
         pci_set_long(dev->wmask + offset + PCI_ERR_CAP,
                      PCI_ERR_CAP_ECRC_GENE | PCI_ERR_CAP_ECRC_CHKE);
     }
 
     switch (pcie_cap_get_type(dev)) {
     case PCI_EXP_TYPE_ROOT_PORT:
         /* this case will be set by pcie_aer_root_init() */
-        /* fallthrough */
+        fallthrough;
     case PCI_EXP_TYPE_DOWNSTREAM:
+        fallthrough;
     case PCI_EXP_TYPE_UPSTREAM:
         pci_word_test_and_set_mask(dev->wmask + PCI_BRIDGE_CONTROL,
                                    PCI_BRIDGE_CTL_SERR);
         pci_long_test_and_set_mask(dev->w1cmask + PCI_STATUS,
                                    PCI_SEC_STATUS_RCV_SYSTEM_ERROR);
         break;
     default:
         /* nothing */
         break;
     }
     return 0;
 }
hw/pci/pcie_doe.c +1 -1
index 2210f86968..f04a36e664 100644
@@ -295,73 +295,73 @@ bool pcie_doe_read_config(DOECap *doe_cap, uint32_t addr, int size,
 /*
  * Write to DOE config space.
  * Return if the address not within DOE_CAP range or receives an abort
  */
 void pcie_doe_write_config(DOECap *doe_cap,
                            uint32_t addr, uint32_t val, int size)
 {
     uint16_t doe_offset = doe_cap->offset;
     uint32_t shift;
 
     if (!range_covers_byte(doe_offset + PCI_EXP_DOE_CAP,
                            PCI_DOE_SIZEOF - 4, addr)) {
         return;
     }
 
     /* Process Alignment */
     shift = addr % DWORD_BYTE;
     addr -= (doe_offset + shift);
     val = deposit32(val, shift * 8, size * 8, val);
 
     switch (addr) {
     case PCI_EXP_DOE_CTRL:
         if (FIELD_EX32(val, PCI_DOE_CAP_CONTROL, DOE_ABORT)) {
             pcie_doe_set_ready(doe_cap, 0);
             pcie_doe_set_error(doe_cap, 0);
             pcie_doe_reset_mbox(doe_cap);
             return;
         }
 
         if (FIELD_EX32(val, PCI_DOE_CAP_CONTROL, DOE_GO)) {
             pcie_doe_prepare_rsp(doe_cap);
         }
 
         if (FIELD_EX32(val, PCI_DOE_CAP_CONTROL, DOE_INTR_EN)) {
             doe_cap->ctrl.intr = 1;
         /* Clear interrupt bit located within the first byte */
         } else if (shift == 0) {
             doe_cap->ctrl.intr = 0;
         }
         break;
     case PCI_EXP_DOE_STATUS:
         if (FIELD_EX32(val, PCI_DOE_CAP_STATUS, DOE_INTR_STATUS)) {
             doe_cap->status.intr = 0;
         }
         break;
     case PCI_EXP_DOE_RD_DATA_MBOX:
         /* Mailbox should be DW accessed */
         if (size != DWORD_BYTE) {
             return;
         }
         doe_cap->read_mbox_idx++;
         if (doe_cap->read_mbox_idx == doe_cap->read_mbox_len) {
             pcie_doe_reset_mbox(doe_cap);
             pcie_doe_set_ready(doe_cap, 0);
         } else if (doe_cap->read_mbox_idx > doe_cap->read_mbox_len) {
             /* Underflow */
             pcie_doe_set_error(doe_cap, 1);
         }
         break;
     case PCI_EXP_DOE_WR_DATA_MBOX:
         /* Mailbox should be DW accessed */
         if (size != DWORD_BYTE) {
             return;
         }
         doe_cap->write_mbox[doe_cap->write_mbox_len] = val;
         doe_cap->write_mbox_len++;
         break;
     case PCI_EXP_DOE_CAP:
-        /* fallthrough */
+        fallthrough;
     default:
         break;
     }
 }
Signature · 1 line
2.39.2
#81 lore raw

RFC PATCH v2 69/78 hw/rdma/rdma_backend.c: add fallthrough pseudo-keyword

In reply to Emmanouil Pitsidianakis

In preparation of raising -Wimplicit-fallthrough to 5, replace all fall-through comments with the fallthrough attribute pseudo-keyword.

---
 hw/rdma/rdma_backend.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/rdma/rdma_backend.c +1 -1
index 6dcdfbbbe2..09e5ad961e 100644
@@ -800,50 +800,50 @@ void rdma_backend_destroy_cq(RdmaBackendCQ *cq)
 int rdma_backend_create_qp(RdmaBackendQP *qp, uint8_t qp_type,
                            RdmaBackendPD *pd, RdmaBackendCQ *scq,
                            RdmaBackendCQ *rcq, RdmaBackendSRQ *srq,
                            uint32_t max_send_wr, uint32_t max_recv_wr,
                            uint32_t max_send_sge, uint32_t max_recv_sge)
 {
     struct ibv_qp_init_attr attr = {};
 
     qp->ibqp = 0;
 
     switch (qp_type) {
     case IBV_QPT_GSI:
         return 0;
 
     case IBV_QPT_RC:
-        /* fall through */
+        fallthrough;
     case IBV_QPT_UD:
         /* do nothing */
         break;
 
     default:
         rdma_error_report("Unsupported QP type %d", qp_type);
         return -EIO;
     }
 
     attr.qp_type = qp_type;
     attr.send_cq = scq->ibcq;
     attr.recv_cq = rcq->ibcq;
     attr.cap.max_send_wr = max_send_wr;
     attr.cap.max_recv_wr = max_recv_wr;
     attr.cap.max_send_sge = max_send_sge;
     attr.cap.max_recv_sge = max_recv_sge;
     if (srq) {
         attr.srq = srq->ibsrq;
     }
 
     qp->ibqp = ibv_create_qp(pd->ibpd, &attr);
     if (!qp->ibqp) {
         rdma_error_report("ibv_create_qp fail, errno=%d", errno);
         return -EIO;
     }
 
     rdma_protected_gslist_init(&qp->cqe_ctx_list);
 
     qp->ibpd = pd->ibpd;
 
     /* TODO: Query QP to get max_inline_data and save it to be used in send */
 
     return 0;
 }
Signature · 1 line
2.39.2
#82 lore raw

RFC PATCH v2 70/78 hw/rtc: add fallthrough pseudo-keyword

In reply to Emmanouil Pitsidianakis

In preparation of raising -Wimplicit-fallthrough to 5, replace all fall-through comments with the fallthrough attribute pseudo-keyword.

---
 hw/rtc/aspeed_rtc.c  | 4 ++--
 hw/rtc/mc146818rtc.c | 4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)
hw/rtc/aspeed_rtc.c +2 -2
index fa861e2d49..59c64b01b9 100644
@@ -68,28 +68,28 @@ static uint32_t aspeed_rtc_get_counter(AspeedRtcState *rtc, int r)
 static uint64_t aspeed_rtc_read(void *opaque, hwaddr addr,
                                 unsigned size)
 {
     AspeedRtcState *rtc = opaque;
     uint64_t val;
     uint32_t r = addr >> 2;
 
     switch (r) {
     case COUNTER1:
     case COUNTER2:
         if (rtc->reg[CONTROL] & RTC_ENABLED) {
             rtc->reg[r] = aspeed_rtc_get_counter(rtc, r);
         }
-        /* fall through */
+        fallthrough;
     case CONTROL:
         val = rtc->reg[r];
         break;
     case ALARM:
     case ALARM_STATUS:
     default:
         qemu_log_mask(LOG_UNIMP, "%s: 0x%" HWADDR_PRIx "\n", __func__, addr);
         return 0;
     }
 
     trace_aspeed_rtc_read(addr, val);
 
     return val;
 }
@@ -97,25 +97,25 @@ static uint64_t aspeed_rtc_read(void *opaque, hwaddr addr,
 static void aspeed_rtc_write(void *opaque, hwaddr addr,
                              uint64_t val, unsigned size)
 {
     AspeedRtcState *rtc = opaque;
     uint32_t r = addr >> 2;
 
     switch (r) {
     case COUNTER1:
     case COUNTER2:
         if (!(rtc->reg[CONTROL] & RTC_UNLOCKED)) {
             break;
         }
-        /* fall through */
+        fallthrough;
     case CONTROL:
         rtc->reg[r] = val;
         aspeed_rtc_calc_offset(rtc);
         break;
     case ALARM:
     case ALARM_STATUS:
     default:
         qemu_log_mask(LOG_UNIMP, "%s: 0x%" HWADDR_PRIx "\n", __func__, addr);
         break;
     }
     trace_aspeed_rtc_write(addr, val);
 }
hw/rtc/mc146818rtc.c +2 -2
index c27c362db9..6b6eef94fd 100644
@@ -439,120 +439,120 @@ static void rtc_update_timer(void *opaque)
 static void cmos_ioport_write(void *opaque, hwaddr addr,
                               uint64_t data, unsigned size)
 {
     MC146818RtcState *s = opaque;
     uint32_t old_period;
     bool update_periodic_timer;
 
     if ((addr & 1) == 0) {
         s->cmos_index = data & 0x7f;
     } else {
         CMOS_DPRINTF("cmos: write index=0x%02x val=0x%02" PRIx64 "\n",
                      s->cmos_index, data);
         switch(s->cmos_index) {
         case RTC_SECONDS_ALARM:
         case RTC_MINUTES_ALARM:
         case RTC_HOURS_ALARM:
             s->cmos_data[s->cmos_index] = data;
             check_update_timer(s);
             break;
         case RTC_IBM_PS2_CENTURY_BYTE:
             s->cmos_index = RTC_CENTURY;
-            /* fall through */
+            fallthrough;
         case RTC_CENTURY:
         case RTC_SECONDS:
         case RTC_MINUTES:
         case RTC_HOURS:
         case RTC_DAY_OF_WEEK:
         case RTC_DAY_OF_MONTH:
         case RTC_MONTH:
         case RTC_YEAR:
             s->cmos_data[s->cmos_index] = data;
             /* if in set mode, do not update the time */
             if (rtc_running(s)) {
                 rtc_set_time(s);
                 check_update_timer(s);
             }
             break;
         case RTC_REG_A:
             update_periodic_timer = (s->cmos_data[RTC_REG_A] ^ data) & 0x0f;
             old_period = rtc_periodic_clock_ticks(s);
 
             if ((data & 0x60) == 0x60) {
                 if (rtc_running(s)) {
                     rtc_update_time(s);
                 }
                 /* What happens to UIP when divider reset is enabled is
                  * unclear from the datasheet.  Shouldn't matter much
                  * though.
                  */
                 s->cmos_data[RTC_REG_A] &= ~REG_A_UIP;
             } else if (((s->cmos_data[RTC_REG_A] & 0x60) == 0x60) &&
                     (data & 0x70)  <= 0x20) {
                 /* when the divider reset is removed, the first update cycle
                  * begins one-half second later*/
                 if (!(s->cmos_data[RTC_REG_B] & REG_B_SET)) {
                     s->offset = 500000000;
                     rtc_set_time(s);
                 }
                 s->cmos_data[RTC_REG_A] &= ~REG_A_UIP;
             }
             /* UIP bit is read only */
             s->cmos_data[RTC_REG_A] = (data & ~REG_A_UIP) |
                 (s->cmos_data[RTC_REG_A] & REG_A_UIP);
 
             if (update_periodic_timer) {
                 periodic_timer_update(s, qemu_clock_get_ns(rtc_clock),
                                       old_period, true);
             }
 
             check_update_timer(s);
             break;
         case RTC_REG_B:
             update_periodic_timer = (s->cmos_data[RTC_REG_B] ^ data)
                                        & REG_B_PIE;
             old_period = rtc_periodic_clock_ticks(s);
 
             if (data & REG_B_SET) {
                 /* update cmos to when the rtc was stopping */
                 if (rtc_running(s)) {
                     rtc_update_time(s);
                 }
                 /* set mode: reset UIP mode */
                 s->cmos_data[RTC_REG_A] &= ~REG_A_UIP;
                 data &= ~REG_B_UIE;
             } else {
                 /* if disabling set mode, update the time */
                 if ((s->cmos_data[RTC_REG_B] & REG_B_SET) &&
                     (s->cmos_data[RTC_REG_A] & 0x70) <= 0x20) {
                     s->offset = get_guest_rtc_ns(s) % NANOSECONDS_PER_SECOND;
                     rtc_set_time(s);
                 }
             }
             /* if an interrupt flag is already set when the interrupt
              * becomes enabled, raise an interrupt immediately.  */
             if (data & s->cmos_data[RTC_REG_C] & REG_C_MASK) {
                 s->cmos_data[RTC_REG_C] |= REG_C_IRQF;
                 qemu_irq_raise(s->irq);
             } else {
                 s->cmos_data[RTC_REG_C] &= ~REG_C_IRQF;
                 qemu_irq_lower(s->irq);
             }
             s->cmos_data[RTC_REG_B] = data;
 
             if (update_periodic_timer) {
                 periodic_timer_update(s, qemu_clock_get_ns(rtc_clock),
                                       old_period, true);
             }
 
             check_update_timer(s);
             break;
         case RTC_REG_C:
         case RTC_REG_D:
             /* cannot write to them */
             break;
         default:
             s->cmos_data[s->cmos_index] = data;
             break;
         }
     }
 }
@@ -678,63 +678,63 @@ static int update_in_progress(MC146818RtcState *s)
 static uint64_t cmos_ioport_read(void *opaque, hwaddr addr,
                                  unsigned size)
 {
     MC146818RtcState *s = opaque;
     int ret;
     if ((addr & 1) == 0) {
         return 0xff;
     } else {
         switch(s->cmos_index) {
         case RTC_IBM_PS2_CENTURY_BYTE:
             s->cmos_index = RTC_CENTURY;
-            /* fall through */
+            fallthrough;
         case RTC_CENTURY:
         case RTC_SECONDS:
         case RTC_MINUTES:
         case RTC_HOURS:
         case RTC_DAY_OF_WEEK:
         case RTC_DAY_OF_MONTH:
         case RTC_MONTH:
         case RTC_YEAR:
             /* if not in set mode, calibrate cmos before
              * reading*/
             if (rtc_running(s)) {
                 rtc_update_time(s);
             }
             ret = s->cmos_data[s->cmos_index];
             break;
         case RTC_REG_A:
             ret = s->cmos_data[s->cmos_index];
             if (update_in_progress(s)) {
                 ret |= REG_A_UIP;
             }
             break;
         case RTC_REG_C:
             ret = s->cmos_data[s->cmos_index];
             qemu_irq_lower(s->irq);
             s->cmos_data[RTC_REG_C] = 0x00;
             if (ret & (REG_C_UF | REG_C_AF)) {
                 check_update_timer(s);
             }
 
             if(s->irq_coalesced &&
                     (s->cmos_data[RTC_REG_B] & REG_B_PIE) &&
                     s->irq_reinject_on_ack_count < RTC_REINJECT_ON_ACK_COUNT) {
                 s->irq_reinject_on_ack_count++;
                 s->cmos_data[RTC_REG_C] |= REG_C_IRQF | REG_C_PF;
                 DPRINTF_C("cmos: injecting on ack\n");
                 if (rtc_policy_slew_deliver_irq(s)) {
                     s->irq_coalesced--;
                     DPRINTF_C("cmos: coalesced irqs decreased to %d\n",
                               s->irq_coalesced);
                 }
             }
             break;
         default:
             ret = s->cmos_data[s->cmos_index];
             break;
         }
         CMOS_DPRINTF("cmos: read index=0x%02x val=0x%02x\n",
                      s->cmos_index, ret);
         return ret;
     }
 }
Signature · 1 line
2.39.2
#83 lore raw

RFC PATCH v2 71/78 hw/s390x: add fallthrough pseudo-keyword

In reply to Emmanouil Pitsidianakis

In preparation of raising -Wimplicit-fallthrough to 5, replace all fall-through comments with the fallthrough attribute pseudo-keyword.

---
 hw/s390x/ipl.c           | 1 +
 hw/s390x/s390-pci-inst.c | 4 ++--
 hw/s390x/sclp.c          | 4 ++--
 3 files changed, 5 insertions(+), 4 deletions(-)
hw/s390x/ipl.c +1 -0
index 515dcf51b5..da2333846f 100644
@@ -394,57 +394,58 @@ static CcwDevice *s390_get_ccw_device(DeviceState *dev_st, int *devtype)
 static bool s390_gen_initial_iplb(S390IPLState *ipl)
 {
     DeviceState *dev_st;
     CcwDevice *ccw_dev = NULL;
     SCSIDevice *sd;
     int devtype;
 
     dev_st = get_boot_device(0);
     if (dev_st) {
         ccw_dev = s390_get_ccw_device(dev_st, &devtype);
     }
 
     /*
      * Currently allow IPL only from CCW devices.
      */
     if (ccw_dev) {
         switch (devtype) {
         case CCW_DEVTYPE_SCSI:
             sd = SCSI_DEVICE(dev_st);
             ipl->iplb.len = cpu_to_be32(S390_IPLB_MIN_QEMU_SCSI_LEN);
             ipl->iplb.blk0_len =
                 cpu_to_be32(S390_IPLB_MIN_QEMU_SCSI_LEN - S390_IPLB_HEADER_LEN);
             ipl->iplb.pbt = S390_IPL_TYPE_QEMU_SCSI;
             ipl->iplb.scsi.lun = cpu_to_be32(sd->lun);
             ipl->iplb.scsi.target = cpu_to_be16(sd->id);
             ipl->iplb.scsi.channel = cpu_to_be16(sd->channel);
             ipl->iplb.scsi.devno = cpu_to_be16(ccw_dev->sch->devno);
             ipl->iplb.scsi.ssid = ccw_dev->sch->ssid & 3;
             break;
         case CCW_DEVTYPE_VFIO:
             ipl->iplb.len = cpu_to_be32(S390_IPLB_MIN_CCW_LEN);
             ipl->iplb.pbt = S390_IPL_TYPE_CCW;
             ipl->iplb.ccw.devno = cpu_to_be16(ccw_dev->sch->devno);
             ipl->iplb.ccw.ssid = ccw_dev->sch->ssid & 3;
             break;
         case CCW_DEVTYPE_VIRTIO_NET:
             ipl->netboot = true;
             /* Fall through to CCW_DEVTYPE_VIRTIO case */
+            fallthrough;
         case CCW_DEVTYPE_VIRTIO:
             ipl->iplb.len = cpu_to_be32(S390_IPLB_MIN_CCW_LEN);
             ipl->iplb.blk0_len =
                 cpu_to_be32(S390_IPLB_MIN_CCW_LEN - S390_IPLB_HEADER_LEN);
             ipl->iplb.pbt = S390_IPL_TYPE_CCW;
             ipl->iplb.ccw.devno = cpu_to_be16(ccw_dev->sch->devno);
             ipl->iplb.ccw.ssid = ccw_dev->sch->ssid & 3;
             break;
         }
 
         if (!s390_ipl_set_loadparm(ipl->iplb.loadparm)) {
             ipl->iplb.flags |= DIAG308_FLAGS_LP_VALID;
         }
 
         return true;
     }
 
     return false;
 }
hw/s390x/s390-pci-inst.c +2 -2
index 30149546c0..171320384c 100644
@@ -1330,83 +1330,83 @@ int mpcifc_service_call(S390CPU *cpu, uint8_t r1, uint64_t fiba, uint8_t ar,
 int stpcifc_service_call(S390CPU *cpu, uint8_t r1, uint64_t fiba, uint8_t ar,
                          uintptr_t ra)
 {
     CPUS390XState *env = &cpu->env;
     uint8_t dmaas;
     uint32_t fh;
     ZpciFib fib;
     S390PCIBusDevice *pbdev;
     uint32_t data;
     uint64_t cc = ZPCI_PCI_LS_OK;
 
     if (env->psw.mask & PSW_MASK_PSTATE) {
         s390_program_interrupt(env, PGM_PRIVILEGED, ra);
         return 0;
     }
 
     fh = env->regs[r1] >> 32;
     dmaas = (env->regs[r1] >> 16) & 0xff;
 
     if (dmaas) {
         setcc(cpu, ZPCI_PCI_LS_ERR);
         s390_set_status_code(env, r1, ZPCI_STPCIFC_ST_INVAL_DMAAS);
         return 0;
     }
 
     if (fiba & 0x7) {
         s390_program_interrupt(env, PGM_SPECIFICATION, ra);
         return 0;
     }
 
     pbdev = s390_pci_find_dev_by_idx(s390_get_phb(), fh & FH_MASK_INDEX);
     if (!pbdev) {
         setcc(cpu, ZPCI_PCI_LS_INVAL_HANDLE);
         return 0;
     }
 
     memset(&fib, 0, sizeof(fib));
 
     switch (pbdev->state) {
     case ZPCI_FS_RESERVED:
     case ZPCI_FS_STANDBY:
         setcc(cpu, ZPCI_PCI_LS_INVAL_HANDLE);
         return 0;
     case ZPCI_FS_DISABLED:
         if (fh & FH_MASK_ENABLE) {
             setcc(cpu, ZPCI_PCI_LS_INVAL_HANDLE);
             return 0;
         }
         goto out;
     /* BLOCKED bit is set to one coincident with the setting of ERROR bit.
      * FH Enabled bit is set to one in states of ENABLED, BLOCKED or ERROR. */
     case ZPCI_FS_ERROR:
         fib.fc |= 0x20;
-        /* fallthrough */
+        fallthrough;
     case ZPCI_FS_BLOCKED:
         fib.fc |= 0x40;
-        /* fallthrough */
+        fallthrough;
     case ZPCI_FS_ENABLED:
         fib.fc |= 0x80;
         if (pbdev->iommu->enabled) {
             fib.fc |= 0x10;
         }
         if (!(fh & FH_MASK_ENABLE)) {
             env->regs[r1] |= 1ULL << 63;
         }
         break;
     case ZPCI_FS_PERMANENT_ERROR:
         setcc(cpu, ZPCI_PCI_LS_ERR);
         s390_set_status_code(env, r1, ZPCI_STPCIFC_ST_PERM_ERROR);
         return 0;
     }
 
     stq_p(&fib.pba, pbdev->iommu->pba);
     stq_p(&fib.pal, pbdev->iommu->pal);
     stq_p(&fib.iota, pbdev->iommu->g_iota);
     stq_p(&fib.aibv, pbdev->routes.adapter.ind_addr);
     stq_p(&fib.aisb, pbdev->routes.adapter.summary_addr);
     stq_p(&fib.fmb_addr, pbdev->fmb_addr);
 
     data = ((uint32_t)pbdev->isc << 28) | ((uint32_t)pbdev->noi << 16) |
            ((uint32_t)pbdev->routes.adapter.ind_offset << 8) |
            ((uint32_t)pbdev->sum << 7) | pbdev->routes.adapter.summary_offset;
     stl_p(&fib.data, data);
hw/s390x/sclp.c +2 -2
index eff74479f4..9b8c7ff043 100644
@@ -50,28 +50,28 @@ static inline bool sclp_command_code_valid(uint32_t code)
 static bool sccb_verify_boundary(uint64_t sccb_addr, uint16_t sccb_len,
                                  uint32_t code)
 {
     uint64_t sccb_max_addr = sccb_addr + sccb_len - 1;
     uint64_t sccb_boundary = (sccb_addr & TARGET_PAGE_MASK) + TARGET_PAGE_SIZE;
 
     switch (code & SCLP_CMD_CODE_MASK) {
     case SCLP_CMDW_READ_SCP_INFO:
     case SCLP_CMDW_READ_SCP_INFO_FORCED:
     case SCLP_CMDW_READ_CPU_INFO:
         /*
          * An extended-length SCCB is only allowed for Read SCP/CPU Info and
          * is allowed to exceed the 4k boundary. The respective commands will
          * set the length field to the required length if an insufficient
          * SCCB length is provided.
          */
         if (s390_has_feat(S390_FEAT_EXTENDED_LENGTH_SCCB)) {
             return true;
         }
-        /* fallthrough */
+        fallthrough;
     default:
         if (sccb_max_addr < sccb_boundary) {
             return true;
         }
     }
 
     return false;
 }
@@ -207,28 +207,28 @@ static void sclp_read_cpu_info(SCLPDevice *sclp, SCCB *sccb)
 static void sclp_configure_io_adapter(SCLPDevice *sclp, SCCB *sccb,
                                       bool configure)
 {
     int rc;
 
     if (be16_to_cpu(sccb->h.length) < 16) {
         rc = SCLP_RC_INSUFFICIENT_SCCB_LENGTH;
         goto out_err;
     }
 
     switch (((IoaCfgSccb *)sccb)->atype) {
     case SCLP_RECONFIG_PCI_ATYPE:
         if (s390_has_feat(S390_FEAT_ZPCI)) {
             if (configure) {
                 s390_pci_sclp_configure(sccb);
             } else {
                 s390_pci_sclp_deconfigure(sccb);
             }
             return;
         }
-        /* fallthrough */
+        fallthrough;
     default:
         rc = SCLP_RC_ADAPTER_TYPE_NOT_RECOGNIZED;
     }
 
  out_err:
     sccb->h.response_code = cpu_to_be16(rc);
 }
Signature · 1 line
2.39.2
Reviewed-by on v2 71/78
#84 lore raw

Re: [RFC PATCH v2 71/78] hw/s390x: add fallthrough pseudo-keyword

Quoted 5 lines · Emmanouil Pitsidianakis

In preparation of raising -Wimplicit-fallthrough to 5, replace all fall-through comments with the fallthrough attribute pseudo-keyword.

---

See Rb's on the other two patches I was CCed in v1.

Signature · 3 lines
Cheers,

David / dhildenb
#85 lore raw

RFC PATCH v2 72/78 hw/ssi: add fallthrough pseudo-keyword

In reply to Emmanouil Pitsidianakis

In preparation of raising -Wimplicit-fallthrough to 5, replace all fall-through comments with the fallthrough attribute pseudo-keyword.

---
 hw/ssi/npcm7xx_fiu.c | 14 ++++++-------
 hw/ssi/omap_spi.c    | 48 ++++++++++++++++++++++----------------------
 2 files changed, 31 insertions(+), 31 deletions(-)
hw/ssi/npcm7xx_fiu.c +7 -7
index 4eedb2927e..fadd66a675 100644
@@ -145,103 +145,103 @@ static void npcm7xx_fiu_deselect(NPCM7xxFIUState *s)
 /* Direct flash memory read handler. */
 static uint64_t npcm7xx_fiu_flash_read(void *opaque, hwaddr addr,
                                        unsigned int size)
 {
     NPCM7xxFIUFlash *f = opaque;
     NPCM7xxFIUState *fiu = f->fiu;
     uint64_t value = 0;
     uint32_t drd_cfg;
     int dummy_cycles;
     int i;
 
     if (fiu->active_cs != -1) {
         qemu_log_mask(LOG_GUEST_ERROR,
                       "%s: direct flash read with CS%d already active",
                       DEVICE(fiu)->canonical_path, fiu->active_cs);
     }
 
     npcm7xx_fiu_select(fiu, npcm7xx_fiu_cs_index(fiu, f));
 
     drd_cfg = fiu->regs[NPCM7XX_FIU_DRD_CFG];
     ssi_transfer(fiu->spi, FIU_DRD_CFG_RDCMD(drd_cfg));
 
     switch (FIU_DRD_CFG_ADDSIZ(drd_cfg)) {
     case FIU_ADDSIZ_4BYTES:
         ssi_transfer(fiu->spi, extract32(addr, 24, 8));
-        /* fall through */
+        fallthrough;
     case FIU_ADDSIZ_3BYTES:
         ssi_transfer(fiu->spi, extract32(addr, 16, 8));
         ssi_transfer(fiu->spi, extract32(addr, 8, 8));
         ssi_transfer(fiu->spi, extract32(addr, 0, 8));
         break;
 
     default:
         qemu_log_mask(LOG_GUEST_ERROR, "%s: bad address size %d\n",
                       DEVICE(fiu)->canonical_path, FIU_DRD_CFG_ADDSIZ(drd_cfg));
         break;
     }
 
     /* Flash chip model expects one transfer per dummy bit, not byte */
     dummy_cycles =
         (FIU_DRD_CFG_DBW(drd_cfg) * 8) >> FIU_DRD_CFG_ACCTYPE(drd_cfg);
     for (i = 0; i < dummy_cycles; i++) {
         ssi_transfer(fiu->spi, 0);
     }
 
     for (i = 0; i < size; i++) {
         value = deposit64(value, 8 * i, 8, ssi_transfer(fiu->spi, 0));
     }
 
     trace_npcm7xx_fiu_flash_read(DEVICE(fiu)->canonical_path, fiu->active_cs,
                                  addr, size, value);
 
     npcm7xx_fiu_deselect(fiu);
 
     return value;
 }
 
 /* Direct flash memory write handler. */
 static void npcm7xx_fiu_flash_write(void *opaque, hwaddr addr, uint64_t v,
                                     unsigned int size)
 {
     NPCM7xxFIUFlash *f = opaque;
     NPCM7xxFIUState *fiu = f->fiu;
     uint32_t dwr_cfg;
     unsigned cs_id;
     int i;
 
     if (fiu->active_cs != -1) {
         qemu_log_mask(LOG_GUEST_ERROR,
                       "%s: direct flash write with CS%d already active",
                       DEVICE(fiu)->canonical_path, fiu->active_cs);
     }
 
     cs_id = npcm7xx_fiu_cs_index(fiu, f);
     trace_npcm7xx_fiu_flash_write(DEVICE(fiu)->canonical_path, cs_id, addr,
                                   size, v);
     npcm7xx_fiu_select(fiu, cs_id);
 
     dwr_cfg = fiu->regs[NPCM7XX_FIU_DWR_CFG];
     ssi_transfer(fiu->spi, FIU_DWR_CFG_WRCMD(dwr_cfg));
 
     switch (FIU_DWR_CFG_ADDSIZ(dwr_cfg)) {
     case FIU_ADDSIZ_4BYTES:
         ssi_transfer(fiu->spi, extract32(addr, 24, 8));
-        /* fall through */
+        fallthrough;
     case FIU_ADDSIZ_3BYTES:
         ssi_transfer(fiu->spi, extract32(addr, 16, 8));
         ssi_transfer(fiu->spi, extract32(addr, 8, 8));
         ssi_transfer(fiu->spi, extract32(addr, 0, 8));
         break;
 
     default:
         qemu_log_mask(LOG_GUEST_ERROR, "%s: bad address size %d\n",
                       DEVICE(fiu)->canonical_path, FIU_DWR_CFG_ADDSIZ(dwr_cfg));
         break;
     }
 
     for (i = 0; i < size; i++) {
         ssi_transfer(fiu->spi, extract64(v, i * 8, 8));
     }
 
     npcm7xx_fiu_deselect(fiu);
 }
@@ -282,22 +282,22 @@ static uint64_t npcm7xx_fiu_ctrl_read(void *opaque, hwaddr addr,
 /* Send the specified number of address bytes from the UMA address register. */
 static void send_address(SSIBus *spi, unsigned int addsiz, uint32_t addr)
 {
     switch (addsiz) {
     case 4:
         ssi_transfer(spi, extract32(addr, 24, 8));
-        /* fall through */
+        fallthrough;
     case 3:
         ssi_transfer(spi, extract32(addr, 16, 8));
-        /* fall through */
+        fallthrough;
     case 2:
         ssi_transfer(spi, extract32(addr, 8, 8));
-        /* fall through */
+        fallthrough;
     case 1:
         ssi_transfer(spi, extract32(addr, 0, 8));
-        /* fall through */
+        fallthrough;
     case 0:
         break;
     }
 }
 
 /* Send the number of dummy bits specified in the UMA config register. */
@@ -378,79 +378,79 @@ static void npcm7xx_fiu_uma_transaction(NPCM7xxFIUState *s)
 /* Control register write handler. */
 static void npcm7xx_fiu_ctrl_write(void *opaque, hwaddr addr, uint64_t v,
                                    unsigned int size)
 {
     hwaddr reg = addr / sizeof(uint32_t);
     NPCM7xxFIUState *s = opaque;
     uint32_t value = v;
 
     trace_npcm7xx_fiu_ctrl_write(DEVICE(s)->canonical_path, addr, value);
 
     switch (reg) {
     case NPCM7XX_FIU_UMA_CFG:
         if (s->regs[reg] & FIU_UMA_CFG_CMMLCK) {
             value &= ~FIU_UMA_CFG_CMMLCK_MASK;
             value |= (s->regs[reg] & FIU_UMA_CFG_CMMLCK_MASK);
         }
-        /* fall through */
+        fallthrough;
     case NPCM7XX_FIU_DRD_CFG:
     case NPCM7XX_FIU_DWR_CFG:
         if (s->regs[reg] & NPCM7XX_FIU_CFG_LCK) {
             qemu_log_mask(LOG_GUEST_ERROR,
                           "%s: write to locked register @ 0x%" PRIx64 "\n",
                           DEVICE(s)->canonical_path, addr);
             return;
         }
         s->regs[reg] = value;
         break;
 
     case NPCM7XX_FIU_UMA_CTS:
         if (value & FIU_UMA_CTS_RDYST) {
             value &= ~FIU_UMA_CTS_RDYST;
         } else {
             value |= s->regs[reg] & FIU_UMA_CTS_RDYST;
         }
         if ((s->regs[reg] ^ value) & FIU_UMA_CTS_SW_CS) {
             if (value & FIU_UMA_CTS_SW_CS) {
                 /*
                  * Don't drop CS if there's a transfer in progress, or we're
                  * about to start one.
                  */
                 if (!((value | s->regs[reg]) & FIU_UMA_CTS_EXEC_DONE)) {
                     npcm7xx_fiu_deselect(s);
                 }
             } else {
                 int cs_id = FIU_UMA_CTS_DEV_NUM(s->regs[NPCM7XX_FIU_UMA_CTS]);
                 npcm7xx_fiu_select(s, cs_id);
             }
         }
         s->regs[reg] = value | (s->regs[reg] & FIU_UMA_CTS_EXEC_DONE);
         if (value & FIU_UMA_CTS_EXEC_DONE) {
             npcm7xx_fiu_uma_transaction(s);
         }
         break;
 
     case NPCM7XX_FIU_UMA_DR0 ... NPCM7XX_FIU_UMA_DR3:
         qemu_log_mask(LOG_GUEST_ERROR,
                       "%s: write to read-only register @ 0x%" PRIx64 "\n",
                       DEVICE(s)->canonical_path, addr);
         return;
 
     case NPCM7XX_FIU_PRT_CFG:
     case NPCM7XX_FIU_PRT_CMD0 ... NPCM7XX_FIU_PRT_CMD9:
         qemu_log_mask(LOG_UNIMP, "%s: PRT is not implemented\n", __func__);
         break;
 
     case NPCM7XX_FIU_UMA_CMD:
     case NPCM7XX_FIU_UMA_ADDR:
     case NPCM7XX_FIU_UMA_DW0 ... NPCM7XX_FIU_UMA_DW3:
     case NPCM7XX_FIU_CFG:
         s->regs[reg] = value;
         break;
 
     default:
         qemu_log_mask(LOG_GUEST_ERROR,
                       "%s: write to invalid offset 0x%" PRIx64 "\n",
                       DEVICE(s)->canonical_path, addr);
         return;
     }
 }
hw/ssi/omap_spi.c +24 -24

228 lines not on this page · raw message

Signature · 1 line
2.39.2
#86 lore raw

RFC PATCH v2 73/78 hw/watchdog/wdt_diag288.c: add fallthrough pseudo-keyword

In reply to Emmanouil Pitsidianakis

In preparation of raising -Wimplicit-fallthrough to 5, replace all fall-through comments with the fallthrough attribute pseudo-keyword.

---
 hw/watchdog/wdt_diag288.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/watchdog/wdt_diag288.c +1 -1
index 76d89fbf78..24fb7fcb62 100644
@@ -66,28 +66,28 @@ static void diag288_timer_expired(void *dev)
 static int wdt_diag288_handle_timer(DIAG288State *diag288,
                                      uint64_t func, uint64_t timeout)
 {
     switch (func) {
     case WDT_DIAG288_INIT:
         diag288->enabled = true;
-        /* fall through */
+        fallthrough;
     case WDT_DIAG288_CHANGE:
         if (!diag288->enabled) {
             return -1;
         }
         timer_mod(diag288->timer,
                   qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) +
                   timeout * NANOSECONDS_PER_SECOND);
         break;
     case WDT_DIAG288_CANCEL:
         if (!diag288->enabled) {
             return -1;
         }
         diag288->enabled = false;
         timer_del(diag288->timer);
         break;
     default:
         return -1;
     }
 
     return 0;
 }
Signature · 1 line
2.39.2
#87 lore raw

RFC PATCH v2 74/78 hw/cxl/cxl-device-utils.c: add fallthrough pseudo-keyword

In reply to Emmanouil Pitsidianakis

In preparation of raising -Wimplicit-fallthrough to 5, replace all fall-through comments with the fallthrough attribute pseudo-keyword.

---
 hw/cxl/cxl-device-utils.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
hw/cxl/cxl-device-utils.c +2 -2
index bd68328032..63f009847e 100644
@@ -78,18 +78,18 @@ static uint64_t mailbox_reg_read(void *opaque, hwaddr offset, unsigned size)
 static void mailbox_mem_writel(uint32_t *reg_state, hwaddr offset,
                                uint64_t value)
 {
     switch (offset) {
     case A_CXL_DEV_MAILBOX_CTRL:
-        /* fallthrough */
+        fallthrough;
     case A_CXL_DEV_MAILBOX_CAP:
         /* RO register */
         break;
     default:
         qemu_log_mask(LOG_UNIMP,
                       "%s Unexpected 32-bit access to 0x%" PRIx64 " (WI)\n",
                       __func__, offset);
         return;
     }
 
     reg_state[offset / sizeof(*reg_state)] = value;
 }
@@ -97,22 +97,22 @@ static void mailbox_mem_writel(uint32_t *reg_state, hwaddr offset,
 static void mailbox_mem_writeq(uint64_t *reg_state, hwaddr offset,
                                uint64_t value)
 {
     switch (offset) {
     case A_CXL_DEV_MAILBOX_CMD:
         break;
     case A_CXL_DEV_BG_CMD_STS:
         /* BG not supported */
-        /* fallthrough */
+        fallthrough;
     case A_CXL_DEV_MAILBOX_STS:
         /* Read only register, will get updated by the state machine */
         return;
     default:
         qemu_log_mask(LOG_UNIMP,
                       "%s Unexpected 64-bit access to 0x%" PRIx64 " (WI)\n",
                       __func__, offset);
         return;
     }
 
 
     reg_state[offset / sizeof(*reg_state)] = value;
 }
Signature · 1 line
2.39.2
#88 lore raw

RFC PATCH v2 75/78 migration: add fallthrough pseudo-keyword

In reply to Emmanouil Pitsidianakis

In preparation of raising -Wimplicit-fallthrough to 5, replace all fall-through comments with the fallthrough attribute pseudo-keyword.

---
 migration/migration.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
migration/migration.c +1 -1
index 585d3c8f55..fdad37efbb 100644
@@ -2772,38 +2772,38 @@ static MigIterateState migration_iteration_run(MigrationState *s)
 static void migration_iteration_finish(MigrationState *s)
 {
     /* If we enabled cpu throttling for auto-converge, turn it off. */
     cpu_throttle_stop();
 
     qemu_mutex_lock_iothread();
     switch (s->state) {
     case MIGRATION_STATUS_COMPLETED:
         migration_calculate_complete(s);
         runstate_set(RUN_STATE_POSTMIGRATE);
         break;
     case MIGRATION_STATUS_COLO:
         assert(migrate_colo());
         migrate_start_colo_process(s);
         s->vm_old_state = RUN_STATE_RUNNING;
-        /* Fallthrough */
+        fallthrough;
     case MIGRATION_STATUS_FAILED:
     case MIGRATION_STATUS_CANCELLED:
     case MIGRATION_STATUS_CANCELLING:
         if (s->vm_old_state == RUN_STATE_RUNNING) {
             if (!runstate_check(RUN_STATE_SHUTDOWN)) {
                 vm_start();
             }
         } else {
             if (runstate_check(RUN_STATE_FINISH_MIGRATE)) {
                 runstate_set(s->vm_old_state);
             }
         }
         break;
 
     default:
         /* Should not reach here, but if so, forgive the VM. */
         error_report("%s: Unknown ending state %d", __func__, s->state);
         break;
     }
     migrate_fd_cleanup_schedule(s);
     qemu_mutex_unlock_iothread();
 }
Signature · 1 line
2.39.2
Reviewed-by on v2 75/78
#89 lore raw

Re: [RFC PATCH v2 75/78] migration: add fallthrough pseudo-keyword

Quoted 4 lines · Emmanouil Pitsidianakis

In preparation of raising -Wimplicit-fallthrough to 5, replace all fall-through comments with the fallthrough attribute pseudo-keyword.

To make things easier for everybody involved, I think it is better than this patch goes through your tree.

I didn't know about this C language feature. Find it very useful.

Thanks, Juan.

#90 lore raw

RFC PATCH v2 76/78 qemu-img.c: add fallthrough pseudo-keyword

In reply to Emmanouil Pitsidianakis

In preparation of raising -Wimplicit-fallthrough to 5, replace all fall-through comments with the fallthrough attribute pseudo-keyword.

---
 qemu-img.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
qemu-img.c +1 -1
index 6068ab0d27..df2457a6fe 100644
@@ -1870,63 +1870,63 @@ static int coroutine_fn convert_co_read(ImgConvertState *s, int64_t sector_num,
 static int coroutine_fn convert_co_write(ImgConvertState *s, int64_t sector_num,
                                          int nb_sectors, uint8_t *buf,
                                          enum ImgConvertBlockStatus status)
 {
     int ret;
 
     while (nb_sectors > 0) {
         int n = nb_sectors;
         BdrvRequestFlags flags = s->compressed ? BDRV_REQ_WRITE_COMPRESSED : 0;
 
         switch (status) {
         case BLK_BACKING_FILE:
             /* If we have a backing file, leave clusters unallocated that are
              * unallocated in the source image, so that the backing file is
              * visible at the respective offset. */
             assert(s->target_has_backing);
             break;
 
         case BLK_DATA:
             /* If we're told to keep the target fully allocated (-S 0) or there
              * is real non-zero data, we must write it. Otherwise we can treat
              * it as zero sectors.
              * Compressed clusters need to be written as a whole, so in that
              * case we can only save the write if the buffer is completely
              * zeroed. */
             if (!s->min_sparse ||
                 (!s->compressed &&
                  is_allocated_sectors_min(buf, n, &n, s->min_sparse,
                                           sector_num, s->alignment)) ||
                 (s->compressed &&
                  !buffer_is_zero(buf, n * BDRV_SECTOR_SIZE)))
             {
                 ret = blk_co_pwrite(s->target, sector_num << BDRV_SECTOR_BITS,
                                     n << BDRV_SECTOR_BITS, buf, flags);
                 if (ret < 0) {
                     return ret;
                 }
                 break;
             }
-            /* fall-through */
+            fallthrough;
 
         case BLK_ZERO:
             if (s->has_zero_init) {
                 assert(!s->target_has_backing);
                 break;
             }
             ret = blk_co_pwrite_zeroes(s->target,
                                        sector_num << BDRV_SECTOR_BITS,
                                        n << BDRV_SECTOR_BITS,
                                        BDRV_REQ_MAY_UNMAP);
             if (ret < 0) {
                 return ret;
             }
             break;
         }
 
         sector_num += n;
         nb_sectors -= n;
         buf += n * BDRV_SECTOR_SIZE;
     }
 
     return 0;
 }
Signature · 1 line
2.39.2
#91 lore raw

RFC PATCH v2 77/78 tests/unit/test-char.c: add fallthrough pseudo-keyword

In reply to Emmanouil Pitsidianakis

In preparation of raising -Wimplicit-fallthrough to 5, replace all fall-through comments with the fallthrough attribute pseudo-keyword.

---
 tests/unit/test-char.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tests/unit/test-char.c +1 -1
index 649fdf64e1..6f5a2c4108 100644
@@ -56,25 +56,25 @@ static void fe_read(void *opaque, const uint8_t *buf, int size)
 static void fe_event(void *opaque, QEMUChrEvent event)
 {
     FeHandler *h = opaque;
     bool new_open_state;
 
     h->last_event = event;
     switch (event) {
     case CHR_EVENT_BREAK:
         break;
     case CHR_EVENT_OPENED:
     case CHR_EVENT_CLOSED:
         h->openclose_count++;
         new_open_state = (event == CHR_EVENT_OPENED);
         if (h->is_open == new_open_state) {
             h->openclose_mismatch = true;
         }
         h->is_open = new_open_state;
-        /* fallthrough */
+        fallthrough;
     default:
         quit = true;
         break;
     }
 }
 
 #ifdef _WIN32
Signature · 1 line
2.39.2
#92 lore raw

RFC PATCH v2 78/78 meson.build: increase -Wimplicit-fallthrough to 5

In reply to Emmanouil Pitsidianakis

Make GCC's implicit fall-through static analysis stricter by requiring the use of the fallthrough attribute statement instead of comments.

This makes the QEMU code style more consistent.

---
 docs/devel/style.rst | 23 +++++++++++++++++++++++
 meson.build          |  2 +-
 2 files changed, 24 insertions(+), 1 deletion(-)
docs/devel/style.rst +23 -0
index 2f68b50079..f473dd24e9 100644
@@ -612,28 +612,51 @@ While this generally results in simpler, less leak-prone code, there
 are still some caveats to beware of
 
 * Variables declared with g_auto* MUST always be initialized,
   otherwise the cleanup function will use uninitialized stack memory
 
 * If a variable declared with g_auto* holds a value which must
   live beyond the life of the function, that value must be saved
   and the original variable NULL'd out. This can be simpler using
   g_steal_pointer
 
 
 .. code-block:: c
 
     char *somefunc(void)
     {
         g_autofree char *foo = g_strdup_printf("foo%", "wibble");
         g_autoptr (GList) bar = .....
 
         if (eek) {
            return NULL;
         }
 
         return g_steal_pointer(&foo);
     }
 
+Implicit switch case fall-through
+=================================
+
+The C language allows switch cases to "fall-through" when a "break" statement
+is missing at the end of a case. This, however, introduces ambiguity in the
+code, as it's not always clear if the missing break is intentional or a bug.
+
+As this behaviour allows for bugs we do not allow "implicit fall-through".
+
+In order to identify intentional fall-through cases, we have adopted a
+pseudo-keyword macro 'fallthrough' which expands to gcc's extension
+__attribute__((__fallthrough__)).  `Statement Attributes
+<https://gcc.gnu.org/onlinedocs/gcc/Statement-Attributes.html>`_
+
+All switch/case blocks must end in one of:
+
+.. code-block:: c
+
+	  break;
+	  fallthrough;
+	  continue;
+	  goto <label>;
+	  return [expression];
 
 QEMU Specific Idioms
 ********************
meson.build +1 -1
index 79aef19bdc..e8805f0e0c 100644
@@ -438,28 +438,28 @@ add_global_link_arguments(qemu_ldflags, native: false, language: all_languages)
 warn_flags = [
   '-Wundef',
   '-Wwrite-strings',
   '-Wmissing-prototypes',
   '-Wstrict-prototypes',
   '-Wredundant-decls',
   '-Wold-style-declaration',
   '-Wold-style-definition',
   '-Wtype-limits',
   '-Wformat-security',
   '-Wformat-y2k',
   '-Winit-self',
   '-Wignored-qualifiers',
   '-Wempty-body',
   '-Wnested-externs',
   '-Wendif-labels',
   '-Wexpansion-to-defined',
-  '-Wimplicit-fallthrough=2',
+  '-Wimplicit-fallthrough=5',
   '-Wmissing-format-attribute',
   '-Wno-initializer-overrides',
   '-Wno-missing-include-dirs',
   '-Wno-shift-negative-value',
   '-Wno-string-plus-int',
   '-Wno-typedef-redefinition',
   '-Wno-tautological-type-limit-compare',
   '-Wno-psabi',
   '-Wno-gnu-variable-sized-type-not-at-end',
 ]
Signature · 1 line
2.39.2
#93 lore raw
In reply to Emmanouil Pitsidianakis
Quoted 17 lines · Emmanouil Pitsidianakis

/* resubmitted because git-send-email crashed with previous attempt */

Hello,

This RFC is inspired by the kernel's move to -Wimplicit-fallthrough=3 back in 2019.[0]
We take one step (or two) further by increasing it to 5 which rejects fall through comments and requires an attribute statement.

[0]:
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=a035d552a93b

The line differences are not many, but they spread all over different subsystems, architectures and devices. An attempt has been made to split them in cohesive patches to aid post-RFC review. Part of the RFC is to determine whether these patch divisions needs improvement.

Quoted 4 lines

Main questions this RFC poses
=============================

- Is this change desirable and net-positive.

I think so - consistency eases code maintenance, and being able to define a keyword-like macro used like any other control-flow statement is nicer than a magic comment.

Quoted 3 lines

- Should the fallthrough; pseudo-keyword be defined like in the Linux kernel, or use glib's G_GNUC_FALLTHROUGH, or keep the already existing QEMU_FALLTHROUGH macro.

This seems like it only affects the one place where we define the keyword. As long as all switch statements actually using it stick to one style, I'm less concerned about the magic used to get the style working in the first place.

Quoted 2 lines

- Should fallthrough comments be removed if they do not include extra information.

That would be fine by me - but we'll see what other reviewers say. I'm going to review on just the files I normally touch.

Quoted 53 lines

Some external resources
=======================

See the RFC discussion in the kernel:

https://lore.kernel.org/lkml/1d2830aadbe9d8151728a7df5b88528fc72a0095.1564549413.git.joe@perches.com/

The fallthrough; pseudo-keyword in the kernel source code:

https://elixir.bootlin.com/linux/latest/C/ident/fallthrough

In summary, I quote the doc comment and definition:

/*
* Add the pseudo keyword 'fallthrough' so case statement blocks
* must end with any of these keywords:
* break;
* fallthrough;
* continue;
* goto <label>;
* return [expression];
*
* gcc: https://gcc.gnu.org/onlinedocs/gcc/Statement-Attributes.html#Statement-Attributes
*/
#if __has_attribute(__fallthrough__)
# define fallthrough __attribute__((__fallthrough__))
#else
# define fallthrough do {} while (0) /* fallthrough */
#endif

Background - Motivation
=======================

The C switch statement allows you to conditionally goto different labels depending on a value. A break; statement conveniently goto's the end of the switch. If a "case" does not end in a break, we say that the control flow falls through the next case label, if any, implicitly. This can lead to bugs and QEMU uses the GCC warning -Wimplicit-fallthrough to prevent this.

Currently, QEMU is built with -Wimplicit-fallthrough=2. This makes GCC's static analyzer check for a case-insensitive matches of the .*falls?[ \t-]*thr(ough|u).* regular expression. This means the following list of comments taken from QEMU all disable the implicit fallthrough warning:

- /* FALLTHRU */
- /* fall through */
- /* Fall through. */
- /* Fall through... */
- /* fall through if hEventTimeout is signaled */
- /* FALL THROUGH */

Quoted 6 lines

To keep a constistent code style, this commit adds a macro fallthrough that looks like a C keyword but expands to an attribute statement in supported compilers (GCC at the moment).

Note: there was already such a macro, QEMU_FALLTHROUGH, and it was used only around 7 times in the code base. The first commit replaces it.

Seems reasonable to me; we'll see what other comments you get.

Signature · 3 lines
Eric Blake, Principal Software Engineer
Red Hat, Inc.
Virtualization:  qemu.org | libguestfs.org