Skip to contentSkip to conversation

some random cleanups for blk-mq.c

PATCH Applied Jinlong Chen 2 participants 5 messages Nov 2, 2022 Block layer

v2 of 3 Applied Latest is v3 →

lore
Share & tools
lore
#0 lore raw

v2 cover some random cleanups for blk-mq.c

Patch 1 improves the error handling blk_mq_alloc_rq_map(). Patch 2 improves readability of blk_mq_alloc_cached_request().

Changes in v2:
- drop wrong and worthless patches, suggested by Christoph, Jens and Chaitanya
- remove silly goto-return-NULL in patch 1 (patch 2 originally), suggested by Christoph and Jens

Jinlong Chen (2):
blk-mq: improve error handling in blk_mq_alloc_rq_map()
blk-mq: use if-else instead of goto in blk_mq_alloc_cached_request()

 block/blk-mq.c | 46 ++++++++++++++++++++++++----------------------
 1 file changed, 24 insertions(+), 22 deletions(-)
Signature · 1 line
2.31.1
#1 lore raw

PATCH v2 1/2 blk-mq: improve error handling in blk_mq_alloc_rq_map()

Use goto-style error handling like we do elsewhere in the kernel.

---
 block/blk-mq.c | 19 ++++++++++---------
 1 file changed, 10 insertions(+), 9 deletions(-)
block/blk-mq.c +10 -9
index 623e8a506539..453ad445a6bd 100644
@@ -3274,21 +3274,22 @@ static struct blk_mq_tags *blk_mq_alloc_rq_map(struct blk_mq_tag_set *set,
 	tags->rqs = kcalloc_node(nr_tags, sizeof(struct request *),
 				 GFP_NOIO | __GFP_NOWARN | __GFP_NORETRY,
 				 node);
-	if (!tags->rqs) {
-		blk_mq_free_tags(tags);
-		return NULL;
-	}
+	if (!tags->rqs)
+		goto err_free_tags;
 
 	tags->static_rqs = kcalloc_node(nr_tags, sizeof(struct request *),
 					GFP_NOIO | __GFP_NOWARN | __GFP_NORETRY,
 					node);
-	if (!tags->static_rqs) {
-		kfree(tags->rqs);
-		blk_mq_free_tags(tags);
-		return NULL;
-	}
+	if (!tags->static_rqs)
+		goto err_free_rqs;
 
 	return tags;
+
+err_free_rqs:
+	kfree(tags->rqs);
+err_free_tags:
+	blk_mq_free_tags(tags);
+	return NULL;
 }
 
 static int blk_mq_init_request(struct blk_mq_tag_set *set, struct request *rq,
Signature · 1 line
2.31.1
#2 lore raw

PATCH v2 2/2 blk-mq: use if-else instead of goto in blk_mq_alloc_cached_request()

In reply to Jinlong Chen

if-else is more readable than goto here.

---
 block/blk-mq.c | 27 ++++++++++++++-------------
 1 file changed, 14 insertions(+), 13 deletions(-)
block/blk-mq.c +14 -13
index 453ad445a6bd..6ffca7af5b6f 100644
@@ -544,25 +544,26 @@ static struct request *blk_mq_alloc_cached_request(struct request_queue *q,
 
 	if (!plug)
 		return NULL;
+
 	if (rq_list_empty(plug->cached_rq)) {
 		if (plug->nr_ios == 1)
 			return NULL;
 		rq = blk_mq_rq_cache_fill(q, plug, opf, flags);
-		if (rq)
-			goto got_it;
-		return NULL;
-	}
-	rq = rq_list_peek(&plug->cached_rq);
-	if (!rq || rq->q != q)
-		return NULL;
+		if (!rq)
+			return NULL;
+	} else {
+		rq = rq_list_peek(&plug->cached_rq);
+		if (!rq || rq->q != q)
+			return NULL;
 
-	if (blk_mq_get_hctx_type(opf) != rq->mq_hctx->type)
-		return NULL;
-	if (op_is_flush(rq->cmd_flags) != op_is_flush(opf))
-		return NULL;
+		if (blk_mq_get_hctx_type(opf) != rq->mq_hctx->type)
+			return NULL;
+		if (op_is_flush(rq->cmd_flags) != op_is_flush(opf))
+			return NULL;
+
+		plug->cached_rq = rq_list_next(rq);
+	}
 
-	plug->cached_rq = rq_list_next(rq);
-got_it:
 	rq->cmd_flags = opf;
 	INIT_LIST_HEAD(&rq->queuelist);
 	return rq;
Signature · 1 line
2.31.1
#3 lore raw
In reply to Jinlong Chen
Quoted 9 lines

Patch 1 improves the error handling blk_mq_alloc_rq_map(). Patch 2 improves readability of blk_mq_alloc_cached_request().

Changes in v2:
- drop wrong and worthless patches, suggested by Christoph, Jens and Chaitanya
- remove silly goto-return-NULL in patch 1 (patch 2 originally), suggested by Christoph and Jens

Quoted 6 lines

Jinlong Chen (2):
blk-mq: improve error handling in blk_mq_alloc_rq_map()
blk-mq: use if-else instead of goto in blk_mq_alloc_cached_request()

 block/blk-mq.c | 46 ++++++++++++++++++++++++----------------------
 1 file changed, 24 insertions(+), 22 deletions(-)

Oops, I forgot the reviewed tag by Christoph!

Sorry!
Jinlong Chen

maintainer Applied
#4 lore raw
In reply to Jinlong Chen
Quoted 10 lines · Jinlong Chen

Patch 1 improves the error handling blk_mq_alloc_rq_map(). Patch 2 improves readability of blk_mq_alloc_cached_request().

Changes in v2:
- drop wrong and worthless patches, suggested by Christoph, Jens and Chaitanya
- remove silly goto-return-NULL in patch 1 (patch 2 originally), suggested by Christoph and Jens

[...]

Applied, thanks!

[1/2] blk-mq: improve error handling in blk_mq_alloc_rq_map()

      commit: 7edfd68165b8dab8cde231728ff092a625469eb7
[2/2] blk-mq: use if-else instead of goto in blk_mq_alloc_cached_request()
      commit: 4046728253751adb41b05e85ebd686210efde1ad

Best regards,

Signature · 1 line
Jens Axboe