public inbox for [email protected]
 help / color / mirror / Atom feed
* [PATCH v2 0/1] io_uring: extract the function that checks the legitimacy of sq/cq entries
@ 2024-03-14 21:21 Xin Wang
  2024-03-14 21:21 ` [PATCH v2 1/1] " Xin Wang
  0 siblings, 1 reply; 2+ messages in thread
From: Xin Wang @ 2024-03-14 21:21 UTC (permalink / raw)
  To: axboe; +Cc: asml.silence, io-uring, linux-kernel, Xin Wang


Xin Wang (1):
  It was really careless of me, earlier I wanted to keep the coding style
  as close as possible to the rest of the code, so I looked for similar
  code, e.g., line 4713 of kernel/trace/ring_buffer.c: if (ts && ! (*ts))
  and line 1178 of ipc/shm.c: audit_ipc_obj(&(shp->shm_perm)). Now I removed
  the brackets and it passes the checkpatch.pl script, thanks!

--
2.25.1

^ permalink raw reply	[flat|nested] 2+ messages in thread

* [PATCH v2 1/1] io_uring: extract the function that checks the legitimacy of sq/cq entries
  2024-03-14 21:21 [PATCH v2 0/1] io_uring: extract the function that checks the legitimacy of sq/cq entries Xin Wang
@ 2024-03-14 21:21 ` Xin Wang
  0 siblings, 0 replies; 2+ messages in thread
From: Xin Wang @ 2024-03-14 21:21 UTC (permalink / raw)
  To: axboe; +Cc: asml.silence, io-uring, linux-kernel, Xin Wang, Xin Wang

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.

Changes:
V1->V2::
  - Replace function name 'io_validate_entries' with 'io_validate_ring_entries'
    to enhance readability.
  - Removed unnecessary parentheses.
  - Line Wrapping.

====================

Signed-off-by: Xin Wang <[email protected]>
---
 io_uring/io_uring.c | 27 +++++++++++++++------------
 1 file changed, 15 insertions(+), 12 deletions(-)

diff --git a/io_uring/io_uring.c b/io_uring/io_uring.c
index cd9a137ad6ce..4c3580229283 100644
--- a/io_uring/io_uring.c
+++ b/io_uring/io_uring.c
@@ -3819,6 +3819,19 @@ static struct file *io_uring_get_file(struct io_ring_ctx *ctx)
 					 O_RDWR | O_CLOEXEC, NULL);
 }
 
+static bool io_validate_ring_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 +3840,8 @@ static __cold int io_uring_create(unsigned entries, struct io_uring_params *p,
 	struct file *file;
 	int ret;
 
-	if (!entries)
+	if (!io_validate_ring_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 +3862,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_ring_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


^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2024-03-14 21:21 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-03-14 21:21 [PATCH v2 0/1] io_uring: extract the function that checks the legitimacy of sq/cq entries Xin Wang
2024-03-14 21:21 ` [PATCH v2 1/1] " Xin Wang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox