This gets repeated in the else branch (more or less). IMHO it would be easier to put the "if (dev == null)" check at the top, and just set "dev" to what the .ioctl header specifies, and then use the original code for both cases.