crypto: caam - Move common error handling code in two functions