kernel-device: generic: Support ATTR condition

Only the plural ATTRS form was checked but we also need to support
the single ATTR for matching device's attribute only.

Signed-off-by: Loic Poulain <loic.poulain@linaro.org>
This commit is contained in:
Loic Poulain
2021-07-30 15:34:17 +02:00
committed by Aleksander Morgado
parent 7c4db66eb3
commit b0248e471c

View File

@@ -128,7 +128,8 @@ read_sysfs_attribute_link_basename (const gchar *path,
static gchar * static gchar *
lookup_sysfs_attribute_as_string (MMKernelDeviceGeneric *self, lookup_sysfs_attribute_as_string (MMKernelDeviceGeneric *self,
const gchar *attribute) const gchar *attribute,
gboolean iterate)
{ {
g_autofree gchar *iter = NULL; g_autofree gchar *iter = NULL;
@@ -145,6 +146,8 @@ lookup_sysfs_attribute_as_string (MMKernelDeviceGeneric *self,
/* return first one found */ /* return first one found */
if ((value = read_sysfs_attribute_as_string (iter, attribute)) != NULL) if ((value = read_sysfs_attribute_as_string (iter, attribute)) != NULL)
return value; return value;
else if (!iterate)
break;
if (g_strcmp0 (iter, self->priv->physdev_sysfs_path) == 0) if (g_strcmp0 (iter, self->priv->physdev_sysfs_path) == 0)
break; break;
@@ -834,7 +837,7 @@ check_condition (MMKernelDeviceGeneric *self,
} }
/* Attributes checks */ /* Attributes checks */
if (g_str_has_prefix (match->parameter, "ATTRS")) { if (g_str_has_prefix (match->parameter, "ATTR")) {
gchar *attribute; gchar *attribute;
gchar *contents = NULL; gchar *contents = NULL;
gboolean result = FALSE; gboolean result = FALSE;
@@ -873,7 +876,7 @@ check_condition (MMKernelDeviceGeneric *self,
else { else {
g_autofree gchar *found_value = NULL; g_autofree gchar *found_value = NULL;
found_value = lookup_sysfs_attribute_as_string (self, attribute); found_value = lookup_sysfs_attribute_as_string (self, attribute, g_str_has_prefix (match->parameter, "ATTRS"));
result = ((found_value && g_str_equal (found_value, match->value)) == condition_equal); result = ((found_value && g_str_equal (found_value, match->value)) == condition_equal);
} }