Hello Anand Jain,

The patch a6500c9ef8ac: "btrfs: add helper function check device
delete able" from Jul 10, 2018, leads to the following static checker
warning:

        fs/btrfs/volumes.c:1871 btrfs_device_delete_able()
        error: passing non negative 4 to ERR_PTR

        fs/btrfs/volumes.c:1876 btrfs_device_delete_able()
        error: passing non negative 6 to ERR_PTR

        fs/btrfs/volumes.c:1879 btrfs_device_delete_able()
        error: passing non negative 5 to ERR_PTR

        fs/btrfs/volumes.c:1883 btrfs_device_delete_able()
        error: passing non negative 7 to ERR_PTR

fs/btrfs/volumes.c
  1861  static struct btrfs_device *btrfs_device_delete_able(
  1862                                  struct btrfs_fs_info *fs_info,
  1863                                  const char *device_path, u64 devid)
  1864  {
  1865          int ret;
  1866          struct btrfs_device *device;
  1867  
  1868          ret = btrfs_check_raid_min_devices(fs_info,
  1869                                             btrfs_num_devices(fs_info) - 
1);
  1870          if (ret)
  1871                  return ERR_PTR(ret);
                                       ^^^
This is a btrfs_err_code enum, not a negative error code.  It leads to
a NULL dereference in the caller.

  1872  
  1873          ret = btrfs_find_device_by_devspec(fs_info, devid, device_path,
  1874                                             &device);
  1875          if (ret)
  1876                  return ERR_PTR(ret);
                                       ^^^
  1877  
  1878          if (test_bit(BTRFS_DEV_STATE_REPLACE_TGT, &device->dev_state))
  1879                  return ERR_PTR(BTRFS_ERROR_DEV_TGT_REPLACE);
                                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^
Same only even more so.

  1880  
  1881          if (test_bit(BTRFS_DEV_STATE_WRITEABLE, &device->dev_state) &&
  1882              fs_info->fs_devices->rw_devices == 1)
  1883                  return ERR_PTR(BTRFS_ERROR_DEV_ONLY_WRITABLE);
                                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  1884  
  1885          return device;
  1886  }

See also:

regards,
dan carpenter
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to