Skip to contentSkip to conversation

xen/Coverity: Audit of MISSING_BREAK defects

PATCH In review Andrew Cooper 2 participants 4 messages Feb 12, 2015 – Feb 13, 2015

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 xen/Coverity: Audit of MISSING_BREAK defects

Coverity uses several heuristics to identify when one case statement legitimately falls through into the next, and a comment as the final item in a case statement is one heuristic (the assumption being that it is a justification for the fallthrough).

Use this to perform an audit of defects and hide the legitimate fallthroughs.

No functional change. All identified fallthroughs are legitimate.

Coverity-IDs: 1055483, 1055484, 1055486 - 1055488, 1055490 - 1055496,

              1055498 - 1055500, 1055501, 1220091
CC Keir Fraser <[email protected]>
CC Jan Beulich <[email protected]>
CC Tim Deegan <[email protected]>
CC Xen Coverity Team <[email protected]>
---
 xen/arch/x86/hvm/emulate.c      |    1 +
 xen/arch/x86/hvm/svm/svm.c      |    1 +
 xen/arch/x86/hvm/vlapic.c       |    1 +
 xen/arch/x86/mm.c               |    2 ++
 xen/arch/x86/traps.c            |    3 +++
 xen/arch/x86/x86_64/compat/mm.c |    1 +
 xen/common/lib.c                |    4 ++++
 xen/common/schedule.c           |    1 +
 8 files changed, 14 insertions(+)
xen/arch/x86/hvm/emulate.c +1 -0
index 636c909..c657bc6 100644
@@ -161,6 +161,7 @@ static int hvmemul_do_io(
                 put_page(ram_page);
             return X86EMUL_RETRY;
         }
+        /* fallthrough */
     default:
         if ( ram_page )
             put_page(ram_page);
xen/arch/x86/hvm/svm/svm.c +1 -0
index a7655bd..018dd70 100644
@@ -2378,6 +2378,7 @@ void svm_vmexit_handler(struct cpu_user_regs *regs)
             case NESTEDHVM_VMEXIT_ERROR:
                 break;
             }
+            /* fallthrough */
         case NESTEDHVM_VMEXIT_ERROR:
             gdprintk(XENLOG_ERR,
                 "nestedsvm_check_intercepts() returned NESTEDHVM_VMEXIT_ERROR\n");
xen/arch/x86/hvm/vlapic.c +1 -0
index 5da6d8f..cee8699 100644
@@ -762,6 +762,7 @@ static int vlapic_reg_write(struct vcpu *v,
             vlapic->hw.tdt_msr = 0;
         }
         vlapic->pt.irq = val & APIC_VECTOR_MASK;
+        /* fallthrough */
     case APIC_LVTTHMR:      /* LVT Thermal Monitor */
     case APIC_LVTPC:        /* LVT Performance Counter */
     case APIC_LVT0:         /* LVT LINT0 Reg */
xen/arch/x86/mm.c +2 -0
index d4965da..12e5006 100644
@@ -2771,6 +2771,7 @@ int new_guest_cr3(unsigned long mfn)
             {
             case -EINTR:
                 rc = -ERESTART;
+                /* fallthrough */
             case -ERESTART:
                 curr->arch.old_guest_table = page;
                 break;
@@ -3126,6 +3127,7 @@ long do_mmuext_op(
                     {
                     case -EINTR:
                         rc = -ERESTART;
+                        /* fallthrough */
                     case -ERESTART:
                         curr->arch.old_guest_table = page;
                         okay = 0;
xen/arch/x86/traps.c +3 -0
index f5516dc..057a7af 100644
@@ -1739,7 +1739,9 @@ static int guest_io_okay(
                                           port>>3, 2) )
         {
         default: x.bytes[0] = ~0;
+            /* fallthrough */
         case 1:  x.bytes[1] = ~0;
+            /* fallthrough */
         case 0:  break;
         }
         TOGGLE_MODE();
@@ -3320,6 +3322,7 @@ static void pci_serr_error(const struct cpu_user_regs *regs)
     {
     case 'd': /* 'dom0' */
         nmi_hwdom_report(_XEN_NMIREASON_pci_serr);
+        /* fallthrough */
     case 'i': /* 'ignore' */
         /* Would like to print a diagnostic here but can't call printk()
            from NMI context -- raise a softirq instead. */
xen/arch/x86/x86_64/compat/mm.c +1 -0
index f90f611..1491ce3 100644
@@ -292,6 +292,7 @@ int compat_mmuext_op(XEN_GUEST_HANDLE_PARAM(mmuext_op_compat_t) cmp_uops,
                 break;
             case MMUEXT_NEW_USER_BASEPTR:
                 rc = -EINVAL;
+                /* fallthrough */
             case MMUEXT_TLB_FLUSH_LOCAL:
             case MMUEXT_TLB_FLUSH_MULTI:
             case MMUEXT_TLB_FLUSH_ALL:
xen/common/lib.c +4 -0
index 89c74ad..ae0bbb3 100644
@@ -461,12 +461,16 @@ unsigned long long parse_size_and_unit(const char *s, const char **ps)
     {
     case 'T': case 't':
         ret <<= 10;
+        /* fallthrough */
     case 'G': case 'g':
         ret <<= 10;
+        /* fallthrough */
     case 'M': case 'm':
         ret <<= 10;
+        /* fallthrough */
     case 'K': case 'k':
         ret <<= 10;
+        /* fallthrough */
     case 'B': case 'b':
         s1++;
         break;
xen/common/schedule.c +1 -0
index b73177f..ef79847 100644
@@ -1179,6 +1179,7 @@ static void schedule(void)
     {
     case TASKLET_enqueued:
         set_bit(_TASKLET_scheduled, tasklet_work);
+        /* fallthrough */
     case TASKLET_enqueued|TASKLET_scheduled:
         tasklet_work_scheduled = 1;
         break;
Signature · 1 line
1.7.10.4
Reviewed-by on v1 1/1
#1 lore raw
Quoted 143 lines · On Thu, 12 Feb 2015 20:08:46 +0000 Andrew Cooper <[email protected]>…

Coverity uses several heuristics to identify when one case statement legitimately falls through into the next, and a comment as the final item in a case statement is one heuristic (the assumption being that it is a justification for the fallthrough).

Use this to perform an audit of defects and hide the legitimate fallthroughs.

No functional change. All identified fallthroughs are legitimate.

Coverity-IDs: 1055483, 1055484, 1055486 - 1055488, 1055490 - 1055496,

              1055498 - 1055500, 1055501, 1220091
CC Keir Fraser <[email protected]>
CC Jan Beulich <[email protected]>
CC Tim Deegan <[email protected]>
CC Xen Coverity Team <[email protected]>
---
 xen/arch/x86/hvm/emulate.c      |    1 +
 xen/arch/x86/hvm/svm/svm.c      |    1 +
 xen/arch/x86/hvm/vlapic.c       |    1 +
 xen/arch/x86/mm.c               |    2 ++
 xen/arch/x86/traps.c            |    3 +++
 xen/arch/x86/x86_64/compat/mm.c |    1 +
 xen/common/lib.c                |    4 ++++
 xen/common/schedule.c           |    1 +
 8 files changed, 14 insertions(+)
xen/arch/x86/hvm/emulate.c +1 -0
index 636c909..c657bc6 100644
@@ -161,6 +161,7 @@ static int hvmemul_do_io(
                 put_page(ram_page);
             return X86EMUL_RETRY;
         }
+        /* fallthrough */
     default:
         if ( ram_page )
             put_page(ram_page);
xen/arch/x86/hvm/svm/svm.c +1 -0
index a7655bd..018dd70 100644
@@ -2378,6 +2378,7 @@ void svm_vmexit_handler(struct cpu_user_regs *regs)
             case NESTEDHVM_VMEXIT_ERROR:
                 break;
             }
+            /* fallthrough */
         case NESTEDHVM_VMEXIT_ERROR:
             gdprintk(XENLOG_ERR,
                 "nestedsvm_check_intercepts() returned NESTEDHVM_VMEXIT_ERROR\n");
xen/arch/x86/hvm/vlapic.c +1 -0
index 5da6d8f..cee8699 100644
@@ -762,6 +762,7 @@ static int vlapic_reg_write(struct vcpu *v,
             vlapic->hw.tdt_msr = 0;
         }
         vlapic->pt.irq = val & APIC_VECTOR_MASK;
+        /* fallthrough */
     case APIC_LVTTHMR:      /* LVT Thermal Monitor */
     case APIC_LVTPC:        /* LVT Performance Counter */
     case APIC_LVT0:         /* LVT LINT0 Reg */
xen/arch/x86/mm.c +2 -0
index d4965da..12e5006 100644
@@ -2771,6 +2771,7 @@ int new_guest_cr3(unsigned long mfn)
             {
             case -EINTR:
                 rc = -ERESTART;
+                /* fallthrough */
             case -ERESTART:
                 curr->arch.old_guest_table = page;
                 break;
@@ -3126,6 +3127,7 @@ long do_mmuext_op(
                     {
                     case -EINTR:
                         rc = -ERESTART;
+                        /* fallthrough */
                     case -ERESTART:
                         curr->arch.old_guest_table = page;
                         okay = 0;
xen/arch/x86/traps.c +3 -0
index f5516dc..057a7af 100644
@@ -1739,7 +1739,9 @@ static int guest_io_okay(
                                           port>>3, 2) )
         {
         default: x.bytes[0] = ~0;
+            /* fallthrough */
         case 1:  x.bytes[1] = ~0;
+            /* fallthrough */
         case 0:  break;
         }
         TOGGLE_MODE();
@@ -3320,6 +3322,7 @@ static void pci_serr_error(const struct cpu_user_regs *regs)
     {
     case 'd': /* 'dom0' */
         nmi_hwdom_report(_XEN_NMIREASON_pci_serr);
+        /* fallthrough */
     case 'i': /* 'ignore' */
         /* Would like to print a diagnostic here but can't call printk()
            from NMI context -- raise a softirq instead. */
xen/arch/x86/x86_64/compat/mm.c +1 -0
index f90f611..1491ce3 100644
@@ -292,6 +292,7 @@ int compat_mmuext_op(XEN_GUEST_HANDLE_PARAM(mmuext_op_compat_t) cmp_uops,
                 break;
             case MMUEXT_NEW_USER_BASEPTR:
                 rc = -EINVAL;
+                /* fallthrough */
             case MMUEXT_TLB_FLUSH_LOCAL:
             case MMUEXT_TLB_FLUSH_MULTI:
             case MMUEXT_TLB_FLUSH_ALL:
xen/common/lib.c +4 -0
index 89c74ad..ae0bbb3 100644
@@ -461,12 +461,16 @@ unsigned long long parse_size_and_unit(const char *s, const char **ps)
     {
     case 'T': case 't':
         ret <<= 10;
+        /* fallthrough */
     case 'G': case 'g':
         ret <<= 10;
+        /* fallthrough */
     case 'M': case 'm':
         ret <<= 10;
+        /* fallthrough */
     case 'K': case 'k':
         ret <<= 10;
+        /* fallthrough */
     case 'B': case 'b':
         s1++;
         break;
xen/common/schedule.c +0 -0
index b73177f..ef79847 100644

xen/common/schedule.c static void schedule(void) · line 1185

Quoted 7 lines
xen/common/schedule.c +1 -0
@@ -1179,6 +1179,7 @@ static void schedule(void)
     {
     case TASKLET_enqueued:
         set_bit(_TASKLET_scheduled, tasklet_work);
+        /* fallthrough */
     case TASKLET_enqueued|TASKLET_scheduled:
         tasklet_work_scheduled = 1;
         break;

I'm surprised that coverity didn't complain about the fallthrough in the next case:

    case TASKLET_scheduled:
        clear_bit(_TASKLET_scheduled, tasklet_work);
    case 0:
        /*tasklet_work_scheduled = 0;*/
        break;

Or is my code out of date?

With or without that change,

Quoted 2 lines
Signature · 1 line
1.7.10.4
#2 lore raw
Quoted 162 lines · Don Koch
Quoted 143 lines · On Thu, 12 Feb 2015 20:08:46 +0000 Andrew Cooper <[email protected]>…

Coverity uses several heuristics to identify when one case statement legitimately falls through into the next, and a comment as the final item in a case statement is one heuristic (the assumption being that it is a justification for the fallthrough).

Use this to perform an audit of defects and hide the legitimate fallthroughs.

No functional change. All identified fallthroughs are legitimate.

Coverity-IDs: 1055483, 1055484, 1055486 - 1055488, 1055490 - 1055496,

              1055498 - 1055500, 1055501, 1220091
CC Keir Fraser <[email protected]>
CC Jan Beulich <[email protected]>
CC Tim Deegan <[email protected]>
CC Xen Coverity Team <[email protected]>
---
 xen/arch/x86/hvm/emulate.c      |    1 +
 xen/arch/x86/hvm/svm/svm.c      |    1 +
 xen/arch/x86/hvm/vlapic.c       |    1 +
 xen/arch/x86/mm.c               |    2 ++
 xen/arch/x86/traps.c            |    3 +++
 xen/arch/x86/x86_64/compat/mm.c |    1 +
 xen/common/lib.c                |    4 ++++
 xen/common/schedule.c           |    1 +
 8 files changed, 14 insertions(+)
xen/arch/x86/hvm/emulate.c +1 -0
index 636c909..c657bc6 100644
@@ -161,6 +161,7 @@ static int hvmemul_do_io(
                 put_page(ram_page);
             return X86EMUL_RETRY;
         }
+        /* fallthrough */
     default:
         if ( ram_page )
             put_page(ram_page);
xen/arch/x86/hvm/svm/svm.c +1 -0
index a7655bd..018dd70 100644
@@ -2378,6 +2378,7 @@ void svm_vmexit_handler(struct cpu_user_regs *regs)
             case NESTEDHVM_VMEXIT_ERROR:
                 break;
             }
+            /* fallthrough */
         case NESTEDHVM_VMEXIT_ERROR:
             gdprintk(XENLOG_ERR,
                 "nestedsvm_check_intercepts() returned NESTEDHVM_VMEXIT_ERROR\n");
xen/arch/x86/hvm/vlapic.c +1 -0
index 5da6d8f..cee8699 100644
@@ -762,6 +762,7 @@ static int vlapic_reg_write(struct vcpu *v,
             vlapic->hw.tdt_msr = 0;
         }
         vlapic->pt.irq = val & APIC_VECTOR_MASK;
+        /* fallthrough */
     case APIC_LVTTHMR:      /* LVT Thermal Monitor */
     case APIC_LVTPC:        /* LVT Performance Counter */
     case APIC_LVT0:         /* LVT LINT0 Reg */
xen/arch/x86/mm.c +2 -0
index d4965da..12e5006 100644
@@ -2771,6 +2771,7 @@ int new_guest_cr3(unsigned long mfn)
             {
             case -EINTR:
                 rc = -ERESTART;
+                /* fallthrough */
             case -ERESTART:
                 curr->arch.old_guest_table = page;
                 break;
@@ -3126,6 +3127,7 @@ long do_mmuext_op(
                     {
                     case -EINTR:
                         rc = -ERESTART;
+                        /* fallthrough */
                     case -ERESTART:
                         curr->arch.old_guest_table = page;
                         okay = 0;
xen/arch/x86/traps.c +3 -0
index f5516dc..057a7af 100644
@@ -1739,7 +1739,9 @@ static int guest_io_okay(
                                           port>>3, 2) )
         {
         default: x.bytes[0] = ~0;
+            /* fallthrough */
         case 1:  x.bytes[1] = ~0;
+            /* fallthrough */
         case 0:  break;
         }
         TOGGLE_MODE();
@@ -3320,6 +3322,7 @@ static void pci_serr_error(const struct cpu_user_regs *regs)
     {
     case 'd': /* 'dom0' */
         nmi_hwdom_report(_XEN_NMIREASON_pci_serr);
+        /* fallthrough */
     case 'i': /* 'ignore' */
         /* Would like to print a diagnostic here but can't call printk()
            from NMI context -- raise a softirq instead. */
xen/arch/x86/x86_64/compat/mm.c +1 -0
index f90f611..1491ce3 100644
@@ -292,6 +292,7 @@ int compat_mmuext_op(XEN_GUEST_HANDLE_PARAM(mmuext_op_compat_t) cmp_uops,
                 break;
             case MMUEXT_NEW_USER_BASEPTR:
                 rc = -EINVAL;
+                /* fallthrough */
             case MMUEXT_TLB_FLUSH_LOCAL:
             case MMUEXT_TLB_FLUSH_MULTI:
             case MMUEXT_TLB_FLUSH_ALL:
xen/common/lib.c +4 -0
index 89c74ad..ae0bbb3 100644
@@ -461,12 +461,16 @@ unsigned long long parse_size_and_unit(const char *s, const char **ps)
     {
     case 'T': case 't':
         ret <<= 10;
+        /* fallthrough */
     case 'G': case 'g':
         ret <<= 10;
+        /* fallthrough */
     case 'M': case 'm':
         ret <<= 10;
+        /* fallthrough */
     case 'K': case 'k':
         ret <<= 10;
+        /* fallthrough */
     case 'B': case 'b':
         s1++;
         break;
xen/common/schedule.c +0 -0
index b73177f..ef79847 100644

xen/common/schedule.c static void schedule(void) · line 1185

Quoted 7 lines
xen/common/schedule.c +1 -0
@@ -1179,6 +1179,7 @@ static void schedule(void)
     {
     case TASKLET_enqueued:
         set_bit(_TASKLET_scheduled, tasklet_work);
+        /* fallthrough */
     case TASKLET_enqueued|TASKLET_scheduled:
         tasklet_work_scheduled = 1;
         break;

I'm surprised that coverity didn't complain about the fallthrough in the next case:

    case TASKLET_scheduled:
        clear_bit(_TASKLET_scheduled, tasklet_work);
    case 0:
        /*tasklet_work_scheduled = 0;*/
        break;
Quoted 4 lines

Or is my code out of date?

With or without that change,

Another heuristic is a case statement followed by another case which begins with a break. The defect would re-emerge if code gets uncommented.

~Andrew

#3 lore raw
Quoted 4 lines · On Fri, 13 Feb 2015 11:01:27 +0000 Andrew Cooper <[email protected]>…
Quoted 3 lines · Don Koch

On Thu, 12 Feb 2015 20:08:46 +0000
Andrew Cooper <[email protected]> wrote:

[...]

Quoted 9 lines
Quoted 9 lines

I'm surprised that coverity didn't complain about the fallthrough in the next case:

    case TASKLET_scheduled:
        clear_bit(_TASKLET_scheduled, tasklet_work);
    case 0:
        /*tasklet_work_scheduled = 0;*/
        break;
Quoted 7 lines
Quoted 4 lines

Or is my code out of date?

With or without that change,

Another heuristic is a case statement followed by another case which begins with a break. The defect would re-emerge if code gets uncommented.

Gotcha. My R-b still stands.

Thanks,
-d

Quoted 2 lines

~Andrew