* [PATCH] block: fix arg type in `blk_mq_update_nr_hw_queues`
@ 2026-06-08 8:39 Andreas Hindborg
2026-06-08 15:50 ` Bart Van Assche
0 siblings, 1 reply; 3+ messages in thread
From: Andreas Hindborg @ 2026-06-08 8:39 UTC (permalink / raw)
To: Jens Axboe; +Cc: linux-block, linux-kernel, Andreas Hindborg
The type of the argument `nr_hw_queues` in the function
`blk_mq_update_nr_hw_queues` is a signed integer. This is wrong,
considering the field `nr_hw_queues` of `struct blk_mq_tag_set` is
unsigned. Thus, change the type of the parameter to unsigned.
Cascade the change to downstream functions.
Signed-off-by: Andreas Hindborg <a.hindborg@kernel.org>
---
block/blk-mq.c | 13 +++++++------
include/linux/blk-mq.h | 2 +-
2 files changed, 8 insertions(+), 7 deletions(-)
diff --git a/block/blk-mq.c b/block/blk-mq.c
index 4c5c16cce4f8..5eb9b52f3146 100644
--- a/block/blk-mq.c
+++ b/block/blk-mq.c
@@ -4816,10 +4816,10 @@ static void blk_mq_update_queue_map(struct blk_mq_tag_set *set)
static struct blk_mq_tags **blk_mq_prealloc_tag_set_tags(
struct blk_mq_tag_set *set,
- int new_nr_hw_queues)
+ unsigned int new_nr_hw_queues)
{
struct blk_mq_tags **new_tags;
- int i;
+ unsigned int i;
if (set->nr_hw_queues >= new_nr_hw_queues)
return NULL;
@@ -5134,12 +5134,12 @@ static int blk_mq_elv_switch_none(struct request_queue *q,
}
static void __blk_mq_update_nr_hw_queues(struct blk_mq_tag_set *set,
- int nr_hw_queues)
+ unsigned int nr_hw_queues)
{
struct request_queue *q;
- int prev_nr_hw_queues = set->nr_hw_queues;
+ unsigned int prev_nr_hw_queues = set->nr_hw_queues;
unsigned int memflags;
- int i;
+ unsigned int i;
struct xarray elv_tbl;
struct blk_mq_tags **new_tags;
bool queues_frozen = false;
@@ -5234,7 +5234,8 @@ static void __blk_mq_update_nr_hw_queues(struct blk_mq_tag_set *set,
__blk_mq_free_map_and_rqs(set, i);
}
-void blk_mq_update_nr_hw_queues(struct blk_mq_tag_set *set, int nr_hw_queues)
+void blk_mq_update_nr_hw_queues(struct blk_mq_tag_set *set,
+ unsigned int nr_hw_queues)
{
down_write(&set->update_nr_hwq_lock);
mutex_lock(&set->tag_list_lock);
diff --git a/include/linux/blk-mq.h b/include/linux/blk-mq.h
index 18a2388ba581..f73b4a1f16db 100644
--- a/include/linux/blk-mq.h
+++ b/include/linux/blk-mq.h
@@ -974,7 +974,7 @@ unsigned int blk_mq_num_online_queues(unsigned int max_queues);
void blk_mq_map_queues(struct blk_mq_queue_map *qmap);
void blk_mq_map_hw_queues(struct blk_mq_queue_map *qmap,
struct device *dev, unsigned int offset);
-void blk_mq_update_nr_hw_queues(struct blk_mq_tag_set *set, int nr_hw_queues);
+void blk_mq_update_nr_hw_queues(struct blk_mq_tag_set *set, unsigned int nr_hw_queues);
void blk_mq_quiesce_queue_nowait(struct request_queue *q);
---
base-commit: 7fd2df204f342fc17d1a0bfcd474b24232fb0f32
change-id: 20260608-update-hw-nodes-arg-940ecec0380a
Best regards,
--
Andreas Hindborg <a.hindborg@kernel.org>
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] block: fix arg type in `blk_mq_update_nr_hw_queues`
2026-06-08 8:39 [PATCH] block: fix arg type in `blk_mq_update_nr_hw_queues` Andreas Hindborg
@ 2026-06-08 15:50 ` Bart Van Assche
2026-06-09 7:59 ` Andreas Hindborg
0 siblings, 1 reply; 3+ messages in thread
From: Bart Van Assche @ 2026-06-08 15:50 UTC (permalink / raw)
To: Andreas Hindborg, Jens Axboe; +Cc: linux-block, linux-kernel
On 6/8/26 1:39 AM, Andreas Hindborg wrote:
> The type of the argument `nr_hw_queues` in the function
> `blk_mq_update_nr_hw_queues` is a signed integer. This is wrong,
> considering the field `nr_hw_queues` of `struct blk_mq_tag_set` is
> unsigned. Thus, change the type of the parameter to unsigned.
Will there ever be storage devices that support more than 2**31 hardware
queues? If not, I think the word "wrong" in the commit message is too
strong.
If this patch does not change the behavior of the code for any practical
use case that would be good to mention.
Thanks,
Bart.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] block: fix arg type in `blk_mq_update_nr_hw_queues`
2026-06-08 15:50 ` Bart Van Assche
@ 2026-06-09 7:59 ` Andreas Hindborg
0 siblings, 0 replies; 3+ messages in thread
From: Andreas Hindborg @ 2026-06-09 7:59 UTC (permalink / raw)
To: Bart Van Assche, Jens Axboe; +Cc: linux-block, linux-kernel
"Bart Van Assche" <bvanassche@acm.org> writes:
> On 6/8/26 1:39 AM, Andreas Hindborg wrote:
>> The type of the argument `nr_hw_queues` in the function
>> `blk_mq_update_nr_hw_queues` is a signed integer. This is wrong,
>> considering the field `nr_hw_queues` of `struct blk_mq_tag_set` is
>> unsigned. Thus, change the type of the parameter to unsigned.
>
> Will there ever be storage devices that support more than 2**31 hardware
> queues? If not,
Probably not.
> I think the word "wrong" in the commit message is too
> strong.
Right, I understand. I can change the wording. I chose it because it
seems wrong to me to use a signed type for a value that logically should
never assume a negative value. If the negative value was used to carry
some kind of information, it would make sense, but that is not the case
here.
> If this patch does not change the behavior of the code for any practical
> use case that would be good to mention.
The patch does not change behavior of the code as long as no overflows
occur, and they are not likely to occur. I will be sure to add that to
the commit message.
I came across this while designing the Rust API for these functions.
Rust is kind of particular about integer types, so it gave me some
checks/casts on the Rust side that really should no be required. I was
thinking we might as well change the type on the C side to unsigned when
the data it carries really should be unsigned.
Best regards,
Andreas Hindborg
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-06-09 8:00 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-06-08 8:39 [PATCH] block: fix arg type in `blk_mq_update_nr_hw_queues` Andreas Hindborg
2026-06-08 15:50 ` Bart Van Assche
2026-06-09 7:59 ` Andreas Hindborg
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.