Re: [PATCH v3] block: add NULL checks for bic in bfq_bfqq_save_state function
From: Jens Axboe
Date: Thu May 07 2026 - 01:19:21 EST
On 5/6/26 7:28 PM, yanlonglong wrote:
> 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.
This part is obvious, what really needs explaining here is what conditions
can lead to bic being NULL, as that is supposedly the problem being fixed.
So, which conditions lead to bic being NULL here? A good commit message
should explain the "why" of why a change is being made. It's obvious
from the code change what is being done, what is not obvious is why it's
necessary.
> Fixes:fd571df0ac5b("block, bfq: turn bfqq_data into an array in bfq_io_cq")
Still incorrect, need space after Fixes:
> diff --git a/block/bfq-iosched.c b/block/bfq-iosched.c
> index 141c602d5e85..c8cf8764d48d 100644
> --- a/block/bfq-iosched.c
> +++ b/block/bfq-iosched.c
> @@ -3036,7 +3036,7 @@ 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];
> + struct bfq_iocq_bfqq_data *bfqq_data = NULL;
Minor nit, but why initialize it to NULL?
--
Jens Axboe