drm/amd/display: Implement bounds check for stream encoder creation in DCN301
[platform/kernel/linux-rpi.git] / io_uring / io_uring.c
index b406cc6..ea772a0 100644 (file)
@@ -1339,7 +1339,7 @@ static inline void io_req_local_work_add(struct io_kiocb *req, unsigned flags)
                nr_tw = nr_tw_prev + 1;
                /* Large enough to fail the nr_wait comparison below */
                if (!(flags & IOU_F_TWQ_LAZY_WAKE))
-                       nr_tw = -1U;
+                       nr_tw = INT_MAX;
 
                req->nr_tw = nr_tw;
                req->io_task_work.node.next = first;
@@ -2630,8 +2630,6 @@ static int io_cqring_wait(struct io_ring_ctx *ctx, int min_events,
                __set_current_state(TASK_RUNNING);
                atomic_set(&ctx->cq_wait_nr, 0);
 
-               if (ret < 0)
-                       break;
                /*
                 * Run task_work after scheduling and before io_should_wake().
                 * If we got woken because of task_work being processed, run it
@@ -2641,6 +2639,18 @@ static int io_cqring_wait(struct io_ring_ctx *ctx, int min_events,
                if (!llist_empty(&ctx->work_llist))
                        io_run_local_work(ctx);
 
+               /*
+                * Non-local task_work will be run on exit to userspace, but
+                * if we're using DEFER_TASKRUN, then we could have waited
+                * with a timeout for a number of requests. If the timeout
+                * hits, we could have some requests ready to process. Ensure
+                * this break is _after_ we have run task_work, to avoid
+                * deferring running potentially pending requests until the
+                * next time we wait for events.
+                */
+               if (ret < 0)
+                       break;
+
                check_cq = READ_ONCE(ctx->check_cq);
                if (unlikely(check_cq)) {
                        /* let the caller flush overflows, retry */