ltp_tbio.c: fix a possible kernel panic

In some environments an attempt to load ltp_tbio.ko module will
result in a kernel panic.

It happens, because after the module is loaded (add_disk(tbio_dev.gd) in
tbio_init() is executed), one or more ioctl() calls are issued to the newly
created block device. However, when ioctl() is called, there is no (yet) file
/dev/tbio created. Therefore, in tbio_ioctl():

  tbio_dev.bdev = blkdev_get_by_path(
              DEVICE_NAME, FMODE_READ | FMODE_WRITE, NULL);

returns -ENODEV, i.e. tbio_dev.bdev == -ENODEV, and it produces a kernel panic at:

  blkdev_put(tbio_dev.bdev, FMODE_READ | FMODE_WRITE);

We could introduce error checking here like this:

  if (IS_ERR(tbio_dev.bdev))
      return PTR_ERR(tbio_dev.bdev);

but I assume it would be better to return the previous logic, before commit
69d3b32681 "device-drivers: tbio: fixes", i.e. where tbio_dev.bdev is assigned
in tbio_open().

Signed-off-by: Stanislav Kholmanskikh <stanislav.kholmanskikh@oracle.com>
Acked-by: Cyril Hrubis <chrubis@suse.cz>
1 file changed