From 59ad8409a6088b3592b537122b39d4d609ee829a Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Tue, 9 Nov 2021 10:49:20 +0100 Subject: kerneldevice,generic: simplify DEVPATH matching logic Use autoptr to avoid the embedded goto. --- src/kerneldevice/mm-kernel-device-generic.c | 30 ++++++++--------------------- 1 file changed, 8 insertions(+), 22 deletions(-) (limited to 'src/kerneldevice/mm-kernel-device-generic.c') diff --git a/src/kerneldevice/mm-kernel-device-generic.c b/src/kerneldevice/mm-kernel-device-generic.c index e0ee7720..9d4fbf06 100644 --- a/src/kerneldevice/mm-kernel-device-generic.c +++ b/src/kerneldevice/mm-kernel-device-generic.c @@ -773,8 +773,7 @@ check_condition (MMKernelDeviceGeneric *self, /* Device sysfs path checks; we allow both a direct match and a prefix patch */ if (g_str_equal (match->parameter, "DEVPATH")) { - gchar *prefix_match = NULL; - gboolean result = FALSE; + g_autofree gchar *prefix_match = NULL; /* If sysfs path invalid (e.g. path doesn't exist), no match */ if (!self->priv->sysfs_path) @@ -786,29 +785,16 @@ check_condition (MMKernelDeviceGeneric *self, if (match->value[0] && match->value[strlen (match->value) - 1] != '*') prefix_match = g_strdup_printf ("%s/*", match->value); - if (mm_kernel_device_generic_string_match (self->priv->sysfs_path, match->value, self) == condition_equal) { - result = TRUE; - goto out; - } - - if (prefix_match && mm_kernel_device_generic_string_match (self->priv->sysfs_path, prefix_match, self) == condition_equal) { - result = TRUE; - goto out; - } + if ((mm_kernel_device_generic_string_match (self->priv->sysfs_path, match->value, self) == condition_equal) || + (prefix_match && mm_kernel_device_generic_string_match (self->priv->sysfs_path, prefix_match, self) == condition_equal)) + return TRUE; if (g_str_has_prefix (self->priv->sysfs_path, "/sys")) { - if (mm_kernel_device_generic_string_match (&self->priv->sysfs_path[4], match->value, self) == condition_equal) { - result = TRUE; - goto out; - } - if (prefix_match && mm_kernel_device_generic_string_match (&self->priv->sysfs_path[4], prefix_match, self) == condition_equal) { - result = TRUE; - goto out; - } + if ((mm_kernel_device_generic_string_match (&self->priv->sysfs_path[4], match->value, self) == condition_equal) || + (prefix_match && mm_kernel_device_generic_string_match (&self->priv->sysfs_path[4], prefix_match, self) == condition_equal)) + return TRUE; } - out: - g_free (prefix_match); - return result; + return FALSE; } /* Attributes checks */ -- cgit v1.2.3-70-g09d2