+ /*
+ * Ignore any non-present pages at the end of the
+ * UPL so that we aren't looking at a upl that
+ * may already have been freed by the preceeding
+ * aborts/completions.
+ */
+ base_index = upl_offset / PAGE_SIZE;
+
+ for (pg_index = (upl_offset + isize) / PAGE_SIZE; pg_index > base_index;) {
+ if (upl_page_present(pl, --pg_index))
+ break;
+ if (pg_index == base_index) {
+ /*
+ * no pages were returned, so release
+ * our hold on the upl and leave
+ */
+ if ( !(flags & UPL_NOCOMMIT))
+ ubc_upl_abort_range(upl, upl_offset, isize, UPL_ABORT_FREE_ON_EMPTY);
+
+ goto out;
+ }
+ }
+ isize = (pg_index + 1) * PAGE_SIZE;
+
+ offset = upl_offset;
+ pg_index = base_index;