crypto: virtio - Less function calls in __virtio_crypto_akcipher_do_req() after error detection
The kfree() function was called in up to two cases by the __virtio_crypto_akcipher_do_req() function during error handling even if the passed variable contained a null pointer. This issue was detected by using the Coccinelle software. * Adjust jump targets. * Delete two initialisations which became unnecessary with this refactoring. Signed-off-by: Markus Elfring <elfring@users.sourceforge.net> Reviewed-by: Gonglei <arei.gonglei@huawei.com> Reviewed-by: Justin Stitt <justinstitt@google.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
This commit is contained in:
parent
c5a2f74db7
commit
e01966e643
@ -224,11 +224,11 @@ static int __virtio_crypto_akcipher_do_req(struct virtio_crypto_akcipher_request
|
|||||||
struct virtio_crypto *vcrypto = ctx->vcrypto;
|
struct virtio_crypto *vcrypto = ctx->vcrypto;
|
||||||
struct virtio_crypto_op_data_req *req_data = vc_req->req_data;
|
struct virtio_crypto_op_data_req *req_data = vc_req->req_data;
|
||||||
struct scatterlist *sgs[4], outhdr_sg, inhdr_sg, srcdata_sg, dstdata_sg;
|
struct scatterlist *sgs[4], outhdr_sg, inhdr_sg, srcdata_sg, dstdata_sg;
|
||||||
void *src_buf = NULL, *dst_buf = NULL;
|
void *src_buf, *dst_buf = NULL;
|
||||||
unsigned int num_out = 0, num_in = 0;
|
unsigned int num_out = 0, num_in = 0;
|
||||||
int node = dev_to_node(&vcrypto->vdev->dev);
|
int node = dev_to_node(&vcrypto->vdev->dev);
|
||||||
unsigned long flags;
|
unsigned long flags;
|
||||||
int ret = -ENOMEM;
|
int ret;
|
||||||
bool verify = vc_akcipher_req->opcode == VIRTIO_CRYPTO_AKCIPHER_VERIFY;
|
bool verify = vc_akcipher_req->opcode == VIRTIO_CRYPTO_AKCIPHER_VERIFY;
|
||||||
unsigned int src_len = verify ? req->src_len + req->dst_len : req->src_len;
|
unsigned int src_len = verify ? req->src_len + req->dst_len : req->src_len;
|
||||||
|
|
||||||
@ -239,7 +239,7 @@ static int __virtio_crypto_akcipher_do_req(struct virtio_crypto_akcipher_request
|
|||||||
/* src data */
|
/* src data */
|
||||||
src_buf = kcalloc_node(src_len, 1, GFP_KERNEL, node);
|
src_buf = kcalloc_node(src_len, 1, GFP_KERNEL, node);
|
||||||
if (!src_buf)
|
if (!src_buf)
|
||||||
goto err;
|
return -ENOMEM;
|
||||||
|
|
||||||
if (verify) {
|
if (verify) {
|
||||||
/* for verify operation, both src and dst data work as OUT direction */
|
/* for verify operation, both src and dst data work as OUT direction */
|
||||||
@ -254,7 +254,7 @@ static int __virtio_crypto_akcipher_do_req(struct virtio_crypto_akcipher_request
|
|||||||
/* dst data */
|
/* dst data */
|
||||||
dst_buf = kcalloc_node(req->dst_len, 1, GFP_KERNEL, node);
|
dst_buf = kcalloc_node(req->dst_len, 1, GFP_KERNEL, node);
|
||||||
if (!dst_buf)
|
if (!dst_buf)
|
||||||
goto err;
|
goto free_src;
|
||||||
|
|
||||||
sg_init_one(&dstdata_sg, dst_buf, req->dst_len);
|
sg_init_one(&dstdata_sg, dst_buf, req->dst_len);
|
||||||
sgs[num_out + num_in++] = &dstdata_sg;
|
sgs[num_out + num_in++] = &dstdata_sg;
|
||||||
@ -277,9 +277,9 @@ static int __virtio_crypto_akcipher_do_req(struct virtio_crypto_akcipher_request
|
|||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
err:
|
err:
|
||||||
kfree(src_buf);
|
|
||||||
kfree(dst_buf);
|
kfree(dst_buf);
|
||||||
|
free_src:
|
||||||
|
kfree(src_buf);
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user