Commit f49a8537 authored by Gabriel Krisman Bertazi's avatar Gabriel Krisman Bertazi Committed by Jens Axboe
Browse files

io_uring/net: Allocate msghdr async data through helper

parent e9447dc0
Loading
Loading
Loading
Loading
+18 −17
Original line number Diff line number Diff line
@@ -155,32 +155,33 @@ static void io_netmsg_recycle(struct io_kiocb *req, unsigned int issue_flags)
	}
}

static void io_msg_async_data_init(void *obj)
{
	struct io_async_msghdr *hdr = (struct io_async_msghdr *)obj;

	hdr->free_iov = NULL;
	hdr->free_iov_nr = 0;
}

static struct io_async_msghdr *io_msg_alloc_async(struct io_kiocb *req)
{
	struct io_ring_ctx *ctx = req->ctx;
	struct io_async_msghdr *hdr;

	hdr = io_alloc_cache_get(&ctx->netmsg_cache);
	if (hdr) {
	hdr = io_uring_alloc_async_data(&ctx->netmsg_cache, req,
					io_msg_async_data_init);
	if (!hdr)
		return NULL;

	/* If the async data was cached, we might have an iov cached inside. */
	if (hdr->free_iov) {
		kasan_mempool_unpoison_object(hdr->free_iov,
					      hdr->free_iov_nr * sizeof(struct iovec));
		req->flags |= REQ_F_NEED_CLEANUP;
	}
		req->flags |= REQ_F_ASYNC_DATA;
		req->async_data = hdr;
	return hdr;
}

	if (!io_alloc_async_data(req)) {
		hdr = req->async_data;
		hdr->free_iov_nr = 0;
		hdr->free_iov = NULL;
		return hdr;
	}
	return NULL;
}

/* assign new iovec to kmsg, if we need to */
static int io_net_vec_assign(struct io_kiocb *req, struct io_async_msghdr *kmsg,
			     struct iovec *iov)