[dpdk-dev,08/41] eal: make malloc free return resulting malloc element

Message ID 757ab0a9ebe0e921c2ab77562cb0333da8334c50.1520083504.git.anatoly.burakov@intel.com (mailing list archive)
State Superseded, archived
Headers

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel-compilation fail apply patch file failure

Commit Message

Anatoly Burakov March 3, 2018, 1:45 p.m. UTC
  Signed-off-by: Anatoly Burakov <anatoly.burakov@intel.com>
---
 lib/librte_eal/common/malloc_elem.c | 4 ++--
 lib/librte_eal/common/malloc_elem.h | 2 +-
 lib/librte_eal/common/malloc_heap.c | 4 ++--
 3 files changed, 5 insertions(+), 5 deletions(-)
  

Comments

Olivier Matz March 19, 2018, 5:34 p.m. UTC | #1
On Sat, Mar 03, 2018 at 01:45:56PM +0000, Anatoly Burakov wrote:
> Signed-off-by: Anatoly Burakov <anatoly.burakov@intel.com>
> ---
>  lib/librte_eal/common/malloc_elem.c | 4 ++--
>  lib/librte_eal/common/malloc_elem.h | 2 +-
>  lib/librte_eal/common/malloc_heap.c | 4 ++--
>  3 files changed, 5 insertions(+), 5 deletions(-)
> 
> diff --git a/lib/librte_eal/common/malloc_elem.c b/lib/librte_eal/common/malloc_elem.c
> index 008f5a3..c18f050 100644
> --- a/lib/librte_eal/common/malloc_elem.c
> +++ b/lib/librte_eal/common/malloc_elem.c
> @@ -379,7 +379,7 @@ malloc_elem_join_adjacent_free(struct malloc_elem *elem)
>   * blocks either immediately before or immediately after newly freed block
>   * are also free, the blocks are merged together.
>   */
> -int
> +struct malloc_elem *
>  malloc_elem_free(struct malloc_elem *elem)
>  {
>  	void *ptr;
> @@ -397,7 +397,7 @@ malloc_elem_free(struct malloc_elem *elem)
>  
>  	memset(ptr, 0, data_len);
>  
> -	return 0;
> +	return elem;
>  }
>  
>  /*

An explanation about why this change is needed would make sense I think.

Thanks,
Olivier
  
Anatoly Burakov March 20, 2018, 9:40 a.m. UTC | #2
On 19-Mar-18 5:34 PM, Olivier Matz wrote:
> On Sat, Mar 03, 2018 at 01:45:56PM +0000, Anatoly Burakov wrote:
>> Signed-off-by: Anatoly Burakov <anatoly.burakov@intel.com>
>> ---
>>   lib/librte_eal/common/malloc_elem.c | 4 ++--
>>   lib/librte_eal/common/malloc_elem.h | 2 +-
>>   lib/librte_eal/common/malloc_heap.c | 4 ++--
>>   3 files changed, 5 insertions(+), 5 deletions(-)
>>
>> diff --git a/lib/librte_eal/common/malloc_elem.c b/lib/librte_eal/common/malloc_elem.c
>> index 008f5a3..c18f050 100644
>> --- a/lib/librte_eal/common/malloc_elem.c
>> +++ b/lib/librte_eal/common/malloc_elem.c
>> @@ -379,7 +379,7 @@ malloc_elem_join_adjacent_free(struct malloc_elem *elem)
>>    * blocks either immediately before or immediately after newly freed block
>>    * are also free, the blocks are merged together.
>>    */
>> -int
>> +struct malloc_elem *
>>   malloc_elem_free(struct malloc_elem *elem)
>>   {
>>   	void *ptr;
>> @@ -397,7 +397,7 @@ malloc_elem_free(struct malloc_elem *elem)
>>   
>>   	memset(ptr, 0, data_len);
>>   
>> -	return 0;
>> +	return elem;
>>   }
>>   
>>   /*
> 
> An explanation about why this change is needed would make sense I think.
> 
> Thanks,
> Olivier
> 

Sure, i'll add this in future commits.

However, to provide some context - we need this because down the line we 
will need to know which element did we create/free to be able to roll 
back the changes, should the sync fail.
  

Patch

diff --git a/lib/librte_eal/common/malloc_elem.c b/lib/librte_eal/common/malloc_elem.c
index 008f5a3..c18f050 100644
--- a/lib/librte_eal/common/malloc_elem.c
+++ b/lib/librte_eal/common/malloc_elem.c
@@ -379,7 +379,7 @@  malloc_elem_join_adjacent_free(struct malloc_elem *elem)
  * blocks either immediately before or immediately after newly freed block
  * are also free, the blocks are merged together.
  */
-int
+struct malloc_elem *
 malloc_elem_free(struct malloc_elem *elem)
 {
 	void *ptr;
@@ -397,7 +397,7 @@  malloc_elem_free(struct malloc_elem *elem)
 
 	memset(ptr, 0, data_len);
 
-	return 0;
+	return elem;
 }
 
 /*
diff --git a/lib/librte_eal/common/malloc_elem.h b/lib/librte_eal/common/malloc_elem.h
index 46e2383..9c1614c 100644
--- a/lib/librte_eal/common/malloc_elem.h
+++ b/lib/librte_eal/common/malloc_elem.h
@@ -138,7 +138,7 @@  malloc_elem_alloc(struct malloc_elem *elem, size_t size,
  * blocks either immediately before or immediately after newly freed block
  * are also free, the blocks are merged together.
  */
-int
+struct malloc_elem *
 malloc_elem_free(struct malloc_elem *elem);
 
 struct malloc_elem *
diff --git a/lib/librte_eal/common/malloc_heap.c b/lib/librte_eal/common/malloc_heap.c
index 44538d7..a2c2e4c 100644
--- a/lib/librte_eal/common/malloc_heap.c
+++ b/lib/librte_eal/common/malloc_heap.c
@@ -145,7 +145,7 @@  int
 malloc_heap_free(struct malloc_elem *elem)
 {
 	struct malloc_heap *heap;
-	int ret;
+	struct malloc_elem *ret;
 
 	if (!malloc_elem_cookies_ok(elem) || elem->state != ELEM_BUSY)
 		return -1;
@@ -159,7 +159,7 @@  malloc_heap_free(struct malloc_elem *elem)
 
 	rte_spinlock_unlock(&(heap->lock));
 
-	return ret;
+	return ret != NULL ? 0 : -1;
 }
 
 int