Re: [PATCH] selftests/ublk: add NULL check after calloc()

From: Ming Lei

Date: Wed Sep 02 2026 - 07:34:33 EST


On Wed, Sep 2, 2026 at 1:45 AM longlong yan <yanlonglong@xxxxxxxxxx> wrote:
>
> Three calloc() calls in the ublk selftests lack NULL return checks,
> leading to potential NULL pointer dereferences on allocation failure:
>
> 1. kublk.c ublk_ctrl_init(): the allocated `dev` is dereferenced
> immediately via `info = &dev->dev_info` without checking for NULL.
>
> 2. batch.c alloc_batch_commit_buf(): the allocated `t->commit` is
> dereferenced in the following for-loop without checking for NULL.
>
> 3. batch.c alloc_batch_fetch_buf(): the allocated `t->fetch` is
> dereferenced in the following for-loop without checking for NULL.
>
> Add NULL checks after each calloc(), returning NULL or -ENOMEM consistent
> with existing error handling in the same functions.
>
> Signed-off-by: longlong yan <yanlonglong@xxxxxxxxxx>

Looks fine, all needn't special failure handling:

Reviewed-by: Ming Lei <tom.leiming@xxxxxxxxx>



Thanks,
Ming