Re: [PATCH v4] btf: reject to register duplicated kfunc
From: Song Chen
Date: Wed Jun 03 2026 - 05:20:08 EST
Hi,
在 2026/6/3 10:18, Leon Hwang 写道:
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)?
This is the first time i used guard and it's awesome. I have tested in my code and will send a new patch later, many thanks.
Thanks,
Leon
[...]
Song