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: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:   Tue,  1 Nov 2022 23:11:37 +0800
From:   Jinlong Chen <nickyc975@....edu.cn>
To:     axboe@...nel.dk
Cc:     hch@....de, linux-block@...r.kernel.org,
        linux-kernel@...r.kernel.org, nickyc975@....edu.cn
Subject: [PATCH 4/4] blk-mq: improve readability of blk_mq_alloc_request()

Add a helper blk_mq_alloc_request_nocache() to alloc request without
cache. This makes blk_mq_alloc_request() more readable.

Signed-off-by: Jinlong Chen <nickyc975@....edu.cn>
---
 block/blk-mq.c | 47 +++++++++++++++++++++++++++++------------------
 1 file changed, 29 insertions(+), 18 deletions(-)

diff --git a/block/blk-mq.c b/block/blk-mq.c
index 87a6348a0d0a..2fae111a42c8 100644
--- a/block/blk-mq.c
+++ b/block/blk-mq.c
@@ -572,36 +572,47 @@ static struct request *blk_mq_alloc_cached_request(struct request_queue *q,
 	return rq;
 }
 
-struct request *blk_mq_alloc_request(struct request_queue *q, blk_opf_t opf,
-		blk_mq_req_flags_t flags)
+static struct request *blk_mq_alloc_request_nocache(struct request_queue *q,
+		blk_opf_t opf, blk_mq_req_flags_t flags)
 {
-	struct request *rq;
-
-	rq = blk_mq_alloc_cached_request(q, opf, flags);
-	if (!rq) {
-		struct blk_mq_alloc_data data = {
+	struct blk_mq_alloc_data data = {
 			.q		= q,
 			.flags		= flags,
 			.cmd_flags	= opf,
 			.nr_tags	= 1,
 		};
-		int ret;
+	struct request *rq;
+	int ret;
 
-		ret = blk_queue_enter(q, flags);
-		if (ret)
-			return ERR_PTR(ret);
+	ret = blk_queue_enter(q, flags);
+	if (ret)
+		return ERR_PTR(ret);
 
-		rq = __blk_mq_alloc_requests(&data);
-		if (!rq)
-			goto out_queue_exit;
+	rq = __blk_mq_alloc_requests(&data);
+	if (!rq) {
+		rq = ERR_PTR(-EWOULDBLOCK);
+		blk_queue_exit(q);
 	}
+
+	return rq;
+}
+
+struct request *blk_mq_alloc_request(struct request_queue *q, blk_opf_t opf,
+		blk_mq_req_flags_t flags)
+{
+	struct request *rq;
+
+	rq = blk_mq_alloc_cached_request(q, opf, flags);
+	if (!rq) {
+		rq = blk_mq_alloc_request_nocache(q, opf, flags);
+		if (IS_ERR(rq))
+			return rq;
+	}
+
 	rq->__data_len = 0;
 	rq->__sector = (sector_t) -1;
 	rq->bio = rq->biotail = NULL;
-	return rq;
-out_queue_exit:
-	blk_queue_exit(q);
-	return ERR_PTR(-EWOULDBLOCK);
+	return rq;
 }
 EXPORT_SYMBOL(blk_mq_alloc_request);
 
-- 
2.31.1

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ