device: Fix null pointer derefence if device is unset