static int _init_by_name_crypt_none(struct crypt_device *cd)
{
	int r;
	char _mode[MAX_CIPHER_LEN];
	struct crypt_dm_active_device dmd;
	struct dm_target *tgt = &dmd.segment;

	if (cd->type || !cd->u.none.active_name)
		return -EINVAL;

	r = dm_query_device(cd, cd->u.none.active_name,
			DM_ACTIVE_CRYPT_CIPHER |
			DM_ACTIVE_CRYPT_KEYSIZE, &dmd);
	if (r < 0)
		return r;
	if (!single_segment(&dmd) || tgt->type != DM_CRYPT)
		r = -EINVAL;
	if (r >= 0)
		r = crypt_parse_name_and_mode(tgt->u.crypt.cipher,
					      cd->u.none.cipher, NULL,
					      _mode);

	if (!r) {
		r = snprintf(cd->u.none.cipher_spec, sizeof(cd->u.none.cipher_spec),
			 "%s-%s", cd->u.none.cipher, _mode);
		if (r < 0 || (size_t)r >= sizeof(cd->u.none.cipher_spec))
			r = -EINVAL;
		else {
			cd->u.none.cipher_mode = cd->u.none.cipher_spec + strlen(cd->u.none.cipher) + 1;
			cd->u.none.key_size = tgt->u.crypt.vk->keylength;
			r = 0;
		}
	}

	dm_targets_free(cd, &dmd);
	return r;
}
static int _init_by_name_crypt_none(struct crypt_device *cd)
{
	int r;
	char _mode[MAX_CIPHER_LEN];
	struct crypt_dm_active_device dmd;
	struct dm_target *tgt = &dmd.segment;

	if (cd->type || !cd->u.none.active_name)
		return -EINVAL;

	r = dm_query_device(cd, cd->u.none.active_name,
			DM_ACTIVE_CRYPT_CIPHER |
			DM_ACTIVE_CRYPT_KEYSIZE, &dmd);
	if (r < 0)
		return r;
	if (!single_segment(&dmd) || tgt->type != DM_CRYPT)
		r = -EINVAL;
	if (r >= 0)
		r = crypt_parse_name_and_mode(tgt->u.crypt.cipher,
					      cd->u.none.cipher, NULL,
					      _mode);

	if (!r) {
		r = snprintf(cd->u.none.cipher_spec, sizeof(cd->u.none.cipher_spec),
			 "%s-%s", cd->u.none.cipher, _mode);
		if (r < 0 || (size_t)r >= sizeof(cd->u.none.cipher_spec))
			r = -EINVAL;
		else {
			cd->u.none.cipher_mode = cd->u.none.cipher_spec + strlen(cd->u.none.cipher) + 1;
			cd->u.none.key_size = tgt->u.crypt.vk->keylength;
			r = 0;
		}
	}

	dm_targets_free(cd, &dmd);
	return r;
}