Skip to content

Commit cd536db

Browse files
committed
dma-buf: Proactively round up to kmalloc bucket size
Instead of discovering the kmalloc bucket size _after_ allocation, round up proactively so the allocation is explicitly made for the full size, allowing the compiler to correctly reason about the resulting size of the buffer through the existing __alloc_size() hint. Cc: Sumit Semwal <[email protected]> Cc: [email protected] Cc: [email protected] Cc: [email protected] Reviewed-by: Christian König <[email protected]> Signed-off-by: Kees Cook <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent e1789d7 commit cd536db

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

drivers/dma-buf/dma-resv.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,12 +98,17 @@ static void dma_resv_list_set(struct dma_resv_list *list,
9898
static struct dma_resv_list *dma_resv_list_alloc(unsigned int max_fences)
9999
{
100100
struct dma_resv_list *list;
101+
size_t size;
101102

102-
list = kmalloc(struct_size(list, table, max_fences), GFP_KERNEL);
103+
/* Round up to the next kmalloc bucket size. */
104+
size = kmalloc_size_roundup(struct_size(list, table, max_fences));
105+
106+
list = kmalloc(size, GFP_KERNEL);
103107
if (!list)
104108
return NULL;
105109

106-
list->max_fences = (ksize(list) - offsetof(typeof(*list), table)) /
110+
/* Given the resulting bucket size, recalculated max_fences. */
111+
list->max_fences = (size - offsetof(typeof(*list), table)) /
107112
sizeof(*list->table);
108113

109114
return list;

0 commit comments

Comments
 (0)