Fix lock ordering in devicestate