lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite for Android: free password hash cracker in your pocket
[<prev] [next>] [day] [month] [year] [list]
Message-Id: <1609932056-26990-1-git-send-email-brookxu@tencent.com>
Date:   Wed,  6 Jan 2021 19:20:56 +0800
From:   Chunguang Xu <brookxu.cn@...il.com>
To:     axboe@...nel.dk
Cc:     linux-block@...r.kernel.org, linux-kernel@...r.kernel.org
Subject: [PATCH] block: introduce for_each_rq_qos macro

From: Chunguang Xu <brookxu@...cent.com>

Compared to direct pointer traversal, introducing a macro
will make the code more concise. But the introduction of
macros will make rq_qos_xxx() produce a redundant judgment,
usually this may not be a big problem.

Signed-off-by: Chunguang Xu <brookxu@...cent.com>
---
 block/blk-rq-qos.c | 45 ++++++++++++++++++---------------------------
 block/blk-rq-qos.h | 11 +++++++++--
 2 files changed, 27 insertions(+), 29 deletions(-)

diff --git a/block/blk-rq-qos.c b/block/blk-rq-qos.c
index 6564606..2c21a49 100644
--- a/block/blk-rq-qos.c
+++ b/block/blk-rq-qos.c
@@ -31,83 +31,74 @@ bool rq_wait_inc_below(struct rq_wait *rq_wait, unsigned int limit)
 
 void __rq_qos_cleanup(struct rq_qos *rqos, struct bio *bio)
 {
-	do {
+	for_each_rq_qos(rqos) {
 		if (rqos->ops->cleanup)
 			rqos->ops->cleanup(rqos, bio);
-		rqos = rqos->next;
-	} while (rqos);
+	}
 }
 
 void __rq_qos_done(struct rq_qos *rqos, struct request *rq)
 {
-	do {
+	for_each_rq_qos(rqos) {
 		if (rqos->ops->done)
 			rqos->ops->done(rqos, rq);
-		rqos = rqos->next;
-	} while (rqos);
+	}
 }
 
 void __rq_qos_issue(struct rq_qos *rqos, struct request *rq)
 {
-	do {
+	for_each_rq_qos(rqos) {
 		if (rqos->ops->issue)
 			rqos->ops->issue(rqos, rq);
-		rqos = rqos->next;
-	} while (rqos);
+	}
 }
 
 void __rq_qos_requeue(struct rq_qos *rqos, struct request *rq)
 {
-	do {
+	for_each_rq_qos(rqos) {
 		if (rqos->ops->requeue)
 			rqos->ops->requeue(rqos, rq);
-		rqos = rqos->next;
-	} while (rqos);
+	}
 }
 
 void __rq_qos_throttle(struct rq_qos *rqos, struct bio *bio)
 {
-	do {
+	for_each_rq_qos(rqos) {
 		if (rqos->ops->throttle)
 			rqos->ops->throttle(rqos, bio);
-		rqos = rqos->next;
-	} while (rqos);
+	}
 }
 
 void __rq_qos_track(struct rq_qos *rqos, struct request *rq, struct bio *bio)
 {
-	do {
+	for_each_rq_qos(rqos) {
 		if (rqos->ops->track)
 			rqos->ops->track(rqos, rq, bio);
-		rqos = rqos->next;
-	} while (rqos);
+	}
 }
 
 void __rq_qos_merge(struct rq_qos *rqos, struct request *rq, struct bio *bio)
 {
-	do {
+	for_each_rq_qos(rqos) {
 		if (rqos->ops->merge)
 			rqos->ops->merge(rqos, rq, bio);
-		rqos = rqos->next;
-	} while (rqos);
+	}
 }
 
 void __rq_qos_done_bio(struct rq_qos *rqos, struct bio *bio)
 {
-	do {
+	for_each_rq_qos(rqos) {
 		if (rqos->ops->done_bio)
 			rqos->ops->done_bio(rqos, bio);
-		rqos = rqos->next;
-	} while (rqos);
+	}
 }
 
 void __rq_qos_queue_depth_changed(struct rq_qos *rqos)
 {
-	do {
+	for_each_rq_qos(rqos) {
 		if (rqos->ops->queue_depth_changed)
 			rqos->ops->queue_depth_changed(rqos);
-		rqos = rqos->next;
-	} while (rqos);
+	}
 }
 
 /*
diff --git a/block/blk-rq-qos.h b/block/blk-rq-qos.h
index 2bc43e9..bfa72a5 100644
--- a/block/blk-rq-qos.h
+++ b/block/blk-rq-qos.h
@@ -57,11 +57,18 @@ struct rq_depth {
 	unsigned int default_depth;
 };
 
+/*
+ * for_each_rq_qos() allows you to iterate on each rqos
+ */
+#define for_each_rq_qos(rqos) \
+	for (; rqos; rqos = rqos->next)
+
 static inline struct rq_qos *rq_qos_id(struct request_queue *q,
 				       enum rq_qos_id id)
 {
-	struct rq_qos *rqos;
-	for (rqos = q->rq_qos; rqos; rqos = rqos->next) {
+	struct rq_qos *rqos = q->rq_qos;
+
+	for_each_rq_qos(rqos) {
 		if (rqos->id == id)
 			break;
 	}
-- 
1.8.3.1

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ