btrfs: test for valid bdev before kobj removal in btrfs_rm_device
authorEric Sandeen <sandeen@redhat.com>
Mon, 7 Jul 2014 17:34:49 +0000 (12:34 -0500)
committerChris Mason <clm@fb.com>
Sat, 19 Jul 2014 18:49:44 +0000 (11:49 -0700)
commit 99994cd btrfs: dev delete should remove sysfs entry
added a btrfs_kobj_rm_device, which dereferences device->bdev...
right after we check whether device->bdev might be NULL.

I don't honestly know if it's possible to have a NULL device->bdev
here, but assuming that it is (given the test), we need to move
the kobject removal to be under that test.

(Coverity spotted this)

Signed-off-by: Eric Sandeen <sandeen@redhat.com>
Signed-off-by: Chris Mason <clm@fb.com>
fs/btrfs/volumes.c

index 6104676857f5c6567bcbb5a375cb91e90a78956f..6cb82f62cb7c22c4b3038e248e52b9694171a5bd 100644 (file)
@@ -1680,11 +1680,11 @@ int btrfs_rm_device(struct btrfs_root *root, char *device_path)
        if (device->bdev == root->fs_info->fs_devices->latest_bdev)
                root->fs_info->fs_devices->latest_bdev = next_device->bdev;
 
-       if (device->bdev)
+       if (device->bdev) {
                device->fs_devices->open_devices--;
-
-       /* remove sysfs entry */
-       btrfs_kobj_rm_device(root->fs_info, device);
+               /* remove sysfs entry */
+               btrfs_kobj_rm_device(root->fs_info, device);
+       }
 
        call_rcu(&device->rcu, free_device);