[PATCH] Task: optimize get_device() function