linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [bug report] btrfs: add helper function check device delete able
@ 2018-07-19  8:10 Dan Carpenter
  2018-07-20  6:36 ` Anand Jain
  0 siblings, 1 reply; 2+ messages in thread
From: Dan Carpenter @ 2018-07-19  8:10 UTC (permalink / raw)
  To: anand.jain; +Cc: linux-btrfs

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

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2018-07-20  7:19 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-07-19  8:10 [bug report] btrfs: add helper function check device delete able Dan Carpenter
2018-07-20  6:36 ` Anand Jain

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).