summaryrefslogtreecommitdiff
path: root/modules/devices/devicetree
diff options
context:
space:
mode:
authorBurt P <pburt0@gmail.com>2017-07-25 14:33:49 -0500
committerLeandro A. F. Pereira <leandro@hardinfo.org>2017-07-25 19:02:32 -0700
commit81ae37c58709cf1396b09e5136acfc8a0c259476 (patch)
treef3e502ab9841dd0b1815ef4848d226cba87037ab /modules/devices/devicetree
parent8e4746423c20b525671998b1bc94b3b6d8ec78d6 (diff)
device tree: fix crash when device tree is not found
* check if device tree was found before add_keys() * UNKIFNULL(model) before strcmp * make UNKIFNULL() STRIFNULL() EMPIFNULL() macros more generic Signed-off-by: Burt P <pburt0@gmail.com>
Diffstat (limited to 'modules/devices/devicetree')
-rw-r--r--modules/devices/devicetree/dt_util.c23
-rw-r--r--modules/devices/devicetree/pmac_data.c15
2 files changed, 25 insertions, 13 deletions
diff --git a/modules/devices/devicetree/dt_util.c b/modules/devices/devicetree/dt_util.c
index 6ef41bd6..619e63be 100644
--- a/modules/devices/devicetree/dt_util.c
+++ b/modules/devices/devicetree/dt_util.c
@@ -221,19 +221,24 @@ const char *dtr_find_device_tree_root() {
return candidates[i];
i++;
}
- return "/did/not/find/device-tree";
+ return NULL;
}
dtr *dtr_new_x(char *base_path, int fast) {
dtr *dt = malloc(sizeof(dtr));
if (dt != NULL) {
memset(dt, 0, sizeof(dtr));
+ dt->log = strdup("");
+
+ if (base_path == NULL)
+ base_path = DTR_ROOT;
+
if (base_path != NULL)
dt->base_path = strdup(base_path);
- else
- dt->base_path = strdup(DTR_ROOT);
-
- dt->log = strdup("");
+ else {
+ dtr_msg(dt, "%s", "Device Tree not found.");
+ return dt;
+ }
/* build alias and phandle lists */
dt->aliases = NULL;
@@ -263,6 +268,14 @@ void dtr_free(dtr *s) {
}
}
+int dtr_was_found(dtr *s) {
+ if (s != NULL) {
+ if (s->base_path != NULL)
+ return 1;
+ }
+ return 0;
+}
+
void dtr_msg(dtr *s, char *fmt, ...) {
gchar *buf, *tmp;
va_list args;
diff --git a/modules/devices/devicetree/pmac_data.c b/modules/devices/devicetree/pmac_data.c
index 01b08419..b236aef1 100644
--- a/modules/devices/devicetree/pmac_data.c
+++ b/modules/devices/devicetree/pmac_data.c
@@ -58,14 +58,13 @@ static gchar *ppc_mac_details(void) {
if (machine == NULL)
goto pmd_exit;
-#define _UNKIFNULL(STR) if (STR == NULL) { STR = strdup(_("(Unknown)")); }
- _UNKIFNULL(platform);
- _UNKIFNULL(model);
- _UNKIFNULL(motherboard);
- _UNKIFNULL(detected_as);
- _UNKIFNULL(pmac_flags);
- _UNKIFNULL(l2_cache);
- _UNKIFNULL(pmac_gen);
+ UNKIFNULL(platform);
+ UNKIFNULL(model);
+ UNKIFNULL(motherboard);
+ UNKIFNULL(detected_as);
+ UNKIFNULL(pmac_flags);
+ UNKIFNULL(l2_cache);
+ UNKIFNULL(pmac_gen);
ret = g_strdup_printf("[%s]\n"
"%s=%s\n"