@@ -438,6 +438,22 @@ static struct io_ring_ctx *io_ring_ctx_a
return ctx;
}
+static void io_req_put_fs(struct io_kiocb *req)
+{
+ struct fs_struct *fs = req->fs;
+
+ if (!fs)
+ return;
+
+ spin_lock(&req->fs->lock);
+ if (--fs->users)
+ fs = NULL;
+ spin_unlock(&req->fs->lock);
+ if (fs)
+ free_fs_struct(fs);
+ req->fs = NULL;
+}
+
static inline bool __io_sequence_defer(struct io_ring_ctx *ctx,
struct io_kiocb *req)
{
@@ -695,6 +711,7 @@ static void io_free_req_many(struct io_r
static void __io_free_req(struct io_kiocb *req)
{
+ io_req_put_fs(req);
if (req->file && !(req->flags & REQ_F_FIXED_FILE))
fput(req->file);
percpu_ref_put(&req->ctx->refs);
@@ -1701,16 +1718,7 @@ static int io_send_recvmsg(struct io_kio
ret = -EINTR;
}
- if (req->fs) {
- struct fs_struct *fs = req->fs;
-
- spin_lock(&req->fs->lock);
- if (--fs->users)
- fs = NULL;
- spin_unlock(&req->fs->lock);
- if (fs)
- free_fs_struct(fs);
- }
+ io_req_put_fs(req);
io_cqring_add_event(req->ctx, sqe->user_data, ret);
io_put_req(req);
return 0;