From: Xin Wang <[email protected]>
To: [email protected]
Cc: [email protected], [email protected],
[email protected], Xin Wang <[email protected]>,
Xin Wang <[email protected]>
Subject: [PATCH] io_uring: extract the function that checks the legitimacy of sq/cq entries
Date: Wed, 13 Mar 2024 03:44:46 +0800 [thread overview]
Message-ID: <[email protected]> (raw)
In the io_uring_create function, the sq_entries and cq_entries passed
in by the user are examined. The checking logic is the same for both, so
the common code can be extracted for reuse.
Extract the common code as io_validate_entries function.
Signed-off-by: Xin Wang <[email protected]>
---
io_uring/io_uring.c | 26 ++++++++++++++------------
1 file changed, 14 insertions(+), 12 deletions(-)
diff --git a/io_uring/io_uring.c b/io_uring/io_uring.c
index cd9a137ad6ce..c51100f39cbf 100644
--- a/io_uring/io_uring.c
+++ b/io_uring/io_uring.c
@@ -3819,6 +3819,18 @@ static struct file *io_uring_get_file(struct io_ring_ctx *ctx)
O_RDWR | O_CLOEXEC, NULL);
}
+static bool io_validate_entries(unsigned int *entries, unsigned int max_entries, __u32 flags)
+{
+ if (!(*entries))
+ return false;
+ if (*entries > max_entries) {
+ if (!(flags & IORING_SETUP_CLAMP))
+ return false;
+ *entries = max_entries;
+ }
+ return true;
+}
+
static __cold int io_uring_create(unsigned entries, struct io_uring_params *p,
struct io_uring_params __user *params)
{
@@ -3827,13 +3839,8 @@ static __cold int io_uring_create(unsigned entries, struct io_uring_params *p,
struct file *file;
int ret;
- if (!entries)
+ if (!io_validate_entries(&entries, IORING_MAX_ENTRIES, p->flags))
return -EINVAL;
- if (entries > IORING_MAX_ENTRIES) {
- if (!(p->flags & IORING_SETUP_CLAMP))
- return -EINVAL;
- entries = IORING_MAX_ENTRIES;
- }
if ((p->flags & IORING_SETUP_REGISTERED_FD_ONLY)
&& !(p->flags & IORING_SETUP_NO_MMAP))
@@ -3854,13 +3861,8 @@ static __cold int io_uring_create(unsigned entries, struct io_uring_params *p,
* to a power-of-two, if it isn't already. We do NOT impose
* any cq vs sq ring sizing.
*/
- if (!p->cq_entries)
+ if (!io_validate_entries(&(p->cq_entries), IORING_MAX_CQ_ENTRIES, p->flags))
return -EINVAL;
- if (p->cq_entries > IORING_MAX_CQ_ENTRIES) {
- if (!(p->flags & IORING_SETUP_CLAMP))
- return -EINVAL;
- p->cq_entries = IORING_MAX_CQ_ENTRIES;
- }
p->cq_entries = roundup_pow_of_two(p->cq_entries);
if (p->cq_entries < p->sq_entries)
return -EINVAL;
--
2.25.1
next reply other threads:[~2024-03-12 19:45 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-03-12 19:44 Xin Wang [this message]
2024-03-14 19:29 ` [PATCH] io_uring: extract the function that checks the legitimacy of sq/cq entries Jens Axboe
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
[email protected] \
[email protected] \
[email protected] \
[email protected] \
[email protected] \
[email protected] \
[email protected] \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox