device: do the right casting