From: Lukasz Wojciechowski <l.wojciechow@partner.samsung.com>
To: Akhil Goyal <akhil.goyal@nxp.com>,
Hemant Agrawal <hemant.agrawal@nxp.com>
Cc: dev@dpdk.org, l.wojciechow@partner.samsung.com
Subject: [dpdk-dev] [PATCH 2/2] crypto/dpaa_sec: repair memory allocations
Date: Tue, 5 May 2020 23:41:05 +0200 [thread overview]
Message-ID: <20200505214105.19465-2-l.wojciechow@partner.samsung.com> (raw)
In-Reply-To: <20200505214105.19465-1-l.wojciechow@partner.samsung.com>
This patch repairs 2 memory allocations issues:
1) possible leak of memory
In cryptodev_dpaa_sec_probe() function in case of portal
initialization failure, function exited without cleanup.
The patch redirects flow to out label, which provides
proper cleanup in case of error: freeing cryptodevice private
data and releasing cryptodevice.
2) double free of cryptodev private data
The function dpaa_sec_dev_init() in case of failure called
dpaa_sec_uninit() which freed both private data and security
context. However one layer above in cryptodev_dpaa_sec_probe()
function, the private data were freed one more time.
The patch limits cleanup of the dpaa_sec_dev_init() function
to freeing only the security context.
Signed-off-by: Lukasz Wojciechowski <l.wojciechow@partner.samsung.com>
---
drivers/crypto/dpaa_sec/dpaa_sec.c | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/drivers/crypto/dpaa_sec/dpaa_sec.c b/drivers/crypto/dpaa_sec/dpaa_sec.c
index 021a5639d..097ab8de9 100644
--- a/drivers/crypto/dpaa_sec/dpaa_sec.c
+++ b/drivers/crypto/dpaa_sec/dpaa_sec.c
@@ -3410,7 +3410,7 @@ dpaa_sec_dev_init(struct rte_cryptodev *cryptodev)
init_error:
DPAA_SEC_ERR("driver %s: create failed\n", cryptodev->data->name);
- dpaa_sec_uninit(cryptodev);
+ rte_free(cryptodev->security_ctx);
return -EFAULT;
}
@@ -3467,7 +3467,7 @@ cryptodev_dpaa_sec_probe(struct rte_dpaa_driver *dpaa_drv __rte_unused,
retval = rte_dpaa_portal_init((void *)1);
if (retval) {
DPAA_SEC_ERR("Unable to initialize portal");
- return retval;
+ goto out;
}
}
@@ -3476,13 +3476,15 @@ cryptodev_dpaa_sec_probe(struct rte_dpaa_driver *dpaa_drv __rte_unused,
if (retval == 0)
return 0;
+ retval = -ENXIO;
+out:
/* In case of error, cleanup is done */
if (rte_eal_process_type() == RTE_PROC_PRIMARY)
rte_free(cryptodev->data->dev_private);
rte_cryptodev_pmd_release_device(cryptodev);
- return -ENXIO;
+ return retval;
}
static int
--
2.17.1
next prev parent reply other threads:[~2020-05-05 21:41 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <CGME20200505214128eucas1p26202807ca7da9e16c1628fd63cb2dfeb@eucas1p2.samsung.com>
2020-05-05 21:41 ` [dpdk-dev] [PATCH 1/2] crypto/dpaa_sec: improve memory freeing Lukasz Wojciechowski
[not found] ` <CGME20200505214129eucas1p146b40738c440b77ee0131d18a80eea3d@eucas1p1.samsung.com>
2020-05-05 21:41 ` Lukasz Wojciechowski [this message]
2020-05-09 21:58 ` Akhil Goyal
2020-05-11 10:17 ` Lukasz Wojciechowski
2020-05-11 10:20 ` Akhil Goyal
2020-05-11 13:11 ` Lukasz Wojciechowski
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200505214105.19465-2-l.wojciechow@partner.samsung.com \
--to=l.wojciechow@partner.samsung.com \
--cc=akhil.goyal@nxp.com \
--cc=dev@dpdk.org \
--cc=hemant.agrawal@nxp.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).