linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v3 0/2] some random cleanups for blk-mq.c
@ 2022-11-02  3:06 Jinlong Chen
  2022-11-02  3:06 ` [PATCH v3 1/2] blk-mq: improve error handling in blk_mq_alloc_rq_map() Jinlong Chen
  2022-11-02  3:06 ` [PATCH v3 2/2] blk-mq: use if-else instead of goto in blk_mq_alloc_cached_request() Jinlong Chen
  0 siblings, 2 replies; 7+ messages in thread
From: Jinlong Chen @ 2022-11-02  3:06 UTC (permalink / raw)
  To: axboe; +Cc: hch, chaitanyak, linux-block, linux-kernel, nickyc975

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

Changes in v3:
- add Reviewed-by: tag from Christoph

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(-)

-- 
2.31.1


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

* [PATCH v3 1/2] blk-mq: improve error handling in blk_mq_alloc_rq_map()
  2022-11-02  3:06 [PATCH v3 0/2] some random cleanups for blk-mq.c Jinlong Chen
@ 2022-11-02  3:06 ` Jinlong Chen
  2022-11-02  5:45   ` Chaitanya Kulkarni
  2022-11-02  6:59   ` Christoph Hellwig
  2022-11-02  3:06 ` [PATCH v3 2/2] blk-mq: use if-else instead of goto in blk_mq_alloc_cached_request() Jinlong Chen
  1 sibling, 2 replies; 7+ messages in thread
From: Jinlong Chen @ 2022-11-02  3:06 UTC (permalink / raw)
  To: axboe; +Cc: hch, chaitanyak, linux-block, linux-kernel, nickyc975

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

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

diff --git a/block/blk-mq.c b/block/blk-mq.c
index 623e8a506539..453ad445a6bd 100644
--- a/block/blk-mq.c
+++ b/block/blk-mq.c
@@ -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,
-- 
2.31.1


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

* [PATCH v3 2/2] blk-mq: use if-else instead of goto in blk_mq_alloc_cached_request()
  2022-11-02  3:06 [PATCH v3 0/2] some random cleanups for blk-mq.c Jinlong Chen
  2022-11-02  3:06 ` [PATCH v3 1/2] blk-mq: improve error handling in blk_mq_alloc_rq_map() Jinlong Chen
@ 2022-11-02  3:06 ` Jinlong Chen
  2022-11-02  5:46   ` Chaitanya Kulkarni
  2022-11-02  6:59   ` Christoph Hellwig
  1 sibling, 2 replies; 7+ messages in thread
From: Jinlong Chen @ 2022-11-02  3:06 UTC (permalink / raw)
  To: axboe; +Cc: hch, chaitanyak, linux-block, linux-kernel, nickyc975

if-else is more readable than goto here.

Signed-off-by: Jinlong Chen <nickyc975@zju.edu.cn>
Reviewed-by: Christoph Hellwig <hch@lst.de>
---
 block/blk-mq.c | 27 ++++++++++++++-------------
 1 file changed, 14 insertions(+), 13 deletions(-)

diff --git a/block/blk-mq.c b/block/blk-mq.c
index 453ad445a6bd..6ffca7af5b6f 100644
--- a/block/blk-mq.c
+++ b/block/blk-mq.c
@@ -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;
-- 
2.31.1


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

* Re: [PATCH v3 1/2] blk-mq: improve error handling in blk_mq_alloc_rq_map()
  2022-11-02  3:06 ` [PATCH v3 1/2] blk-mq: improve error handling in blk_mq_alloc_rq_map() Jinlong Chen
@ 2022-11-02  5:45   ` Chaitanya Kulkarni
  2022-11-02  6:59   ` Christoph Hellwig
  1 sibling, 0 replies; 7+ messages in thread
From: Chaitanya Kulkarni @ 2022-11-02  5:45 UTC (permalink / raw)
  To: Jinlong Chen, axboe; +Cc: hch, linux-block, linux-kernel

On 11/1/22 20:06, Jinlong Chen wrote:
> Use goto-style error handling like we do elsewhere in the kernel.
> 
> Signed-off-by: Jinlong Chen <nickyc975@zju.edu.cn>
> ---

since all to blk_mq_free_tags is duplicated in the code this seems
to be the right thing to do.

Reviewed-by: Chaitanya Kulkarni <kch@nvidia.com>

-ck

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

* Re: [PATCH v3 2/2] blk-mq: use if-else instead of goto in blk_mq_alloc_cached_request()
  2022-11-02  3:06 ` [PATCH v3 2/2] blk-mq: use if-else instead of goto in blk_mq_alloc_cached_request() Jinlong Chen
@ 2022-11-02  5:46   ` Chaitanya Kulkarni
  2022-11-02  6:59   ` Christoph Hellwig
  1 sibling, 0 replies; 7+ messages in thread
From: Chaitanya Kulkarni @ 2022-11-02  5:46 UTC (permalink / raw)
  To: Jinlong Chen, axboe; +Cc: hch, linux-block, linux-kernel

On 11/1/22 20:06, Jinlong Chen wrote:
> if-else is more readable than goto here.
> 
> Signed-off-by: Jinlong Chen <nickyc975@zju.edu.cn>
> Reviewed-by: Christoph Hellwig <hch@lst.de>
> ---

Reviewed-by: Chaitanya Kulkarni <kch@nvidia.com>

-ck



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

* Re: [PATCH v3 1/2] blk-mq: improve error handling in blk_mq_alloc_rq_map()
  2022-11-02  3:06 ` [PATCH v3 1/2] blk-mq: improve error handling in blk_mq_alloc_rq_map() Jinlong Chen
  2022-11-02  5:45   ` Chaitanya Kulkarni
@ 2022-11-02  6:59   ` Christoph Hellwig
  1 sibling, 0 replies; 7+ messages in thread
From: Christoph Hellwig @ 2022-11-02  6:59 UTC (permalink / raw)
  To: Jinlong Chen; +Cc: axboe, hch, chaitanyak, linux-block, linux-kernel

Looks good:

Reviewed-by: Christoph Hellwig <hch@lst.de>

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

* Re: [PATCH v3 2/2] blk-mq: use if-else instead of goto in blk_mq_alloc_cached_request()
  2022-11-02  3:06 ` [PATCH v3 2/2] blk-mq: use if-else instead of goto in blk_mq_alloc_cached_request() Jinlong Chen
  2022-11-02  5:46   ` Chaitanya Kulkarni
@ 2022-11-02  6:59   ` Christoph Hellwig
  1 sibling, 0 replies; 7+ messages in thread
From: Christoph Hellwig @ 2022-11-02  6:59 UTC (permalink / raw)
  To: Jinlong Chen; +Cc: axboe, hch, chaitanyak, linux-block, linux-kernel

Looks good:

Reviewed-by: Christoph Hellwig <hch@lst.de>

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

end of thread, other threads:[~2022-11-02  7:00 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-02  3:06 [PATCH v3 0/2] some random cleanups for blk-mq.c Jinlong Chen
2022-11-02  3:06 ` [PATCH v3 1/2] blk-mq: improve error handling in blk_mq_alloc_rq_map() Jinlong Chen
2022-11-02  5:45   ` Chaitanya Kulkarni
2022-11-02  6:59   ` Christoph Hellwig
2022-11-02  3:06 ` [PATCH v3 2/2] blk-mq: use if-else instead of goto in blk_mq_alloc_cached_request() Jinlong Chen
2022-11-02  5:46   ` Chaitanya Kulkarni
2022-11-02  6:59   ` Christoph Hellwig

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).