From: Peter Hutterer Date: Wed, 1 Nov 2023 01:57:21 +0000 (+1000) Subject: login: switch an if condition to a switch statement X-Git-Tag: v255-rc2~113 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=351072ed71ba21d18aae916d86fcc4152381f316;p=thirdparty%2Fsystemd.git login: switch an if condition to a switch statement No functional changes but makes the code more readable once we expand the list of device types. --- diff --git a/src/login/logind-session-device.c b/src/login/logind-session-device.c index 9743cd570cf..44d8d525ee0 100644 --- a/src/login/logind-session-device.c +++ b/src/login/logind-session-device.c @@ -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);