diff --git a/cmds-device.c b/cmds-device.c index f9ac7f5f..9a7287a6 100644 --- a/cmds-device.c +++ b/cmds-device.c @@ -180,15 +180,16 @@ static int cmd_rm_dev(int argc, char **argv) strncpy_null(arg.name, argv[i]); res = ioctl(fdmnt, BTRFS_IOC_RM_DEV, &arg); e = errno; - if (res > 0) { + if (res) { + const char *msg; + + if (ret > 0) + msg = btrfs_err_str(res); + else + msg = strerror(e); fprintf(stderr, "ERROR: error removing the device '%s' - %s\n", - argv[i], btrfs_err_str(res)); - ret++; - } else if (res < 0) { - fprintf(stderr, - "ERROR: error removing the device '%s' - %s\n", - argv[i], strerror(e)); + argv[i], msg); ret++; } }