Skip to contentSkip to conversation

io_uring: suppress an unused warning

PATCH In review Vincenzo Palazzo 2 participants 2 messages Mar 9, 2023 io_uring

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 io_uring: suppress an unused warning

suppress unused warnings and fix the error that there is with the W=1 enabled.

Warning generated

io_uring/io_uring.c: In function ‘__io_submit_flush_completions’:
io_uring/io_uring.c:1502:40: error: variable ‘prev’ set but not used [-Werror=unused-but-set-variable]
1502 | struct io_wq_work_node *node, *prev;

---
 io_uring/io_uring.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
io_uring/io_uring.c +1 -1
index fd1cc35a1c00..bd38e45522da 100644
@@ -1499,7 +1499,7 @@ void io_free_batch_list(struct io_ring_ctx *ctx, struct io_wq_work_node *node)
 static void __io_submit_flush_completions(struct io_ring_ctx *ctx)
 	__must_hold(&ctx->uring_lock)
 {
-	struct io_wq_work_node *node, *prev;
+	struct io_wq_work_node *node, *prev __maybe_unused;
 	struct io_submit_state *state = &ctx->submit_state;
 
 	__io_cq_lock(ctx);
Signature · 1 line
2.39.2
maintainer
#1 lore raw
Quoted 8 lines · Vincenzo Palazzo

suppress unused warnings and fix the error that there is with the W=1 enabled.

Warning generated

io_uring/io_uring.c: In function ?__io_submit_flush_completions?:
io_uring/io_uring.c:1502:40: error: variable ?prev? set but not used [-Werror=unused-but-set-variable]
1502 | struct io_wq_work_node *node, *prev;

I think it'd be cleaner to just add an iterator that doesn't track 'prev' if we don't actually need it. Ala:

io_uring/io_uring.c +2 -2
index fd1cc35a1c00..722624b6d0dc 100644
@@ -1499,14 +1499,14 @@ void io_free_batch_list(struct io_ring_ctx *ctx, struct io_wq_work_node *node)
 static void __io_submit_flush_completions(struct io_ring_ctx *ctx)
 	__must_hold(&ctx->uring_lock)
 {
-	struct io_wq_work_node *node, *prev;
 	struct io_submit_state *state = &ctx->submit_state;
+	struct io_wq_work_node *node;
 
 	__io_cq_lock(ctx);
 	/* must come first to preserve CQE ordering in failure cases */
 	if (state->cqes_count)
 		__io_flush_post_cqes(ctx);
-	wq_list_for_each(node, prev, &state->compl_reqs) {
+	__wq_list_for_each(node, &state->compl_reqs) {
 		struct io_kiocb *req = container_of(node, struct io_kiocb,
 					    comp_list);
 
io_uring/slist.h +4 -1
index 7c198a40d5f1..0eb194817242 100644
@@ -3,6 +3,9 @@
 
 #include <linux/io_uring_types.h>
 
+#define __wq_list_for_each(pos, head)				\
+	for (pos = (head)->first; pos; pos = (pos)->next)
+
 #define wq_list_for_each(pos, prv, head)			\
 	for (pos = (head)->first, prv = NULL; pos; prv = pos, pos = (pos)->next)
 
@@ -113,4 +116,4 @@ static inline struct io_wq_work *wq_next_work(struct io_wq_work *work)
 	return container_of(work->list.next, struct io_wq_work, list);
 }
 
-#endif // INTERNAL_IO_SLIST_H
\ No newline at end of file
+#endif // INTERNAL_IO_SLIST_H
Signature · 1 line
Jens Axboe