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

Commit dba385ed authored by Kelvin Zhang's avatar Kelvin Zhang
Browse files

Ignore 16K kernel modules when running on 4K kernel

Test: th
Bug: 293313353
Change-Id: I02ea01c8e67b9ded164c7492eea3be0aead75de1
parent 09a61fad
Loading
Loading
Loading
Loading
+21 −1
Original line number Original line Diff line number Diff line
@@ -163,6 +163,21 @@ std::string GetPageSizeSuffix() {
    return android::base::StringPrintf("_%zuk", page_size / 1024);
    return android::base::StringPrintf("_%zuk", page_size / 1024);
}
}


constexpr bool EndsWith(const std::string_view str, const std::string_view suffix) {
    return str.size() >= suffix.size() &&
           0 == str.compare(str.size() - suffix.size(), suffix.size(), suffix);
}

constexpr std::string_view GetPageSizeSuffix(std::string_view dirname) {
    if (EndsWith(dirname, "_16k")) {
        return "_16k";
    }
    if (EndsWith(dirname, "_64k")) {
        return "_64k";
    }
    return "";
}

}  // namespace
}  // namespace


std::string GetModuleLoadList(BootMode boot_mode, const std::string& dir_path) {
std::string GetModuleLoadList(BootMode boot_mode, const std::string& dir_path) {
@@ -211,7 +226,8 @@ bool LoadKernelModules(BootMode boot_mode, bool want_console, bool want_parallel
    }
    }
    dirent* entry = nullptr;
    dirent* entry = nullptr;
    std::vector<std::string> module_dirs;
    std::vector<std::string> module_dirs;
    const std::string release_specific_module_dir = uts.release + GetPageSizeSuffix();
    const auto page_size_suffix = GetPageSizeSuffix();
    const std::string release_specific_module_dir = uts.release + page_size_suffix;
    while ((entry = readdir(base_dir.get()))) {
    while ((entry = readdir(base_dir.get()))) {
        if (entry->d_type != DT_DIR) {
        if (entry->d_type != DT_DIR) {
            continue;
            continue;
@@ -223,6 +239,10 @@ bool LoadKernelModules(BootMode boot_mode, bool want_console, bool want_parallel
            module_dirs.emplace_back(entry->d_name);
            module_dirs.emplace_back(entry->d_name);
            break;
            break;
        }
        }
        // Ignore _16k/_64k module dirs on 4K kernels
        if (GetPageSizeSuffix(entry->d_name) != page_size_suffix) {
            continue;
        }
        int dir_major = 0, dir_minor = 0;
        int dir_major = 0, dir_minor = 0;
        if (sscanf(entry->d_name, "%d.%d", &dir_major, &dir_minor) != 2 || dir_major != major ||
        if (sscanf(entry->d_name, "%d.%d", &dir_major, &dir_minor) != 2 || dir_major != major ||
            dir_minor != minor) {
            dir_minor != minor) {