Hi Dan,
Thanks for catching this.
You're right, `bd` is dereferenced before being checked in
hl_dio_fd_register(). I'll send a fix that moves the NULL check
before the dereference.
Konstantin.
On Sat, Sep 27, 2025 at 02:21:00PM +0000, Dan Carpenter wrote:
> Hello Konstantin Sinyuk,
>
> This is a semi-automatic email about new static checker warnings.
>
> Commit 8cbacc9a2703 ("accel/habanalabs: add NVMe Direct I/O (HLDIO)
> infrastructure") from Sep 9, 2024, leads to the following Smatch
> complaint:
>
> drivers/accel/habanalabs/common/hldio.c:106 hl_dio_fd_register()
> warn: variable dereferenced before check 'bd' (see line 98)
>
> drivers/accel/habanalabs/common/hldio.c
> 97 bd = sb->s_bdev;
> 98 gd = bd->bd_disk;
> ^^^^
> "bd" is dereferenced here
>
> 99
> 100 if (inode->i_blocks << sb->s_blocksize_bits <
> i_size_read(inode)) {
> 101 dev_err(hdev->dev, "sparse files are not
> currently supported\n");
> 102 rc = -EINVAL;
> 103 goto fput;
> 104 }
> 105
> 106 if (!bd || !gd) {
> ^^
> Checked too late here.
>
> 107 dev_err(hdev->dev, "invalid block device\n");
> 108 rc = -ENODEV;
>
> regards,
> dan carpenter