Blame SOURCES/0001-Do-not-make-any-of-the-HWIDs-setup-failures-fatal.patch

75fbaf
From 90e5a58736645cdd37bf4c63f9a4056951dfb3f2 Mon Sep 17 00:00:00 2001
75fbaf
From: Richard Hughes <richard@hughsie.com>
75fbaf
Date: Tue, 24 Jan 2023 09:52:17 +0000
75fbaf
Subject: [PATCH] Do not make any of the HWIDs setup failures fatal
75fbaf
75fbaf
It's perfectly okay to have no HWIDs defined.
75fbaf
75fbaf
Should help with https://github.com/fwupd/fwupd/issues/5402
75fbaf
---
75fbaf
 libfwupdplugin/fu-context.c | 73 +++++++++++--------------------------
75fbaf
 1 file changed, 21 insertions(+), 52 deletions(-)
75fbaf
75fbaf
diff --git a/libfwupdplugin/fu-context.c b/libfwupdplugin/fu-context.c
75fbaf
index 08618b435..11b4b1b38 100644
75fbaf
--- a/libfwupdplugin/fu-context.c
75fbaf
+++ b/libfwupdplugin/fu-context.c
75fbaf
@@ -767,6 +767,8 @@ fu_context_security_changed(FuContext *self)
75fbaf
 	g_signal_emit(self, signals[SIGNAL_SECURITY_CHANGED], 0);
75fbaf
 }
75fbaf
 
75fbaf
+typedef gboolean (*FuContextHwidsSetupFunc)(FuContext *self, FuHwids *hwids, GError **error);
75fbaf
+
75fbaf
 /**
75fbaf
  * fu_context_load_hwinfo:
75fbaf
  * @self: a #FuContext
75fbaf
@@ -786,62 +788,29 @@ fu_context_load_hwinfo(FuContext *self, FuContextHwidFlags flags, GError **error
75fbaf
 	GPtrArray *guids;
75fbaf
 	g_autoptr(GError) error_hwids = NULL;
75fbaf
 	g_autoptr(GError) error_bios_settings = NULL;
75fbaf
+	struct {
75fbaf
+		const gchar *name;
75fbaf
+		FuContextHwidFlags flag;
75fbaf
+		FuContextHwidsSetupFunc func;
75fbaf
+	} hwids_setup_map[] = {{"config", FU_CONTEXT_HWID_FLAG_LOAD_CONFIG, fu_hwids_config_setup},
75fbaf
+			       {"smbios", FU_CONTEXT_HWID_FLAG_LOAD_SMBIOS, fu_hwids_smbios_setup},
75fbaf
+			       {"fdt", FU_CONTEXT_HWID_FLAG_LOAD_FDT, fu_hwids_fdt_setup},
75fbaf
+			       {"kenv", FU_CONTEXT_HWID_FLAG_LOAD_KENV, fu_hwids_kenv_setup},
75fbaf
+			       {"dmi", FU_CONTEXT_HWID_FLAG_LOAD_DMI, fu_hwids_dmi_setup},
75fbaf
+			       {NULL, FU_CONTEXT_HWID_FLAG_NONE, NULL}};
75fbaf
 
75fbaf
 	g_return_val_if_fail(FU_IS_CONTEXT(self), FALSE);
75fbaf
 	g_return_val_if_fail(error == NULL || *error == NULL, FALSE);
75fbaf
 
75fbaf
-	if ((flags & FU_CONTEXT_HWID_FLAG_LOAD_CONFIG) > 0) {
75fbaf
-		g_autoptr(GError) error_local = NULL;
75fbaf
-		if (!fu_hwids_config_setup(self, priv->hwids, &error_local)) {
75fbaf
-			if (!g_error_matches(error_local, FWUPD_ERROR, FWUPD_ERROR_NOT_SUPPORTED)) {
75fbaf
-				g_propagate_prefixed_error(error,
75fbaf
-							   g_steal_pointer(&error_local),
75fbaf
-							   "Failed to load HWIDs config: ");
75fbaf
-				return FALSE;
75fbaf
-			}
75fbaf
-		}
75fbaf
-	}
75fbaf
-	if ((flags & FU_CONTEXT_HWID_FLAG_LOAD_DMI) > 0) {
75fbaf
-		g_autoptr(GError) error_local = NULL;
75fbaf
-		if (!fu_hwids_dmi_setup(self, priv->hwids, &error_local)) {
75fbaf
-			if (!g_error_matches(error_local, FWUPD_ERROR, FWUPD_ERROR_NOT_SUPPORTED)) {
75fbaf
-				g_propagate_prefixed_error(error,
75fbaf
-							   g_steal_pointer(&error_local),
75fbaf
-							   "Failed to load HWIDs DMI: ");
75fbaf
-				return FALSE;
75fbaf
-			}
75fbaf
-		}
75fbaf
-	}
75fbaf
-	if ((flags & FU_CONTEXT_HWID_FLAG_LOAD_FDT) > 0) {
75fbaf
-		g_autoptr(GError) error_local = NULL;
75fbaf
-		if (!fu_hwids_fdt_setup(self, priv->hwids, &error_local)) {
75fbaf
-			if (!g_error_matches(error_local, FWUPD_ERROR, FWUPD_ERROR_NOT_SUPPORTED)) {
75fbaf
-				g_propagate_prefixed_error(error,
75fbaf
-							   g_steal_pointer(&error_local),
75fbaf
-							   "Failed to load HWIDs FDT: ");
75fbaf
-				return FALSE;
75fbaf
-			}
75fbaf
-		}
75fbaf
-	}
75fbaf
-	if ((flags & FU_CONTEXT_HWID_FLAG_LOAD_KENV) > 0) {
75fbaf
-		g_autoptr(GError) error_local = NULL;
75fbaf
-		if (!fu_hwids_kenv_setup(self, priv->hwids, &error_local)) {
75fbaf
-			if (!g_error_matches(error_local, FWUPD_ERROR, FWUPD_ERROR_NOT_SUPPORTED)) {
75fbaf
-				g_propagate_prefixed_error(error,
75fbaf
-							   g_steal_pointer(&error_local),
75fbaf
-							   "Failed to load HWIDs kenv: ");
75fbaf
-				return FALSE;
75fbaf
-			}
75fbaf
-		}
75fbaf
-	}
75fbaf
-	if ((flags & FU_CONTEXT_HWID_FLAG_LOAD_SMBIOS) > 0) {
75fbaf
-		g_autoptr(GError) error_local = NULL;
75fbaf
-		if (!fu_hwids_smbios_setup(self, priv->hwids, &error_local)) {
75fbaf
-			if (!g_error_matches(error_local, FWUPD_ERROR, FWUPD_ERROR_NOT_SUPPORTED)) {
75fbaf
-				g_propagate_prefixed_error(error,
75fbaf
-							   g_steal_pointer(&error_local),
75fbaf
-							   "Failed to load SMBIOS: ");
75fbaf
-				return FALSE;
75fbaf
+	/* run all the HWID setup funcs */
75fbaf
+	for (guint i = 0; hwids_setup_map[i].name != NULL; i++) {
75fbaf
+		if ((flags & hwids_setup_map[i].flag) > 0) {
75fbaf
+			g_autoptr(GError) error_local = NULL;
75fbaf
+			if (!hwids_setup_map[i].func(self, priv->hwids, &error_local)) {
75fbaf
+				g_debug("failed to load %s: %s",
75fbaf
+					hwids_setup_map[i].name,
75fbaf
+					error_local->message);
75fbaf
+				break;
75fbaf
 			}
75fbaf
 		}
75fbaf
 	}
75fbaf
-- 
75fbaf
2.39.1
75fbaf