Cleanup: lttng_abi_create_event{,_notifier}: use switch/case rather than if
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Tue, 6 Apr 2021 20:21:54 +0000 (16:21 -0400)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Tue, 6 Apr 2021 20:26:43 +0000 (16:26 -0400)
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Change-Id: I2a5454521d57fdfcb0c623031b24d590aff40281

src/lttng-abi.c

index eb68bce8d15328da889e4f1077c87f779aa4b37d..88c92d91e0fd4d336c59ecdc371be25c1843d205 100644 (file)
@@ -1814,8 +1814,11 @@ int lttng_abi_create_event(struct file *channel_file,
        ret = lttng_abi_validate_event_param(event_param);
        if (ret)
                goto event_error;
-       if (event_param->instrumentation == LTTNG_KERNEL_TRACEPOINT
-                       || event_param->instrumentation == LTTNG_KERNEL_SYSCALL) {
+
+       switch (event_param->instrumentation) {
+       case LTTNG_KERNEL_TRACEPOINT:           /* Fall-through */
+       case LTTNG_KERNEL_SYSCALL:
+       {
                struct lttng_event_enabler *event_enabler;
 
                if (strutils_is_star_glob_pattern(event_param->name)) {
@@ -1830,7 +1833,13 @@ int lttng_abi_create_event(struct file *channel_file,
                                event_param, channel);
                }
                priv = event_enabler;
-       } else {
+               break;
+       }
+
+       case LTTNG_KERNEL_KPROBE:               /* Fall-through */
+       case LTTNG_KERNEL_KRETPROBE:            /* Fall-through */
+       case LTTNG_KERNEL_UPROBE:
+       {
                struct lttng_event *event;
 
                /*
@@ -1846,6 +1855,14 @@ int lttng_abi_create_event(struct file *channel_file,
                        goto event_error;
                }
                priv = event;
+               break;
+       }
+
+       case LTTNG_KERNEL_FUNCTION:             /* Fall-through */
+       case LTTNG_KERNEL_NOOP:                 /* Fall-through */
+       default:
+               ret = -EINVAL;
+               goto event_error;
        }
        event_file->private_data = priv;
        fd_install(event_fd, event_file);
@@ -2025,8 +2042,10 @@ int lttng_abi_create_event_notifier(struct file *event_notifier_group_file,
                goto refcount_error;
        }
 
-       if (event_notifier_param->event.instrumentation == LTTNG_KERNEL_TRACEPOINT
-                       || event_notifier_param->event.instrumentation == LTTNG_KERNEL_SYSCALL) {
+       switch (event_notifier_param->event.instrumentation) {
+       case LTTNG_KERNEL_TRACEPOINT:           /* Fall-through */
+       case LTTNG_KERNEL_SYSCALL:
+       {
                struct lttng_event_notifier_enabler *enabler;
 
                if (strutils_is_star_glob_pattern(event_notifier_param->event.name)) {
@@ -2045,7 +2064,13 @@ int lttng_abi_create_event_notifier(struct file *event_notifier_group_file,
                                        event_notifier_param);
                }
                priv = enabler;
-       } else {
+               break;
+       }
+
+       case LTTNG_KERNEL_KPROBE:               /* Fall-through */
+       case LTTNG_KERNEL_KRETPROBE:            /* Fall-through */
+       case LTTNG_KERNEL_UPROBE:
+       {
                struct lttng_event_notifier *event_notifier;
 
                /*
@@ -2064,6 +2089,14 @@ int lttng_abi_create_event_notifier(struct file *event_notifier_group_file,
                        goto event_notifier_error;
                }
                priv = event_notifier;
+               break;
+       }
+
+       case LTTNG_KERNEL_FUNCTION:             /* Fall-through */
+       case LTTNG_KERNEL_NOOP:                 /* Fall-through */
+       default:
+               ret = -EINVAL;
+               goto event_notifier_error;
        }
        event_notifier_file->private_data = priv;
        fd_install(event_notifier_fd, event_notifier_file);
This page took 0.027938 seconds and 4 git commands to generate.