Skip to contentSkip to conversation

accel/habanalabs: add NVMe Direct I/O (HLDIO) infrastructure

bug report Dan Carpenter 2 participants 2 messages Sep 27, 2025

lore
Share & tools
lore
#0 lore raw

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

#1 lore raw

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.

Quoted 33 lines · Dan Carpenter

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