Commit 24efcec2 authored by Longfang Liu's avatar Longfang Liu Committed by Herbert Xu
Browse files

crypto: hisilicon - fixed memory allocation error



1. Fix the bug of 'mac' memory leak as allocating 'pbuf' failing.
2. Fix the bug of 'qps' leak as allocating 'qp_ctx' failing.

Signed-off-by: default avatarLongfang Liu <liulongfang@huawei.com>
Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
parent 0542a941
Loading
Loading
Loading
Loading
+12 −4
Original line number Diff line number Diff line
@@ -340,11 +340,14 @@ static int sec_alg_resource_alloc(struct sec_ctx *ctx,
		ret = sec_alloc_pbuf_resource(dev, res);
		if (ret) {
			dev_err(dev, "fail to alloc pbuf dma resource!\n");
			goto alloc_fail;
			goto alloc_pbuf_fail;
		}
	}

	return 0;
alloc_pbuf_fail:
	if (ctx->alg_type == SEC_AEAD)
		sec_free_mac_resource(dev, qp_ctx->res);
alloc_fail:
	sec_free_civ_resource(dev, res);

@@ -455,8 +458,10 @@ static int sec_ctx_base_init(struct sec_ctx *ctx)
	ctx->fake_req_limit = QM_Q_DEPTH >> 1;
	ctx->qp_ctx = kcalloc(sec->ctx_q_num, sizeof(struct sec_qp_ctx),
			      GFP_KERNEL);
	if (!ctx->qp_ctx)
		return -ENOMEM;
	if (!ctx->qp_ctx) {
		ret = -ENOMEM;
		goto err_destroy_qps;
	}

	for (i = 0; i < sec->ctx_q_num; i++) {
		ret = sec_create_qp_ctx(&sec->qm, ctx, i, 0);
@@ -465,12 +470,15 @@ static int sec_ctx_base_init(struct sec_ctx *ctx)
	}

	return 0;

err_sec_release_qp_ctx:
	for (i = i - 1; i >= 0; i--)
		sec_release_qp_ctx(ctx, &ctx->qp_ctx[i]);

	sec_destroy_qps(ctx->qps, sec->ctx_q_num);
	kfree(ctx->qp_ctx);
err_destroy_qps:
	sec_destroy_qps(ctx->qps, sec->ctx_q_num);

	return ret;
}