@@ -24,28 +24,34 @@ struct objpool {
2424
2525#define OBJPOOL_BITS (sizeof(((struct objpool *)0)->mask) * 8)
2626
27- static int objpool_add (struct list_item * head , unsigned int n , size_t size , uint32_t flags )
27+ static int objpool_add (struct objpool_head * head , unsigned int n , size_t size , uint32_t flags )
2828{
2929 if (n > OBJPOOL_BITS )
3030 return - ENOMEM ;
3131
3232 if (!is_power_of_2 (n ))
3333 return - EINVAL ;
3434
35- size_t aligned_size = ALIGN_UP (size , sizeof (int ));
35+ size_t aligned_size = n * ALIGN_UP (size , sizeof (int ));
3636
37- /* Initialize with 0 to give caller a chance to identify new allocations */
38- struct objpool * pobjpool = rzalloc (flags , n * aligned_size + sizeof (* pobjpool ));
37+ if (!head -> heap )
38+ head -> heap = sof_sys_heap_get ();
39+
40+ struct objpool * pobjpool = sof_heap_alloc (head -> heap , flags ,
41+ aligned_size + sizeof (* pobjpool ), 0 );
3942
4043 if (!pobjpool )
4144 return - ENOMEM ;
4245
46+ /* Initialize with 0 to give caller a chance to identify new allocations */
47+ memset (pobjpool -> data , 0 , aligned_size );
48+
4349 pobjpool -> n = n ;
4450 /* clear bit means free */
4551 pobjpool -> mask = 0 ;
4652 pobjpool -> size = size ;
4753
48- list_item_append (& pobjpool -> list , head );
54+ list_item_append (& pobjpool -> list , & head -> list );
4955
5056 return 0 ;
5157}
@@ -99,7 +105,7 @@ void *objpool_alloc(struct objpool_head *head, size_t size, uint32_t flags)
99105 new_n = pobjpool -> n << 1 ;
100106 }
101107
102- if (objpool_add (& head -> list , new_n , size , flags ) < 0 )
108+ if (objpool_add (head , new_n , size , flags ) < 0 )
103109 return NULL ;
104110
105111 /* Return the first element of the new objpool, which is now the last one in the list */
0 commit comments