Fix the coverity issues

This PR is to resolve issues raised by coverity.

BUG=XWALK-2928
While this is correct, a more future-proof approach is to invert the check: if it fails, return, otherwise you carry on. This way even if someone in the future adds more code to the function after this section it will still fail early on error.