Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit d4e75d57 authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge "Load kernel modules from /lib/modules/`uname -r`_$(page_size) if present" into main

parents 30b1c4dd d479afa0
Loading
Loading
Loading
Loading
+20 −0
Original line number Diff line number Diff line
@@ -35,6 +35,7 @@
#include <android-base/chrono_utils.h>
#include <android-base/file.h>
#include <android-base/logging.h>
#include <android-base/stringprintf.h>
#include <modprobe/modprobe.h>
#include <private/android_filesystem_config.h>

@@ -153,6 +154,15 @@ void PrepareSwitchRoot() {
        Copy(snapuserd, dst);
    }
}

std::string GetPageSizeSuffix() {
    static const size_t page_size = sysconf(_SC_PAGE_SIZE);
    if (page_size <= 4096) {
        return "";
    }
    return android::base::StringPrintf("_%zuk", page_size / 1024);
}

}  // namespace

std::string GetModuleLoadList(BootMode boot_mode, const std::string& dir_path) {
@@ -201,10 +211,18 @@ bool LoadKernelModules(BootMode boot_mode, bool want_console, bool want_parallel
    }
    dirent* entry = nullptr;
    std::vector<std::string> module_dirs;
    const std::string release_specific_module_dir = uts.release + GetPageSizeSuffix();
    while ((entry = readdir(base_dir.get()))) {
        if (entry->d_type != DT_DIR) {
            continue;
        }
        if (entry->d_name == release_specific_module_dir) {
            LOG(INFO) << "Release specific kernel module dir " << release_specific_module_dir
                      << " found, loading modules from here with no fallbacks.";
            module_dirs.clear();
            module_dirs.emplace_back(entry->d_name);
            break;
        }
        int dir_major = 0, dir_minor = 0;
        if (sscanf(entry->d_name, "%d.%d", &dir_major, &dir_minor) != 2 || dir_major != major ||
            dir_minor != minor) {
@@ -228,6 +246,7 @@ bool LoadKernelModules(BootMode boot_mode, bool want_console, bool want_parallel
        bool retval = m.LoadListedModules(!want_console);
        modules_loaded = m.GetModuleCount();
        if (modules_loaded > 0) {
            LOG(INFO) << "Loaded " << modules_loaded << " modules from " << dir_path;
            return retval;
        }
    }
@@ -237,6 +256,7 @@ bool LoadKernelModules(BootMode boot_mode, bool want_console, bool want_parallel
                                  : m.LoadListedModules(!want_console);
    modules_loaded = m.GetModuleCount();
    if (modules_loaded > 0) {
        LOG(INFO) << "Loaded " << modules_loaded << " modules from " << MODULE_BASE_DIR;
        return retval;
    }
    return true;