]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
login: switch an if condition to a switch statement
authorPeter Hutterer <peter.hutterer@who-t.net>
Wed, 1 Nov 2023 01:57:21 +0000 (11:57 +1000)
committerLennart Poettering <lennart@poettering.net>
Mon, 6 Nov 2023 16:42:28 +0000 (17:42 +0100)
No functional changes but makes the code more readable once we expand
the list of device types.

src/login/logind-session-device.c

index 9743cd570cf820850406427459c4ea0598aa59ca..44d8d525ee01c240ac4033dc0dae78374c129f76 100644 (file)
@@ -275,21 +275,26 @@ static int session_device_verify(SessionDevice *sd) {
 
         /* detect device type so we can find the correct sysfs parent */
         sd->type = detect_device_type(dev);
-        if (sd->type == DEVICE_TYPE_UNKNOWN)
-                return -ENODEV;
 
-        else if (sd->type == DEVICE_TYPE_EVDEV) {
+        /* Prevent opening unsupported devices. Especially devices of
+         * subsystem "input" must be opened via the evdev node as
+         * we require EVIOCREVOKE. */
+        switch (sd->type) {
+        case DEVICE_TYPE_EVDEV:
                 /* for evdev devices we need the parent node as device */
                 if (sd_device_get_parent_with_subsystem_devtype(p, "input", NULL, &dev) < 0)
                         return -ENODEV;
                 if (sd_device_get_syspath(dev, &sp) < 0)
                         return -ENODEV;
+                break;
 
-        } else if (sd->type != DEVICE_TYPE_DRM)
-                /* Prevent opening unsupported devices. Especially devices of
-                 * subsystem "input" must be opened via the evdev node as
-                 * we require EVIOCREVOKE. */
+        case DEVICE_TYPE_DRM:
+                break;
+
+        case  DEVICE_TYPE_UNKNOWN:
+        default:
                 return -ENODEV;
+        }
 
         /* search for an existing seat device and return it if available */
         sd->device = hashmap_get(sd->session->manager->devices, sp);