Re: [PATCH v4] btf: reject to register duplicated kfunc

From: Leon Hwang

Date: Tue Jun 02 2026 - 22:19:53 EST


On 3/6/26 01:13, Yonghong Song wrote:
>
>
> On 6/2/26 4:07 AM, Song Chen wrote:
[...]
>> +
>> +#ifdef CONFIG_DEBUG_INFO_BTF_MODULES
>> +    mutex_lock(&btf_module_mutex);
>> +    list_for_each_entry_safe(btf_mod, tmp, &btf_modules, list) {
>> +        if (btf_mod->btf == btf)
>> +            continue;
>> +        id = btf_find_by_name_kind(btf_mod->btf, func_name, kind);
>> +        if (id >= 0) {
>> +            pr_err("kfunc %s (id: %d) is already present in module
>> %s.\n",
>> +                    func_name, id, btf_mod->module->name);
>> +            mutex_unlock(&btf_module_mutex);
>> +            return -EINVAL;
>
> Let us avoid the above mutex_unlock and 'return -EINVAL', just do
>     err = -EINVAL;
>     break;
>

Better to use guard(mutex)(&btf_module_mutex)?

Thanks,
Leon

>> [...]