Changeset View
Changeset View
Standalone View
Standalone View
sys/fs/tmpfs/tmpfs_subr.c
Show First 20 Lines • Show All 169 Lines • ▼ Show 20 Lines | |||||
static __inline int tmpfs_dirtree_cmp(struct tmpfs_dirent *a, | static __inline int tmpfs_dirtree_cmp(struct tmpfs_dirent *a, | ||||
struct tmpfs_dirent *b); | struct tmpfs_dirent *b); | ||||
RB_PROTOTYPE_STATIC(tmpfs_dir, tmpfs_dirent, uh.td_entries, tmpfs_dirtree_cmp); | RB_PROTOTYPE_STATIC(tmpfs_dir, tmpfs_dirent, uh.td_entries, tmpfs_dirtree_cmp); | ||||
size_t | size_t | ||||
tmpfs_mem_avail(void) | tmpfs_mem_avail(void) | ||||
{ | { | ||||
vm_ooffset_t avail; | long avail; | ||||
kib: I think this should be size_t, and before subtraction, the check should be made to return 0. | |||||
avail = swap_pager_avail + vm_free_count() - tmpfs_pages_reserved; | avail = swap_pager_avail + vm_free_count() - tmpfs_pages_reserved; | ||||
if (__predict_false(avail < 0)) | if (__predict_false(avail < 0)) | ||||
avail = 0; | avail = 0; | ||||
return (avail); | return (avail); | ||||
} | } | ||||
size_t | size_t | ||||
Not Done Inline ActionsYou perform two reads of tmpfs_pages_reserved. If user changes the sysctl meanime, you might get overflow on the second calculation. kib: You perform two reads of tmpfs_pages_reserved. If user changes the sysctl meanime, you might… | |||||
Not Done Inline ActionsTo make this pedantically correct I believe you have to use atomic_load_long(&tmpfs_pages_reserved). There is nothing preventing the compiler from loading tmpfs_pages_reserved twice. markj: To make this pedantically correct I believe you have to use atomic_load_long… | |||||
tmpfs_pages_used(struct tmpfs_mount *tmp) | tmpfs_pages_used(struct tmpfs_mount *tmp) | ||||
{ | { | ||||
const size_t node_size = sizeof(struct tmpfs_node) + | const size_t node_size = sizeof(struct tmpfs_node) + | ||||
sizeof(struct tmpfs_dirent); | sizeof(struct tmpfs_dirent); | ||||
size_t meta_pages; | size_t meta_pages; | ||||
meta_pages = howmany((uintmax_t)tmp->tm_nodes_inuse * node_size, | meta_pages = howmany((uintmax_t)tmp->tm_nodes_inuse * node_size, | ||||
PAGE_SIZE); | PAGE_SIZE); | ||||
▲ Show 20 Lines • Show All 1,744 Lines • Show Last 20 Lines |
I think this should be size_t, and before subtraction, the check should be made to return 0.