linux-block.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Yiyuan GUO <yguoaz@gmail.com>
To: hare@suse.de
Cc: axboe@kernel.dk, linux-block@vger.kernel.org, yguoaz@gmail.com,
	Yiyuan GUO <yguoaz@cse.ust.hk>
Subject: [PATCH] block: add protection for divide by zero in blk_mq_map_queues
Date: Fri, 14 May 2021 17:16:09 +0800	[thread overview]
Message-ID: <20210514091609.66252-1-yguoaz@cse.ust.hk> (raw)
In-Reply-To: <21cb65d1-b91a-2627-3824-292de3a7553a@suse.de>

In function blk_mq_map_queues, qmap->nr_queues may equal zero
and thus it needs to be checked before we pass it to function
queue_index.

Signed-off-by: Yiyuan GUO <yguoaz@cse.ust.hk>
---
 block/blk-mq-cpumap.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/block/blk-mq-cpumap.c b/block/blk-mq-cpumap.c
index 3db84d319..dc440870e 100644
--- a/block/blk-mq-cpumap.c
+++ b/block/blk-mq-cpumap.c
@@ -65,7 +65,8 @@ int blk_mq_map_queues(struct blk_mq_queue_map *qmap)
 		} else {
 			first_sibling = get_first_sibling(cpu);
 			if (first_sibling == cpu)
-				map[cpu] = queue_index(qmap, nr_queues, q++);
+				if (nr_queues)
+					map[cpu] = queue_index(qmap, nr_queues, q++);
 			else
 				map[cpu] = map[first_sibling];
 		}
-- 
2.25.1


  reply	other threads:[~2021-05-14  9:16 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-14  8:28 A possible divide by zero bug in blk_mq_map_queues Yiyuan guo
2021-05-14  8:34 ` Hannes Reinecke
2021-05-14  9:16   ` Yiyuan GUO [this message]
2021-05-14  9:24     ` [PATCH] block: add protection for divide by zero " Hannes Reinecke
2021-05-14  9:38       ` [PATCH v2] " Yiyuan GUO

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210514091609.66252-1-yguoaz@cse.ust.hk \
    --to=yguoaz@gmail.com \
    --cc=axboe@kernel.dk \
    --cc=hare@suse.de \
    --cc=linux-block@vger.kernel.org \
    --cc=yguoaz@cse.ust.hk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).