mirror of
				https://github.com/torvalds/linux.git
				synced 2025-10-31 16:48:26 +02:00 
			
		
		
		
	bpf: Always raise reference in btf_get_module_btf
Align it with helpers like bpf_find_btf_id, so all functions returning BTF in out parameter follow the same rule of raising reference consistently, regardless of module or vmlinux BTF. Adjust existing callers to handle the change accordinly. Signed-off-by: Kumar Kartikeya Dwivedi <memxor@gmail.com> Signed-off-by: Alexei Starovoitov <ast@kernel.org> Link: https://lore.kernel.org/bpf/20220317115957.3193097-10-memxor@gmail.com
This commit is contained in:
		
							parent
							
								
									edc3ec09ab
								
							
						
					
					
						commit
						9492450fd2
					
				
					 1 changed files with 11 additions and 10 deletions
				
			
		|  | @ -6572,20 +6572,23 @@ struct module *btf_try_get_module(const struct btf *btf) | ||||||
| 	return res; | 	return res; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| /* Returns struct btf corresponding to the struct module
 | /* Returns struct btf corresponding to the struct module.
 | ||||||
|  * |  * This function can return NULL or ERR_PTR. | ||||||
|  * This function can return NULL or ERR_PTR. Note that caller must |  | ||||||
|  * release reference for struct btf iff btf_is_module is true. |  | ||||||
|  */ |  */ | ||||||
| static struct btf *btf_get_module_btf(const struct module *module) | static struct btf *btf_get_module_btf(const struct module *module) | ||||||
| { | { | ||||||
| 	struct btf *btf = NULL; |  | ||||||
| #ifdef CONFIG_DEBUG_INFO_BTF_MODULES | #ifdef CONFIG_DEBUG_INFO_BTF_MODULES | ||||||
| 	struct btf_module *btf_mod, *tmp; | 	struct btf_module *btf_mod, *tmp; | ||||||
| #endif | #endif | ||||||
|  | 	struct btf *btf = NULL; | ||||||
|  | 
 | ||||||
|  | 	if (!module) { | ||||||
|  | 		btf = bpf_get_btf_vmlinux(); | ||||||
|  | 		if (!IS_ERR(btf)) | ||||||
|  | 			btf_get(btf); | ||||||
|  | 		return btf; | ||||||
|  | 	} | ||||||
| 
 | 
 | ||||||
| 	if (!module) |  | ||||||
| 		return bpf_get_btf_vmlinux(); |  | ||||||
| #ifdef CONFIG_DEBUG_INFO_BTF_MODULES | #ifdef CONFIG_DEBUG_INFO_BTF_MODULES | ||||||
| 	mutex_lock(&btf_module_mutex); | 	mutex_lock(&btf_module_mutex); | ||||||
| 	list_for_each_entry_safe(btf_mod, tmp, &btf_modules, list) { | 	list_for_each_entry_safe(btf_mod, tmp, &btf_modules, list) { | ||||||
|  | @ -6823,9 +6826,7 @@ int register_btf_kfunc_id_set(enum bpf_prog_type prog_type, | ||||||
| 
 | 
 | ||||||
| 	hook = bpf_prog_type_to_kfunc_hook(prog_type); | 	hook = bpf_prog_type_to_kfunc_hook(prog_type); | ||||||
| 	ret = btf_populate_kfunc_set(btf, hook, kset); | 	ret = btf_populate_kfunc_set(btf, hook, kset); | ||||||
| 	/* reference is only taken for module BTF */ | 	btf_put(btf); | ||||||
| 	if (btf_is_module(btf)) |  | ||||||
| 		btf_put(btf); |  | ||||||
| 	return ret; | 	return ret; | ||||||
| } | } | ||||||
| EXPORT_SYMBOL_GPL(register_btf_kfunc_id_set); | EXPORT_SYMBOL_GPL(register_btf_kfunc_id_set); | ||||||
|  |  | ||||||
		Loading…
	
		Reference in a new issue
	
	 Kumar Kartikeya Dwivedi
						Kumar Kartikeya Dwivedi