• Anand Jain's avatar
    btrfs: move device->name RCU allocation and assign to btrfs_alloc_device() · bb21e302
    Anand Jain authored
    There is a repeating code section in the parent function after calling
    btrfs_alloc_device(), as below:
    
          name = rcu_string_strdup(path, GFP_...);
          if (!name) {
                  btrfs_free_device(device);
                  return ERR_PTR(-ENOMEM);
          }
          rcu_assign_pointer(device->name, name);
    
    Except in add_missing_dev() for obvious reasons.
    
    This patch consolidates that repeating code into the btrfs_alloc_device()
    itself so that the parent function doesn't have to duplicate code.
    This consolidation also helps to review issues regarding RCU lock
    violation with device->name.
    
    Parent function device_list_add() and add_missing_dev() use GFP_NOFS for
    the allocation, whereas the rest of the parent functions use GFP_KERNEL,
    so bring the NOFS allocation context using memalloc_nofs_save() in the
    function device_list_add() and add_missing_dev() is already doing it.
    Signed-off-by: default avatarAnand Jain <anand.jain@oracle.com>
    Reviewed-by: default avatarDavid Sterba <dsterba@suse.com>
    Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
    bb21e302
volumes.c 226 KB