kernel: userspace: Sanitize switch usage

MISRA-C requires that every switch clause has a break instruction.
Changing gen_kobject_list script to generates compliance code.

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
This commit is contained in:
Flavio Ceolin 2018-09-11 13:14:21 -07:00 committed by Anas Nashif
commit 3259ac08ca
2 changed files with 14 additions and 5 deletions

View file

@ -34,6 +34,7 @@ static void clear_perms_cb(struct _k_object *ko, void *ctx_ptr);
const char *otype_to_str(enum k_objects otype)
{
const char *ret;
/* -fdata-sections doesn't work right except in very very recent
* GCC and these literal strings would appear in the binary even if
* otype_to_str was omitted by the linker
@ -45,12 +46,14 @@ const char *otype_to_str(enum k_objects otype)
*/
#include <otype-to-str.h>
default:
return "?";
ret = "?";
break;
}
#else
ARG_UNUSED(otype);
return NULL;
#endif
return ret;
}
struct perm_ctx {
@ -94,11 +97,16 @@ static sys_dlist_t obj_list = SYS_DLIST_STATIC_INIT(&obj_list);
static size_t obj_size_get(enum k_objects otype)
{
size_t ret;
switch (otype) {
#include <otype-to-size.h>
default:
return sizeof(struct device);
ret = sizeof(struct device);
break;
}
return ret;
}
static int node_lessthan(struct rbnode *a, struct rbnode *b)
@ -342,6 +350,7 @@ static void unref_check(struct _k_object *ko)
k_stack_cleanup((struct k_stack *)ko->name);
break;
default:
/* Nothing to do */
break;
}

View file

@ -202,14 +202,14 @@ def write_kobj_otype_output(fp):
if dep:
fp.write("#ifdef %s\n" % dep)
fp.write('case %s: return "%s";\n' % (kobject_to_enum(kobj), kobj))
fp.write('case %s: ret = "%s"; break;\n' % (kobject_to_enum(kobj), kobj))
if dep:
fp.write("#endif\n")
fp.write("/* Driver subsystems */\n")
for subsystem in subsystems:
subsystem = subsystem.replace("_driver_api", "")
fp.write('case K_OBJ_DRIVER_%s: return "%s driver";\n' % (
fp.write('case K_OBJ_DRIVER_%s: ret = "%s driver"; break;\n' % (
subsystem.upper(),
subsystem
))
@ -225,7 +225,7 @@ def write_kobj_size_output(fp):
if dep:
fp.write("#ifdef %s\n" % dep)
fp.write('case %s: return sizeof(struct %s);\n' %
fp.write('case %s: ret = sizeof(struct %s); break;\n' %
(kobject_to_enum(kobj), kobj))
if dep:
fp.write("#endif\n")