[dpdk-dev,v2] mempool: fix local cache initialization

Message ID 1465460387-42065-1-git-send-email-sergio.gonzalez.monroy@intel.com (mailing list archive)
State Accepted, archived
Delegated to: Thomas Monjalon
Headers

Commit Message

Sergio Gonzalez Monroy June 9, 2016, 8:19 a.m. UTC
  The mempool local cache was not initialized properly leading to
undefined behavior in cases where the allocated memory was used
previously and left with data.

Fixes: 213af31e0960 ("mempool: reduce structure size if no cache needed")

Signed-off-by: Sergio Gonzalez Monroy <sergio.gonzalez.monroy@intel.com>
---
 lib/librte_mempool/rte_mempool.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
  

Comments

Olivier Matz June 9, 2016, 8:26 a.m. UTC | #1
On 06/09/2016 10:19 AM, Sergio Gonzalez Monroy wrote:
> The mempool local cache was not initialized properly leading to
> undefined behavior in cases where the allocated memory was used
> previously and left with data.
> 
> Fixes: 213af31e0960 ("mempool: reduce structure size if no cache needed")
> 
> Signed-off-by: Sergio Gonzalez Monroy <sergio.gonzalez.monroy@intel.com>

Acked-by: Olivier Matz <olivier.matz@6wind.com>

Thanks
  
Thomas Monjalon June 15, 2016, 1:59 p.m. UTC | #2
2016-06-09 10:26, Olivier Matz:
> On 06/09/2016 10:19 AM, Sergio Gonzalez Monroy wrote:
> > The mempool local cache was not initialized properly leading to
> > undefined behavior in cases where the allocated memory was used
> > previously and left with data.
> > 
> > Fixes: 213af31e0960 ("mempool: reduce structure size if no cache needed")
> > 
> > Signed-off-by: Sergio Gonzalez Monroy <sergio.gonzalez.monroy@intel.com>
> 
> Acked-by: Olivier Matz <olivier.matz@6wind.com>
> 
> Thanks

Applied, thanks
  

Patch

diff --git a/lib/librte_mempool/rte_mempool.c b/lib/librte_mempool/rte_mempool.c
index b54de43..216514c 100644
--- a/lib/librte_mempool/rte_mempool.c
+++ b/lib/librte_mempool/rte_mempool.c
@@ -787,7 +787,7 @@  rte_mempool_create_empty(const char *name, unsigned n, unsigned elt_size,
 
 	/* init the mempool structure */
 	mp = mz->addr;
-	memset(mp, 0, sizeof(*mp));
+	memset(mp, 0, MEMPOOL_HEADER_SIZE(mp, cache_size));
 	ret = snprintf(mp->name, sizeof(mp->name), "%s", name);
 	if (ret < 0 || ret >= (int)sizeof(mp->name)) {
 		rte_errno = ENAMETOOLONG;