From 7ac7c061a140b6d2ccd1856cb02c19e8fabdb39e Mon Sep 17 00:00:00 2001 From: Philip Elcan Date: Thu, 11 Oct 2018 10:14:40 -0400 Subject: [PATCH] gpu: nvgpu: unit: only load .so files There was a situation where a .so.debug file was stored with the unit .so files and was causing the unit test framework to abort with a "Bus Error." This update only loads files ending in .so to avoid loading invalid files in the future. Bug 2415403 Change-Id: I0c3cdd7a05942b746695f88f5b1f2324f309daba Signed-off-by: Philip Elcan Reviewed-on: https://git-master.nvidia.com/r/1924614 Reviewed-by: svc-mobile-coverity GVS: Gerrit_Virtual_Submit Reviewed-by: Nicolas Benech Reviewed-by: Konsta Holtta Reviewed-by: Alex Waterman Reviewed-by: mobile promotions Tested-by: mobile promotions --- userspace/src/module.c | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/userspace/src/module.c b/userspace/src/module.c index deb18b0f7..836d36abd 100644 --- a/userspace/src/module.c +++ b/userspace/src/module.c @@ -117,6 +117,17 @@ static void sort_modules_by_prio(struct unit_module **modules, int nr) cmp_module_prio); } +static bool is_shared_obj_filename(char *name) +{ + size_t len = strlen(name); + + if ((len > 3) && (strcmp(&name[len-3], ".so") == 0)) { + return true; + } else { + return false; + } +} + /* * Load all the modules we can from the module load path. Return the list of * loaded module as an array of pointers to modules. The returned list of @@ -142,11 +153,17 @@ struct unit_module **core_load_modules(struct unit_fw *fw) return NULL; } - while (readdir(load_dir) != NULL) - nr_modules += 1; - - /* '.' and '..' should be skipped. */ - nr_modules -= 2; + ent = readdir(load_dir); + while (ent != NULL) { + if (is_shared_obj_filename(ent->d_name)) { + nr_modules += 1; + } else { + core_vbs(fw, 1, + "Skipping load of file %s (not a .so)\n", + ent->d_name); + } + ent = readdir(load_dir); + } /* * Now allocate necessary space for storing pointers to the modules and @@ -162,7 +179,8 @@ struct unit_module **core_load_modules(struct unit_fw *fw) i = 0; while ((ent = readdir(load_dir)) != NULL) { if (strcmp(".", ent->d_name) == 0 || - strcmp("..", ent->d_name) == 0) + strcmp("..", ent->d_name) == 0 || + !is_shared_obj_filename(ent->d_name)) continue; mod = load_one_module(fw, ent);