From: yanlonglong <yanlonglong@kylinos.cn>
To: axboe@kernel.dk
Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org,
yanlonglong@kylinos.cn, yukuai@fnnas.com
Subject: [PATCH v2] block: add NULL checks for bic in bfq_bfqq_save_state function
Date: Wed, 6 May 2026 17:04:09 +0800 [thread overview]
Message-ID: <20260506090409.49648-1-yanlonglong@kylinos.cn> (raw)
In-Reply-To: <db3d516f-6ad2-469a-9bd8-1a9b61eb12a0@kernel.dk>
When the `bic` variable is null, referencing `bfqq_data` through `bic` will
cause the program to crash. Therefore, the null check for `bic` should be
moved to the beginning of the function to prevent referencing a null pointer.
Fixed:fd571df0ac5b289af8("block, bfq: turn bfqq_data into an array in bfq_io_cq")
Signed-off-by: yanlonglong <yanlonglong@kylinos.cn>
---
block/bfq-iosched.c | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/block/bfq-iosched.c b/block/bfq-iosched.c
index 141c602d5e85..e952e4ea2dd4 100644
--- a/block/bfq-iosched.c
+++ b/block/bfq-iosched.c
@@ -3035,9 +3035,8 @@ bfq_setup_cooperator(struct bfq_data *bfqd, struct bfq_queue *bfqq,
static void bfq_bfqq_save_state(struct bfq_queue *bfqq)
{
struct bfq_io_cq *bic = bfqq->bic;
- unsigned int a_idx = bfqq->actuator_idx;
- struct bfq_iocq_bfqq_data *bfqq_data = &bic->bfqq_data[a_idx];
-
+ unsigned int a_idx = 0;
+ struct bfq_iocq_bfqq_data *bfqq_data = NULL;
/*
* If !bfqq->bic, the queue is already shared or its requests
* have already been redirected to a shared queue; both idle window
@@ -3046,6 +3045,9 @@ static void bfq_bfqq_save_state(struct bfq_queue *bfqq)
if (!bic)
return;
+ a_idx = bfqq->actuator_idx;
+ bfqq_data = &bic->bfqq_data[a_idx];
+
bfqq_data->saved_last_serv_time_ns = bfqq->last_serv_time_ns;
bfqq_data->saved_inject_limit = bfqq->inject_limit;
bfqq_data->saved_decrease_time_jif = bfqq->decrease_time_jif;
--
2.43.0
next prev parent reply other threads:[~2026-05-06 9:04 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-06 5:56 [PATCH] block: bic maybe null pointer dereference yanlonglong
2026-05-06 7:09 ` Jens Axboe
2026-05-06 9:04 ` yanlonglong [this message]
2026-05-06 10:41 ` [PATCH v2] block: add NULL checks for bic in bfq_bfqq_save_state function Jens Axboe
2026-05-07 1:28 ` [PATCH v3] " yanlonglong
2026-05-07 5:18 ` Jens Axboe
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=20260506090409.49648-1-yanlonglong@kylinos.cn \
--to=yanlonglong@kylinos.cn \
--cc=axboe@kernel.dk \
--cc=linux-block@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=yukuai@fnnas.com \
/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