firmware: Fix bug in error checking