Properly close device after opening it to determine type

The prior code was unreachable due to the returns above it.