[dpdk-dev,v1,09/15] malloc: fix the issue of SOCKET_ID_ANY

Message ID 1421914598-2747-10-git-send-email-cunming.liang@intel.com (mailing list archive)
State Superseded, archived
Headers

Commit Message

Cunming Liang Jan. 22, 2015, 8:16 a.m. UTC
  Add check for rte_socket_id(), avoid get unexpected return like (-1).

Signed-off-by: Cunming Liang <cunming.liang@intel.com>
---
 lib/librte_malloc/malloc_heap.h | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
  

Comments

Stephen Hemminger Jan. 25, 2015, 11:04 p.m. UTC | #1
On Thu, 22 Jan 2015 16:16:32 +0800
Cunming Liang <cunming.liang@intel.com> wrote:

> -	return rte_socket_id();
> +	unsigned socket_id = rte_socket_id();
> +
> +	if (socket_id == (unsigned)SOCKET_ID_ANY)

I prefer not casting -1 to unsigned it will cause warnings.
It is better to make socket_id an integer and then have
the implicit cast in the return.
  
Stephen Hemminger Jan. 26, 2015, 1:48 p.m. UTC | #2
On Thu, 22 Jan 2015 16:16:32 +0800
Cunming Liang <cunming.liang@intel.com> wrote:

> -	return rte_socket_id();
> +	unsigned socket_id = rte_socket_id();
> +
> +	if (socket_id == (unsigned)SOCKET_ID_ANY)

I prefer not casting -1 to unsigned it will cause warnings.
It is better to make socket_id an integer and then have
the implicit cast in the return
  
Cunming Liang Jan. 27, 2015, 4:55 a.m. UTC | #3
> -----Original Message-----
> From: Stephen Hemminger [mailto:stephen@networkplumber.org]
> Sent: Sunday, January 25, 2015 4:05 PM
> To: Liang, Cunming
> Cc: dev@dpdk.org
> Subject: Re: [dpdk-dev] [PATCH v1 09/15] malloc: fix the issue of SOCKET_ID_ANY
> 
> On Thu, 22 Jan 2015 16:16:32 +0800
> Cunming Liang <cunming.liang@intel.com> wrote:
> 
> > -	return rte_socket_id();
> > +	unsigned socket_id = rte_socket_id();
> > +
> > +	if (socket_id == (unsigned)SOCKET_ID_ANY)
> 
> I prefer not casting -1 to unsigned it will cause warnings.
> It is better to make socket_id an integer and then have
> the implicit cast in the return.
[Liang, Cunming] I didn't got warning about it, in which version of compiler complain it ?
  

Patch

diff --git a/lib/librte_malloc/malloc_heap.h b/lib/librte_malloc/malloc_heap.h
index b4aec45..a47136d 100644
--- a/lib/librte_malloc/malloc_heap.h
+++ b/lib/librte_malloc/malloc_heap.h
@@ -44,7 +44,12 @@  extern "C" {
 static inline unsigned
 malloc_get_numa_socket(void)
 {
-	return rte_socket_id();
+	unsigned socket_id = rte_socket_id();
+
+	if (socket_id == (unsigned)SOCKET_ID_ANY)
+		return 0;
+
+	return socket_id;
 }
 
 void *