On 10/11/2017 11:59 AM, Bruce Richardson wrote:
When compiling with clang extra warning flags, such as used by default with
meson, a warning is given in iotlb.c:

../lib/librte_vhost/iotlb.c:318:6: warning: variable 'socket' is used 
uninitialized whenever 'if' condition is false [-Wsometimes-uninitialized]

This is a false positive, as the socket value will be initialized by the
call to get_mempolicy in the case where the NUMA build-time flag is set,
and in cases where it is not set, "if (ret)" will always be true as ret is
initialized to -1 and never changed.

However, this is not immediately obvious, and is perhaps a little fragile,
as it will break if other code using ret is subsequently added above the
call to get_mempolicy by someone unaware of this subtle dependency.
Therefore, we can fix the warning and making the code more robust by
explicitly initializing socket to zero, and moving the extra condition
check on ret into the #ifdef alongside the call to get_mempolicy which sets
ret.

Fixes: d012d1f293f4 ("vhost: add IOTLB helper functions")

CC: Maxime Coquelin <maxime.coque...@redhat.com>
Signed-off-by: Bruce Richardson <bruce.richard...@intel.com>
---
  lib/librte_vhost/iotlb.c | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)


I agree this is a bit fragile. Thanks for handling this:
Reviewed-by: Maxime Coquelin <maxime.coque...@redhat.com>

Thanks,
Maxime

Reply via email to