Skip to content

Commit e01966e

Browse files
elfringherbertx
authored andcommitted
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 <[email protected]> Reviewed-by: Gonglei <[email protected]> Reviewed-by: Justin Stitt <[email protected]> Signed-off-by: Herbert Xu <[email protected]>
1 parent c5a2f74 commit e01966e

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

drivers/crypto/virtio/virtio_crypto_akcipher_algs.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -224,11 +224,11 @@ static int __virtio_crypto_akcipher_do_req(struct virtio_crypto_akcipher_request
224224
struct virtio_crypto *vcrypto = ctx->vcrypto;
225225
struct virtio_crypto_op_data_req *req_data = vc_req->req_data;
226226
struct scatterlist *sgs[4], outhdr_sg, inhdr_sg, srcdata_sg, dstdata_sg;
227-
void *src_buf = NULL, *dst_buf = NULL;
227+
void *src_buf, *dst_buf = NULL;
228228
unsigned int num_out = 0, num_in = 0;
229229
int node = dev_to_node(&vcrypto->vdev->dev);
230230
unsigned long flags;
231-
int ret = -ENOMEM;
231+
int ret;
232232
bool verify = vc_akcipher_req->opcode == VIRTIO_CRYPTO_AKCIPHER_VERIFY;
233233
unsigned int src_len = verify ? req->src_len + req->dst_len : req->src_len;
234234

@@ -239,7 +239,7 @@ static int __virtio_crypto_akcipher_do_req(struct virtio_crypto_akcipher_request
239239
/* src data */
240240
src_buf = kcalloc_node(src_len, 1, GFP_KERNEL, node);
241241
if (!src_buf)
242-
goto err;
242+
return -ENOMEM;
243243

244244
if (verify) {
245245
/* 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
254254
/* dst data */
255255
dst_buf = kcalloc_node(req->dst_len, 1, GFP_KERNEL, node);
256256
if (!dst_buf)
257-
goto err;
257+
goto free_src;
258258

259259
sg_init_one(&dstdata_sg, dst_buf, req->dst_len);
260260
sgs[num_out + num_in++] = &dstdata_sg;
@@ -277,9 +277,9 @@ static int __virtio_crypto_akcipher_do_req(struct virtio_crypto_akcipher_request
277277
return 0;
278278

279279
err:
280-
kfree(src_buf);
281280
kfree(dst_buf);
282-
281+
free_src:
282+
kfree(src_buf);
283283
return -ENOMEM;
284284
}
285285

0 commit comments

Comments
 (0)