openbmc/build/tmp/deploy/sdk/witherspoon-2019-08-08/sysroots/armv6-openbmc-linux-gnueabi/usr/src/debug/kmod/26-r0/git/tools/depmod.c
static int depmod_module_is_higher_priority(const struct depmod* depmod,
                                            const struct mod* mod,
                                            size_t baselen, size_t namelen,
                                            size_t modnamelen,
                                            const char* newpath)
{
    const struct cfg* cfg = depmod->cfg;
    const struct cfg_override* ov;
    const struct cfg_search* se;
    const struct cfg_external* ext;

    /* baselen includes the last '/' and mod->baselen doesn't. So it's
     * actually correct to use modnamelen in the first and modnamesz in
     * the latter */
    size_t newlen = baselen + modnamelen;
    size_t oldlen = mod->baselen + mod->modnamesz;
    const char* oldpath = mod->path;
    int i, bprio = -1, oldprio = -1, newprio = -1;
    size_t relnewlen = 0;
    size_t reloldlen = 0;
    const char* relnewpath = NULL;
    const char* reloldpath = NULL;

    DBG("comparing priorities of %s and %s\n", oldpath, newpath);

    if (strncmp(newpath, cfg->dirname, cfg->dirnamelen) == 0)
    {
        relnewpath = newpath + cfg->dirnamelen + 1;
        relnewlen = newlen - (cfg->dirnamelen + 1);
    }
    if (strncmp(oldpath, cfg->dirname, cfg->dirnamelen) == 0)
    {
        reloldpath = oldpath + cfg->dirnamelen + 1;
        reloldlen = oldlen - (cfg->dirnamelen + 1);
    }

    for (ov = cfg->overrides; ov != NULL; ov = ov->next)
    {
        DBG("override %s\n", ov->path);
        if (relnewlen == ov->len &&
            memcmp(ov->path, relnewpath, relnewlen) == 0)
            return 0;
        if (reloldlen == ov->len &&
            memcmp(ov->path, reloldpath, reloldlen) == 0)
            return 1;
    }

    for (i = 0, se = cfg->searches; se != NULL; se = se->next, i++)
    {
        DBG("search %s\n", search_to_string(se));
        if (se->type == SEARCH_BUILTIN)
            bprio = i;
        else if (se->type == SEARCH_EXTERNAL)
        {
            for (ext = cfg->externals; ext != NULL; ext = ext->next, i++)
            {
                if (depmod_is_path_starts_with(newpath, newlen, ext->path,
                                               ext->len))
                    newprio = i;
                if (depmod_is_path_starts_with(oldpath, oldlen, ext->path,
                                               ext->len))
                    oldprio = i;
            }
        }
        else if (relnewlen > se->len && relnewpath[se->len] == '/' &&
                 memcmp(se->path, relnewpath, se->len) == 0)
            newprio = i;
        else if (reloldlen > se->len && reloldpath[se->len] == '/' &&
                 memcmp(se->path, reloldpath, se->len) == 0)
            oldprio = i;
    }

    if (newprio < 0)
        newprio = bprio;
    if (oldprio < 0)
        oldprio = bprio;

    DBG("priorities: built-in: %d, old: %d, new: %d\n", bprio, oldprio,
        newprio);

    return newprio <= oldprio;
}
/* returns if existing module @mod is higher priority than newpath.
 * note this is the inverse of module-init-tools is_higher_priority()
 */
returns if existing module @mod is higher priority than newpath.
note this is the inverse of module-init-tools is_higher_priority()
returns if existing module @mod is higher priority than newpath . note this is the inverse of module - init - tools is_higher_priority ()
static int depmod_module_is_higher_priority(const struct depmod* depmod,
                                            const struct mod* mod,
                                            size_t baselen, size_t namelen,
                                            size_t modnamelen,
                                            const char* newpath)
{
    const struct cfg* cfg = depmod->cfg;
    const struct cfg_override* ov;
    const struct cfg_search* se;
    const struct cfg_external* ext;
    size_t newlen = baselen + modnamelen;
    size_t oldlen = mod->baselen + mod->modnamesz;
    const char* oldpath = mod->path;
    int i, bprio = -1, oldprio = -1, newprio = -1;
    size_t relnewlen = 0;
    size_t reloldlen = 0;
    const char* relnewpath = NULL;
    const char* reloldpath = NULL;
    DBG("comparing priorities of %s and %s\n", oldpath, newpath);
    if (strncmp(newpath, cfg->dirname, cfg->dirnamelen) == 0)
    {
        relnewpath = newpath + cfg->dirnamelen + 1;
        relnewlen = newlen - (cfg->dirnamelen + 1);
    }
    if (strncmp(oldpath, cfg->dirname, cfg->dirnamelen) == 0)
    {
        reloldpath = oldpath + cfg->dirnamelen + 1;
        reloldlen = oldlen - (cfg->dirnamelen + 1);
    }
    for (ov = cfg->overrides; ov != NULL; ov = ov->next)
    {
        DBG("override %s\n", ov->path);
        if (relnewlen == ov->len &&
            memcmp(ov->path, relnewpath, relnewlen) == 0)
            return 0;
        if (reloldlen == ov->len &&
            memcmp(ov->path, reloldpath, reloldlen) == 0)
            return 1;
    }
    for (i = 0, se = cfg->searches; se != NULL; se = se->next, i++)
    {
        DBG("search %s\n", search_to_string(se));
        if (se->type == SEARCH_BUILTIN)
            bprio = i;
        else if (se->type == SEARCH_EXTERNAL)
        {
            for (ext = cfg->externals; ext != NULL; ext = ext->next, i++)
            {
                if (depmod_is_path_starts_with(newpath, newlen, ext->path,
                                               ext->len))
                    newprio = i;
                if (depmod_is_path_starts_with(oldpath, oldlen, ext->path,
                                               ext->len))
                    oldprio = i;
            }
        }
        else if (relnewlen > se->len && relnewpath[se->len] == '/' &&
                 memcmp(se->path, relnewpath, se->len) == 0)
            newprio = i;
        else if (reloldlen > se->len && reloldpath[se->len] == '/' &&
                 memcmp(se->path, reloldpath, se->len) == 0)
            oldprio = i;
    }
    if (newprio < 0)
        newprio = bprio;
    if (oldprio < 0)
        oldprio = bprio;
    DBG("priorities: built-in: %d, old: %d, new: %d\n", bprio, oldprio,
        newprio);
    return newprio <= oldprio;
}
static int depmod_module_is_higher_priority ( const struct depmod * depmod , const struct mod * mod , size_t baselen , size_t namelen , size_t modnamelen , const char * newpath ) { const struct cfg * cfg = depmod -> cfg ; const struct cfg_override * ov ; const struct cfg_search * se ; const struct cfg_external * ext ; size_t newlen = baselen + modnamelen ; size_t oldlen = mod -> baselen + mod -> modnamesz ; const char * oldpath = mod -> path ; int i , bprio = -1 , oldprio = -1 , newprio = -1 ; size_t relnewlen = 0 ; size_t reloldlen = 0 ; const char * relnewpath = NULL ; const char * reloldpath = NULL ; DBG ( " \n " , oldpath , newpath ) ; if ( strncmp ( newpath , cfg -> dirname , cfg -> dirnamelen ) == 0 ) { relnewpath = newpath + cfg -> dirnamelen + 1 ; relnewlen = newlen - ( cfg -> dirnamelen + 1 ) ; } if ( strncmp ( oldpath , cfg -> dirname , cfg -> dirnamelen ) == 0 ) { reloldpath = oldpath + cfg -> dirnamelen + 1 ; reloldlen = oldlen - ( cfg -> dirnamelen + 1 ) ; } for ( ov = cfg -> overrides ; ov != NULL ; ov = ov -> next ) { DBG ( " \n " , ov -> path ) ; if ( relnewlen == ov -> len && memcmp ( ov -> path , relnewpath , relnewlen ) == 0 ) return 0 ; if ( reloldlen == ov -> len && memcmp ( ov -> path , reloldpath , reloldlen ) == 0 ) return 1 ; } for ( i = 0 , se = cfg -> searches ; se != NULL ; se = se -> next , i ++ ) { DBG ( " \n " , search_to_string ( se ) ) ; if ( se -> type == SEARCH_BUILTIN ) bprio = i ; else if ( se -> type == SEARCH_EXTERNAL ) { for ( ext = cfg -> externals ; ext != NULL ; ext = ext -> next , i ++ ) { if ( depmod_is_path_starts_with ( newpath , newlen , ext -> path , ext -> len ) ) newprio = i ; if ( depmod_is_path_starts_with ( oldpath , oldlen , ext -> path , ext -> len ) ) oldprio = i ; } } else if ( relnewlen > se -> len && relnewpath [ se -> len ] == ' ' && memcmp ( se -> path , relnewpath , se -> len ) == 0 ) newprio = i ; else if ( reloldlen > se -> len && reloldpath [ se -> len ] == ' ' && memcmp ( se -> path , reloldpath , se -> len ) == 0 ) oldprio = i ; } if ( newprio < 0 ) newprio = bprio ; if ( oldprio < 0 ) oldprio = bprio ; DBG ( " \n " , bprio , oldprio , newprio ) ; return newprio <= oldprio ; }
returns if existing module @mod is higher priority than newpath.
returns if existing module @mod is higher priority than newpath .
/* baselen includes the last '/' and mod->baselen doesn't. So it's
     * actually correct to use modnamelen in the first and modnamesz in
     * the latter */