Skip to content

Commit fd03177

Browse files
Algodev-githubaxboe
authored andcommitted
block, bfq: handle NULL return value by bfq_init_rq()
As reported in [1], the call bfq_init_rq(rq) may return NULL in case of OOM (in particular, if rq->elv.icq is NULL because memory allocation failed in failed in ioc_create_icq()). This commit handles this circumstance. [1] https://lkml.org/lkml/2019/7/22/824 Cc: Hsin-Yi Wang <[email protected]> Cc: Nicolas Boichat <[email protected]> Cc: Doug Anderson <[email protected]> Reported-by: Guenter Roeck <[email protected]> Reported-by: Hsin-Yi Wang <[email protected]> Reviewed-by: Guenter Roeck <[email protected]> Signed-off-by: Paolo Valente <[email protected]> Signed-off-by: Jens Axboe <[email protected]>
1 parent 3f758e8 commit fd03177

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

block/bfq-iosched.c

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2251,9 +2251,14 @@ static void bfq_request_merged(struct request_queue *q, struct request *req,
22512251
blk_rq_pos(container_of(rb_prev(&req->rb_node),
22522252
struct request, rb_node))) {
22532253
struct bfq_queue *bfqq = bfq_init_rq(req);
2254-
struct bfq_data *bfqd = bfqq->bfqd;
2254+
struct bfq_data *bfqd;
22552255
struct request *prev, *next_rq;
22562256

2257+
if (!bfqq)
2258+
return;
2259+
2260+
bfqd = bfqq->bfqd;
2261+
22572262
/* Reposition request in its sort_list */
22582263
elv_rb_del(&bfqq->sort_list, req);
22592264
elv_rb_add(&bfqq->sort_list, req);
@@ -2300,6 +2305,9 @@ static void bfq_requests_merged(struct request_queue *q, struct request *rq,
23002305
struct bfq_queue *bfqq = bfq_init_rq(rq),
23012306
*next_bfqq = bfq_init_rq(next);
23022307

2308+
if (!bfqq)
2309+
return;
2310+
23032311
/*
23042312
* If next and rq belong to the same bfq_queue and next is older
23052313
* than rq, then reposition rq in the fifo (by substituting next
@@ -5454,12 +5462,12 @@ static void bfq_insert_request(struct blk_mq_hw_ctx *hctx, struct request *rq,
54545462

54555463
spin_lock_irq(&bfqd->lock);
54565464
bfqq = bfq_init_rq(rq);
5457-
if (at_head || blk_rq_is_passthrough(rq)) {
5465+
if (!bfqq || at_head || blk_rq_is_passthrough(rq)) {
54585466
if (at_head)
54595467
list_add(&rq->queuelist, &bfqd->dispatch);
54605468
else
54615469
list_add_tail(&rq->queuelist, &bfqd->dispatch);
5462-
} else { /* bfqq is assumed to be non null here */
5470+
} else {
54635471
idle_timer_disabled = __bfq_insert_request(bfqd, rq);
54645472
/*
54655473
* Update bfqq, because, if a queue merge has occurred

0 commit comments

Comments
 (0)