Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge branch 'two-tiny-fixes-for-btf-record'

Hou Tao says:

====================
The tiny patch set aims to fix two problems found during the development
of supporting dynptr key in hash table. Patch #1 fixes the missed
btf_record_free() when map creation fails and patch #2 fixes the missed
kfree() when there is no special field in the passed btf.
====================

Link: https://lore.kernel.org/r/20240912012845.3458483-1-houtao@huaweicloud.com
Signed-off-by: Alexei Starovoitov <ast@kernel.org>

+15 -8
+3 -1
kernel/bpf/btf.c
··· 5572 5572 aof->ids[aof->cnt++] = i; 5573 5573 } 5574 5574 5575 - if (!aof->cnt) 5575 + if (!aof->cnt) { 5576 + kfree(aof); 5576 5577 return NULL; 5578 + } 5577 5579 sort(&aof->ids, aof->cnt, sizeof(aof->ids[0]), btf_id_cmp_func, NULL); 5578 5580 5579 5581 for (i = 1; i < n; i++) {
+12 -7
kernel/bpf/syscall.c
··· 735 735 } 736 736 } 737 737 738 - /* called from workqueue */ 739 - static void bpf_map_free_deferred(struct work_struct *work) 738 + static void bpf_map_free(struct bpf_map *map) 740 739 { 741 - struct bpf_map *map = container_of(work, struct bpf_map, work); 742 740 struct btf_record *rec = map->record; 743 741 struct btf *btf = map->btf; 744 742 745 - security_bpf_map_free(map); 746 - bpf_map_release_memcg(map); 747 743 /* implementation dependent freeing */ 748 744 map->ops->map_free(map); 749 745 /* Delay freeing of btf_record for maps, as map_free ··· 756 760 * struct_meta info which will be freed with btf_put(). 757 761 */ 758 762 btf_put(btf); 763 + } 764 + 765 + /* called from workqueue */ 766 + static void bpf_map_free_deferred(struct work_struct *work) 767 + { 768 + struct bpf_map *map = container_of(work, struct bpf_map, work); 769 + 770 + security_bpf_map_free(map); 771 + bpf_map_release_memcg(map); 772 + bpf_map_free(map); 759 773 } 760 774 761 775 static void bpf_map_put_uref(struct bpf_map *map) ··· 1419 1413 free_map_sec: 1420 1414 security_bpf_map_free(map); 1421 1415 free_map: 1422 - btf_put(map->btf); 1423 - map->ops->map_free(map); 1416 + bpf_map_free(map); 1424 1417 put_token: 1425 1418 bpf_token_put(token); 1426 1419 return err;