All of lore.kernel.org
 help / color / mirror / Atom feed
From: Oleksandr Andrushchenko <andr2000@gmail.com>
To: xen-devel@lists.xenproject.org
Cc: Artem_Mygaiev@epam.com, sstabellini@kernel.org,
	Andrii_Anisov@epam.com,
	Oleksandr Andrushchenko <oleksandr_andrushchenko@epam.com>,
	andr2000@gmail.com, julien.grall@arm.com
Subject: [RFC PATCH 2/4] cert:xen/common: Add missing default labels to switch statements
Date: Fri, 22 Feb 2019 11:57:19 +0200	[thread overview]
Message-ID: <20190222095721.24764-3-andr2000@gmail.com> (raw)
In-Reply-To: <20190222095721.24764-1-andr2000@gmail.com>

From: Oleksandr Andrushchenko <oleksandr_andrushchenko@epam.com>

It is required by MISRA [1] that every switch statement has a default
label as a measure of defensive programming technique.

The changes in this patch are to match MISRA C:2012: Rule 16.4
requirements.

[1] https://www.misra.org.uk/

Signed-off-by: Oleksandr Andrushchenko <oleksandr_andrushchenko@epam.com>
---
 xen/common/device_tree.c           |  2 ++
 xen/common/domain.c                |  4 ++++
 xen/common/efi/boot.c              |  2 ++
 xen/common/event_channel.c         |  5 +++++
 xen/common/grant_table.c           | 18 +++++++++++++++++-
 xen/common/kernel.c                |  6 ++++++
 xen/common/libelf/libelf-dominfo.c |  3 +++
 xen/common/libfdt/fdt.c            |  2 ++
 xen/common/libfdt/fdt_ro.c         |  3 +++
 xen/common/sched_arinc653.c        |  3 +++
 xen/common/sched_credit.c          |  3 +++
 xen/common/sched_credit2.c         |  3 +++
 xen/common/sched_rt.c              |  3 +++
 xen/common/trace.c                 |  2 ++
 xen/common/vsprintf.c              |  8 ++++++++
 15 files changed, 66 insertions(+), 1 deletion(-)

diff --git a/xen/common/device_tree.c b/xen/common/device_tree.c
index 8fc401d91cf0..342a62933ed6 100644
--- a/xen/common/device_tree.c
+++ b/xen/common/device_tree.c
@@ -568,6 +568,8 @@ static unsigned int dt_bus_pci_get_flags(const __be32 *addr)
     case 0x03: /* 64 bits */
         flags |= IORESOURCE_MEM;
         break;
+    default:
+        break;
     }
     if (w & 0x40000000)
         flags |= IORESOURCE_PREFETCH;
diff --git a/xen/common/domain.c b/xen/common/domain.c
index 32bca8dbf2df..9b253b167643 100644
--- a/xen/common/domain.c
+++ b/xen/common/domain.c
@@ -747,6 +747,8 @@ int domain_kill(struct domain *d)
         send_global_virq(VIRQ_DOM_EXC);
         /* fallthrough */
     case DOMDYING_dead:
+        /* fallthrough */
+    default:
         break;
     }
 
@@ -1569,6 +1571,8 @@ long vm_assist(struct domain *p, unsigned int cmd, unsigned int type,
     case VMASST_CMD_disable:
         clear_bit(type, &p->vm_assist);
         return 0;
+    default:
+        break;
     }
 
     return -ENOSYS;
diff --git a/xen/common/efi/boot.c b/xen/common/efi/boot.c
index 79193784ff14..673d4a625178 100644
--- a/xen/common/efi/boot.c
+++ b/xen/common/efi/boot.c
@@ -582,6 +582,8 @@ static CHAR16 *__init point_tail(CHAR16 *fn)
         case L'_':
             tail = fn;
             break;
+        default:
+            break;
         }
 }
 /*
diff --git a/xen/common/event_channel.c b/xen/common/event_channel.c
index 6fbe346490fb..191a967c4b1d 100644
--- a/xen/common/event_channel.c
+++ b/xen/common/event_channel.c
@@ -105,6 +105,8 @@ static bool virq_is_global(unsigned int virq)
 
     case VIRQ_ARCH_0 ... VIRQ_ARCH_7:
         return arch_virq_is_global(virq);
+    default:
+        break;
     }
 
     ASSERT(virq < NR_VIRQS);
@@ -1419,6 +1421,9 @@ static void domain_dump_evtchn_info(struct domain *d)
         case ECS_VIRQ:
             printk(" v=%d", chn->u.virq);
             break;
+        default:
+            printk(" unknown state: %u", chn->state);
+            break;
         }
 
         ssid = xsm_show_security_evtchn(d, chn);
diff --git a/xen/common/grant_table.c b/xen/common/grant_table.c
index fd099a8f2593..0ed1c46c1790 100644
--- a/xen/common/grant_table.c
+++ b/xen/common/grant_table.c
@@ -640,6 +640,8 @@ static unsigned int nr_grant_entries(struct grant_table *gt)
                      GNTTAB_NR_RESERVED_ENTRIES);
         return f2e(nr_grant_frames(gt), 2);
 #undef f2e
+    default:
+        break;
     }
 
     return 0;
@@ -2992,7 +2994,9 @@ gnttab_set_version(XEN_GUEST_HANDLE_PARAM(gnttab_set_version_t) uop)
     case 2:
         for ( i = 0; i < GNTTAB_NR_RESERVED_ENTRIES; i++ )
         {
-            switch ( shared_entry_v2(gt, i).hdr.flags & GTF_type_mask )
+            unsigned int flags = shared_entry_v2(gt, i).hdr.flags;
+
+            switch ( flags & GTF_type_mask )
             {
             case GTF_permit_access:
                  if ( !(shared_entry_v2(gt, i).full_page.frame >> 32) )
@@ -3003,9 +3007,17 @@ gnttab_set_version(XEN_GUEST_HANDLE_PARAM(gnttab_set_version_t) uop)
                          "tried to change grant table version to 1 with non-representable entries\n");
                 res = -ERANGE;
                 goto out_unlock;
+            default:
+                gdprintk(XENLOG_ERR,
+                         "bad flags %#x in grant %#x when switching version\n",
+                         flags, i);
+                res = -EINVAL;
+                goto out_unlock;
             }
         }
         break;
+    default:
+        break;
     }
 
     /* Preserve the first 8 entries (toolstack reserved grants). */
@@ -3038,6 +3050,8 @@ gnttab_set_version(XEN_GUEST_HANDLE_PARAM(gnttab_set_version_t) uop)
             }
         }
         break;
+    default:
+        break;
     }
 
     if ( op.version < 2 && gt->gt_version == 2 &&
@@ -3069,6 +3083,8 @@ gnttab_set_version(XEN_GUEST_HANDLE_PARAM(gnttab_set_version_t) uop)
                     reserved_entries[i].frame;
             }
             break;
+        default:
+            break;
         }
     }
 
diff --git a/xen/common/kernel.c b/xen/common/kernel.c
index 612575430f1c..3983977b1643 100644
--- a/xen/common/kernel.c
+++ b/xen/common/kernel.c
@@ -267,6 +267,9 @@ int parse_bool(const char *s, const char *e)
         if ( !strncmp("disable", s, 7) )
             return 0;
         break;
+
+    default:
+        break;
     }
 
     return -1;
@@ -565,6 +568,9 @@ DO(xen_version)(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg)
 
         return sz;
     }
+
+    default:
+        break;
     }
 
     return -ENOSYS;
diff --git a/xen/common/libelf/libelf-dominfo.c b/xen/common/libelf/libelf-dominfo.c
index 508f08db428d..1f5acc2f71f8 100644
--- a/xen/common/libelf/libelf-dominfo.c
+++ b/xen/common/libelf/libelf-dominfo.c
@@ -216,6 +216,9 @@ elf_errorstatus elf_xen_parse_note(struct elf_binary *elf,
     case XEN_ELFNOTE_PHYS32_ENTRY:
         parms->phys_entry = val;
         break;
+
+    default:
+        break;
     }
     return 0;
 }
diff --git a/xen/common/libfdt/fdt.c b/xen/common/libfdt/fdt.c
index d02f4bf5f312..c30b45f8b49e 100644
--- a/xen/common/libfdt/fdt.c
+++ b/xen/common/libfdt/fdt.c
@@ -190,6 +190,8 @@ int fdt_next_node(const void *fdt, int offset, int *depth)
 				return -FDT_ERR_NOTFOUND;
 			else
 				return nextoffset;
+		default:
+			break;
 		}
 	} while (tag != FDT_BEGIN_NODE);
 
diff --git a/xen/common/libfdt/fdt_ro.c b/xen/common/libfdt/fdt_ro.c
index 36f9b480d19e..bed77e195496 100644
--- a/xen/common/libfdt/fdt_ro.c
+++ b/xen/common/libfdt/fdt_ro.c
@@ -120,6 +120,9 @@ static int _nextprop(const void *fdt, int offset)
 
 		case FDT_PROP:
 			return offset;
+
+		default:
+			break;
 		}
 		offset = nextoffset;
 	} while (tag == FDT_NOP);
diff --git a/xen/common/sched_arinc653.c b/xen/common/sched_arinc653.c
index a4c6d00b8185..ba16b9e17f8c 100644
--- a/xen/common/sched_arinc653.c
+++ b/xen/common/sched_arinc653.c
@@ -689,6 +689,9 @@ a653sched_adjust_global(const struct scheduler *ops,
         if ( copy_to_guest(sc->u.sched_arinc653.schedule, &local_sched, 1) )
             rc = -EFAULT;
         break;
+
+    default:
+        break;
     }
 
     return rc;
diff --git a/xen/common/sched_credit.c b/xen/common/sched_credit.c
index 3abe20def842..b485d4c4fdf0 100644
--- a/xen/common/sched_credit.c
+++ b/xen/common/sched_credit.c
@@ -1291,6 +1291,9 @@ csched_sys_cntl(const struct scheduler *ops,
         params->vcpu_migr_delay_us = prv->vcpu_migr_delay / MICROSECS(1);
         rc = 0;
         break;
+
+    default:
+        break;
     }
     out:
     return rc;
diff --git a/xen/common/sched_credit2.c b/xen/common/sched_credit2.c
index 543dc3664dd3..927a70eab944 100644
--- a/xen/common/sched_credit2.c
+++ b/xen/common/sched_credit2.c
@@ -3037,6 +3037,9 @@ static int csched2_sys_cntl(const struct scheduler *ops,
     case XEN_SYSCTL_SCHEDOP_getinfo:
         params->ratelimit_us = prv->ratelimit_us;
         break;
+
+    default:
+        return -EINVAL;
     }
 
     return 0;
diff --git a/xen/common/sched_rt.c b/xen/common/sched_rt.c
index f1b81f037329..87db8bb68c9c 100644
--- a/xen/common/sched_rt.c
+++ b/xen/common/sched_rt.c
@@ -1455,6 +1455,9 @@ rt_dom_cntl(
             /* notify upper caller how many vcpus have been processed. */
             op->u.v.nr_vcpus = index;
         break;
+    default:
+        rc = -EINVAL;
+        break;
     }
 
     return rc;
diff --git a/xen/common/trace.c b/xen/common/trace.c
index cc294fc38473..e345767552f8 100644
--- a/xen/common/trace.c
+++ b/xen/common/trace.c
@@ -863,6 +863,8 @@ void __trace_hypercall(uint32_t event, unsigned long op,
     case __HYPERVISOR_sched_op:
         APPEND_ARG32(0); /* cmd */
         break;
+    default:
+        break;
     }
 
     __trace_var(event, 1, sizeof(uint32_t) * (1 + (a - d.args)), &d);
diff --git a/xen/common/vsprintf.c b/xen/common/vsprintf.c
index 352d43b42519..c2ee5ec06220 100644
--- a/xen/common/vsprintf.c
+++ b/xen/common/vsprintf.c
@@ -361,11 +361,13 @@ static char *print_domain(char *str, char *end, const struct domain *d)
     case DOMID_XEN:  name = "[XEN]";  break;
     case DOMID_COW:  name = "[COW]";  break;
     case DOMID_IDLE: name = "[IDLE]"; break;
+    default:
         /*
          * In principle, we could ASSERT_UNREACHABLE() in the default case.
          * However, this path is used to print out crash information, which
          * risks recursing infinitely and not printing any useful information.
          */
+        break;
     }
 
     if ( str < end )
@@ -455,6 +457,8 @@ static char *pointer(char *str, char *end, const char **fmt_ptr,
             ++*fmt_ptr;
             sep = 0;
             break;
+        default:
+            break;
         }
 
         for ( i = 0; ; )
@@ -519,6 +523,9 @@ static char *pointer(char *str, char *end, const char **fmt_ptr,
     case 'v': /* d<domain-id>v<vcpu-id> from a struct vcpu */
         ++*fmt_ptr;
         return print_vcpu(str, end, arg);
+
+    default:
+        break;
     }
 
     if ( field_width == -1 )
@@ -594,6 +601,7 @@ int vsnprintf(char *buf, size_t size, const char *fmt, va_list args)
         case ' ': flags |= SPACE; goto repeat;
         case '#': flags |= SPECIAL; goto repeat;
         case '0': flags |= ZEROPAD; goto repeat;
+        default : break;
         }
 
         /* get field width */
-- 
2.20.1


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

  parent reply	other threads:[~2019-02-22  9:57 UTC|newest]

Thread overview: 81+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-02-22  9:57 [RFC PATCH 0/4] Add missing default labels to switch statements Oleksandr Andrushchenko
2019-02-22  9:57 ` [RFC PATCH 1/4] cert:arch/arm: " Oleksandr Andrushchenko
2019-02-22 18:24   ` Julien Grall
2019-02-22  9:57 ` Oleksandr Andrushchenko [this message]
2019-02-22  9:57 ` [RFC PATCH 3/4] cert:xen/drivers: " Oleksandr Andrushchenko
2019-02-22  9:57 ` [RFC PATCH 4/4] cert:xen/xsm/flask: " Oleksandr Andrushchenko
2019-02-22 10:27 ` [RFC PATCH 0/4] " Andrew Cooper
2019-02-22 11:05   ` Julien Grall
2019-02-22 11:13     ` Oleksandr Andrushchenko
2019-02-22 11:27       ` Julien Grall
2019-02-22 12:01         ` Oleksandr Andrushchenko
2019-02-22 13:27           ` Julien Grall
2019-02-22 21:00             ` Stefano Stabellini
2019-02-22 21:33               ` Andrew Cooper
2019-02-22 21:58                 ` Stefano Stabellini
2019-02-22 22:11                   ` Julien Grall
2019-02-22 22:34                     ` Stefano Stabellini
2019-02-22 23:11                       ` Julien Grall
2019-02-25 17:38                         ` Stefano Stabellini
2019-02-22 23:13                       ` Julien Grall
2019-02-25 10:27                         ` Oleksandr Andrushchenko
2019-02-25 10:57                           ` Julien Grall
2019-02-22 22:34                     ` Andrew Cooper
2019-02-22 22:38                       ` Stefano Stabellini
2019-02-22 23:34                         ` Julien Grall
2019-02-25 10:00                           ` Oleksandr Andrushchenko
2019-02-25 11:08                             ` Julien Grall
2019-02-25 11:37                               ` Oleksandr Andrushchenko
2019-02-22 23:22                       ` Julien Grall
2019-02-22 23:41                         ` Andrew Cooper
2019-02-25 10:06                           ` Oleksandr Andrushchenko
2019-02-25 11:10                             ` Julien Grall
2019-02-25 11:43                               ` Oleksandr Andrushchenko
2019-02-25  9:50                 ` Oleksandr Andrushchenko
2019-02-25 11:23                   ` Julien Grall
2019-02-25 11:49                     ` Oleksandr Andrushchenko
2019-02-25 12:11                       ` Jan Beulich
2019-02-25 12:32                         ` Oleksandr Andrushchenko
2019-02-25 12:15                       ` Julien Grall
2019-02-25 12:38                         ` Oleksandr Andrushchenko
2019-02-25 12:50                           ` Julien Grall
2019-02-25 13:06                             ` Oleksandr Andrushchenko
2019-02-25 13:22                               ` Julien Grall
2019-02-25 13:32                                 ` Oleksandr Andrushchenko
2019-02-25 13:40                                   ` Julien Grall
2019-02-25 13:47                                     ` Oleksandr Andrushchenko
2019-02-25 15:54                                       ` Lars Kurth
2019-02-25 17:42                                         ` Stefano Stabellini
2019-02-25 11:40                 ` Jan Beulich
2019-02-25 16:58                   ` George Dunlap
2019-02-25 17:47                     ` Stefano Stabellini
2019-02-25 18:20                       ` Julien Grall
2019-02-25 21:13                         ` Stefano Stabellini
2019-02-25 21:34                           ` Julien Grall
2019-02-26  7:43                             ` Oleksandr Andrushchenko
2019-02-26 11:20                             ` Jan Beulich
2019-02-26 11:33                               ` Oleksandr Andrushchenko
2019-02-26 11:47                                 ` Jan Beulich
2019-02-26 12:20                                   ` Oleksandr Andrushchenko
2019-02-26 18:27                                   ` Stefano Stabellini
2019-02-27  9:23                                     ` Lars Kurth
2019-02-27 10:16                                       ` Jan Beulich
2019-02-27 17:34                                         ` Lars Kurth
2019-02-27 23:45                                           ` Stefano Stabellini
2019-02-28 10:30                                           ` Jan Beulich
2019-02-26 21:10                             ` Stefano Stabellini
2019-02-26 21:31                               ` Julien Grall
2019-02-26 11:14                       ` Jan Beulich
2019-02-22 22:08               ` Julien Grall
2019-02-25 10:11                 ` Oleksandr Andrushchenko
2019-02-25 11:47                   ` Julien Grall
2019-02-25 11:59                     ` Oleksandr Andrushchenko
2019-02-25 12:10                     ` Jan Beulich
2019-02-22 11:20   ` Andrii Anisov
2019-02-22 11:21   ` Andrii Anisov
2019-02-22 11:30     ` Julien Grall
2019-02-22 11:32       ` Julien Grall
2019-02-22 11:53       ` Andrii Anisov
2019-02-22 13:30         ` Julien Grall
2019-02-25 11:43   ` Julien Grall
2019-02-25 12:00     ` Oleksandr Andrushchenko

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190222095721.24764-3-andr2000@gmail.com \
    --to=andr2000@gmail.com \
    --cc=Andrii_Anisov@epam.com \
    --cc=Artem_Mygaiev@epam.com \
    --cc=julien.grall@arm.com \
    --cc=oleksandr_andrushchenko@epam.com \
    --cc=sstabellini@kernel.org \
    --cc=xen-devel@lists.xenproject.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.