* [bug report] blk-mq-tag: cleanup the normal/reserved tag allocation
@ 2017-01-19 10:54 Dan Carpenter
2017-01-19 14:13 ` Jens Axboe
0 siblings, 1 reply; 2+ messages in thread
From: Dan Carpenter @ 2017-01-19 10:54 UTC (permalink / raw)
To: axboe; +Cc: linux-block
Hello Jens Axboe,
This is a semi-automatic email about new static checker warnings.
The patch 4941115bef2b: "blk-mq-tag: cleanup the normal/reserved tag
allocation" from Jan 13, 2017, leads to the following Smatch
complaint:
block/blk-mq-tag.c:142 blk_mq_get_tag()
warn: variable dereferenced before check 'data->hctx' (see line 102)
block/blk-mq-tag.c
101 {
102 struct blk_mq_tags *tags = blk_mq_tags_from_data(data);
^^^^^^^^^^^^^^^^^^^^^^^^^^^
We added a new "data->hctx" dereference here.
103 struct sbitmap_queue *bt;
104 struct sbq_wait_state *ws;
105 DEFINE_WAIT(wait);
106 unsigned int tag_offset;
107 int tag;
108
109 if (data->flags & BLK_MQ_REQ_RESERVED) {
110 if (unlikely(!tags->nr_reserved_tags)) {
111 WARN_ON_ONCE(1);
112 return BLK_MQ_TAG_FAIL;
113 }
114 bt = &tags->breserved_tags;
115 tag_offset = 0;
116 } else {
117 bt = &tags->bitmap_tags;
118 tag_offset = tags->nr_reserved_tags;
119 }
120
121 tag = __blk_mq_get_tag(data->hctx, bt);
122 if (tag != -1)
123 goto found_tag;
124
125 if (data->flags & BLK_MQ_REQ_NOWAIT)
126 return BLK_MQ_TAG_FAIL;
127
128 ws = bt_wait_ptr(bt, data->hctx);
129 do {
130 prepare_to_wait(&ws->wait, &wait, TASK_UNINTERRUPTIBLE);
131
132 tag = __blk_mq_get_tag(data->hctx, bt);
133 if (tag != -1)
134 break;
135
136 /*
137 * We're out of tags on this hardware queue, kick any
138 * pending IO submits before going to sleep waiting for
139 * some to complete. Note that hctx can be NULL here for
140 * reserved tag allocation.
141 */
142 if (data->hctx)
We're in a loop here so it's possible we don't need to check the first
item in the list, but it's kind of new so I thought I would forward the
message anyway even though it might be a false positive.
143 blk_mq_run_hw_queue(data->hctx, false);
144
regards,
dan carpenter
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [bug report] blk-mq-tag: cleanup the normal/reserved tag allocation
2017-01-19 10:54 [bug report] blk-mq-tag: cleanup the normal/reserved tag allocation Dan Carpenter
@ 2017-01-19 14:13 ` Jens Axboe
0 siblings, 0 replies; 2+ messages in thread
From: Jens Axboe @ 2017-01-19 14:13 UTC (permalink / raw)
To: Dan Carpenter; +Cc: linux-block
On 01/19/2017 02:54 AM, Dan Carpenter wrote:
> Hello Jens Axboe,
>
> This is a semi-automatic email about new static checker warnings.
>
> The patch 4941115bef2b: "blk-mq-tag: cleanup the normal/reserved tag
> allocation" from Jan 13, 2017, leads to the following Smatch
> complaint:
>
> block/blk-mq-tag.c:142 blk_mq_get_tag()
> warn: variable dereferenced before check 'data->hctx' (see line 102)
>
> block/blk-mq-tag.c
> 101 {
> 102 struct blk_mq_tags *tags = blk_mq_tags_from_data(data);
> ^^^^^^^^^^^^^^^^^^^^^^^^^^^
> We added a new "data->hctx" dereference here.
>
> 103 struct sbitmap_queue *bt;
> 104 struct sbq_wait_state *ws;
> 105 DEFINE_WAIT(wait);
> 106 unsigned int tag_offset;
> 107 int tag;
> 108
> 109 if (data->flags & BLK_MQ_REQ_RESERVED) {
> 110 if (unlikely(!tags->nr_reserved_tags)) {
> 111 WARN_ON_ONCE(1);
> 112 return BLK_MQ_TAG_FAIL;
> 113 }
> 114 bt = &tags->breserved_tags;
> 115 tag_offset = 0;
> 116 } else {
> 117 bt = &tags->bitmap_tags;
> 118 tag_offset = tags->nr_reserved_tags;
> 119 }
> 120
> 121 tag = __blk_mq_get_tag(data->hctx, bt);
> 122 if (tag != -1)
> 123 goto found_tag;
> 124
> 125 if (data->flags & BLK_MQ_REQ_NOWAIT)
> 126 return BLK_MQ_TAG_FAIL;
> 127
> 128 ws = bt_wait_ptr(bt, data->hctx);
> 129 do {
> 130 prepare_to_wait(&ws->wait, &wait, TASK_UNINTERRUPTIBLE);
> 131
> 132 tag = __blk_mq_get_tag(data->hctx, bt);
> 133 if (tag != -1)
> 134 break;
> 135
> 136 /*
> 137 * We're out of tags on this hardware queue, kick any
> 138 * pending IO submits before going to sleep waiting for
> 139 * some to complete. Note that hctx can be NULL here for
> 140 * reserved tag allocation.
> 141 */
> 142 if (data->hctx)
>
> We're in a loop here so it's possible we don't need to check the first
> item in the list, but it's kind of new so I thought I would forward the
> message anyway even though it might be a false positive.
It's no longer possible for 'hctx' to be passed in as NULL, so the above
dereference is safe. I'll tend to this superfluous hctx check.
--
Jens Axboe
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2017-01-19 14:19 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-01-19 10:54 [bug report] blk-mq-tag: cleanup the normal/reserved tag allocation Dan Carpenter
2017-01-19 14:13 ` Jens Axboe
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.