if (id >= node2id(hdl->ctrl_refs.prev)) {
                        ref = NULL; /* Yes, so there is no next control */
                } else if (ref) {
+                       struct v4l2_ctrl_ref *pos = ref;
+
                        /*
                         * We found a control with the given ID, so just get
                         * the next valid one in the list.
                         */
-                       list_for_each_entry_continue(ref, &hdl->ctrl_refs, node) {
-                               is_compound = ref->ctrl->is_array ||
-                                       ref->ctrl->type >= V4L2_CTRL_COMPOUND_TYPES;
-                               if (id < ref->ctrl->id &&
-                                   (is_compound & mask) == match)
+                       ref = NULL;
+                       list_for_each_entry_continue(pos, &hdl->ctrl_refs, node) {
+                               is_compound = pos->ctrl->is_array ||
+                                       pos->ctrl->type >= V4L2_CTRL_COMPOUND_TYPES;
+                               if (id < pos->ctrl->id &&
+                                   (is_compound & mask) == match) {
+                                       ref = pos;
                                        break;
+                               }
                        }
-                       if (&ref->node == &hdl->ctrl_refs)
-                               ref = NULL;
                } else {
+                       struct v4l2_ctrl_ref *pos;
+
                        /*
                         * No control with the given ID exists, so start
                         * searching for the next largest ID. We know there
                         * is one, otherwise the first 'if' above would have
                         * been true.
                         */
-                       list_for_each_entry(ref, &hdl->ctrl_refs, node) {
-                               is_compound = ref->ctrl->is_array ||
-                                       ref->ctrl->type >= V4L2_CTRL_COMPOUND_TYPES;
-                               if (id < ref->ctrl->id &&
-                                   (is_compound & mask) == match)
+                       list_for_each_entry(pos, &hdl->ctrl_refs, node) {
+                               is_compound = pos->ctrl->is_array ||
+                                       pos->ctrl->type >= V4L2_CTRL_COMPOUND_TYPES;
+                               if (id < pos->ctrl->id &&
+                                   (is_compound & mask) == match) {
+                                       ref = pos;
                                        break;
+                               }
                        }
-                       if (&ref->node == &hdl->ctrl_refs)
-                               ref = NULL;
                }
        }
        mutex_unlock(hdl->lock);