Unverified Commit a4c42527 authored by openeuler-ci-bot's avatar openeuler-ci-bot Committed by Gitee
Browse files
parents 9ea5cbb2 af025b6b
Loading
Loading
Loading
Loading
+28 −14
Original line number Diff line number Diff line
@@ -361,6 +361,7 @@ static int seg6_hmac_init_algo(void)
	struct crypto_shash *tfm;
	struct shash_desc *shash;
	int i, alg_count, cpu;
	int ret = -ENOMEM;

	alg_count = ARRAY_SIZE(hmac_algos);

@@ -371,12 +372,14 @@ static int seg6_hmac_init_algo(void)
		algo = &hmac_algos[i];
		algo->tfms = alloc_percpu(struct crypto_shash *);
		if (!algo->tfms)
			return -ENOMEM;
			goto error_out;

		for_each_possible_cpu(cpu) {
			tfm = crypto_alloc_shash(algo->name, 0, 0);
			if (IS_ERR(tfm))
				return PTR_ERR(tfm);
			if (IS_ERR(tfm)) {
				ret = PTR_ERR(tfm);
				goto error_out;
			}
			p_tfm = per_cpu_ptr(algo->tfms, cpu);
			*p_tfm = tfm;
		}
@@ -388,18 +391,22 @@ static int seg6_hmac_init_algo(void)

		algo->shashs = alloc_percpu(struct shash_desc *);
		if (!algo->shashs)
			return -ENOMEM;
			goto error_out;

		for_each_possible_cpu(cpu) {
			shash = kzalloc_node(shsize, GFP_KERNEL,
					     cpu_to_node(cpu));
			if (!shash)
				return -ENOMEM;
				goto error_out;
			*per_cpu_ptr(algo->shashs, cpu) = shash;
		}
	}

	return 0;

error_out:
	seg6_hmac_exit();
	return ret;
}

int __init seg6_hmac_init(void)
@@ -421,22 +428,29 @@ EXPORT_SYMBOL(seg6_hmac_net_init);
void seg6_hmac_exit(void)
{
	struct seg6_hmac_algo *algo = NULL;
	struct crypto_shash *tfm;
	struct shash_desc *shash;
	int i, alg_count, cpu;

	alg_count = ARRAY_SIZE(hmac_algos);
	for (i = 0; i < alg_count; i++) {
		algo = &hmac_algos[i];
		for_each_possible_cpu(cpu) {
			struct crypto_shash *tfm;
			struct shash_desc *shash;

		if (algo->shashs) {
			for_each_possible_cpu(cpu) {
				shash = *per_cpu_ptr(algo->shashs, cpu);
				kfree(shash);
			}
			free_percpu(algo->shashs);
		}

		if (algo->tfms) {
			for_each_possible_cpu(cpu) {
				tfm = *per_cpu_ptr(algo->tfms, cpu);
				crypto_free_shash(tfm);
			}
			free_percpu(algo->tfms);
		free_percpu(algo->shashs);
		}
	}
}
EXPORT_SYMBOL(seg6_hmac_exit);