* [dpdk-dev] [PATCH] net/pcap: solve pcap resource leakage when port probe
@ 2021-08-30 2:54 Qiming Chen
2021-08-30 3:01 ` [dpdk-dev] [PATCH v2] " Qiming Chen
0 siblings, 1 reply; 3+ messages in thread
From: Qiming Chen @ 2021-08-30 2:54 UTC (permalink / raw)
To: dev; +Cc: ferruh.yigit, Qiming Chen
When the port is probed, if the eth_from_pcaps function fails, the
previously opened pcap resources are not released, causing resource
leakage.
The patch solves the problem of resource leakage caused by abnormal
branch exit during the port probe process.
Signed-off-by: Qiming Chen <chenqiming_huawei@163.com>
---
drivers/net/pcap/pcap_ethdev.c | 30 ++++++++++++++++++++++++++++++
1 file changed, 30 insertions(+)
diff --git a/drivers/net/pcap/pcap_ethdev.c b/drivers/net/pcap/pcap_ethdev.c
index fdc74313d5..163e583f7f 100644
--- a/drivers/net/pcap/pcap_ethdev.c
+++ b/drivers/net/pcap/pcap_ethdev.c
@@ -1410,6 +1410,33 @@ eth_from_pcaps(struct rte_vdev_device *vdev,
return 0;
}
+static void
+eth_release_pcaps(struct pmd_devargs *pcaps,
+ struct pmd_devargs *dumpers,
+ int single_iface)
+{
+ unsigned int i;
+
+ if (single_iface) {
+ if (pcaps->queue[0].pcap)
+ pcap_close(pcaps->queue[0].pcap);
+ return;
+ }
+
+ for (i = 0; i < dumpers->num_of_queue; i++) {
+ if (dumpers->queue[i].dumper)
+ pcap_dump_close(dumpers->queue[i].dumper);
+
+ if (dumpers->queue[i].pcap)
+ pcap_close(dumpers->queue[i].pcap);
+ }
+
+ for (i = 0; i < pcaps->num_of_queue; i++) {
+ if (pcaps->queue[i].pcap)
+ pcap_close(pcaps->queue[i].pcap);
+ }
+}
+
static int
pmd_pcap_probe(struct rte_vdev_device *dev)
{
@@ -1639,6 +1666,9 @@ pmd_pcap_probe(struct rte_vdev_device *dev)
free_kvlist:
rte_kvargs_free(kvlist);
+ if (ret < 0)
+ eth_release_pcaps(&pcaps, &dumpers, devargs_all.single_iface);
+
return ret;
}
--
2.30.1.windows.1
^ permalink raw reply [flat|nested] 3+ messages in thread
* [dpdk-dev] [PATCH v2] net/pcap: solve pcap resource leakage when port probe
2021-08-30 2:54 [dpdk-dev] [PATCH] net/pcap: solve pcap resource leakage when port probe Qiming Chen
@ 2021-08-30 3:01 ` Qiming Chen
2021-09-09 13:02 ` Ferruh Yigit
0 siblings, 1 reply; 3+ messages in thread
From: Qiming Chen @ 2021-08-30 3:01 UTC (permalink / raw)
To: dev; +Cc: ferruh.yigit, Qiming Chen
When the port is probed, if the eth_from_pcaps function fails, the
previously opened pcap resources are not released, causing resource
leakage.
The patch solves the problem of resource leakage caused by abnormal
branch exit during the port probe process.
Signed-off-by: Qiming Chen <chenqiming_huawei@163.com>
---
v2:
Clear coding style warning.
---
drivers/net/pcap/pcap_ethdev.c | 30 ++++++++++++++++++++++++++++++
1 file changed, 30 insertions(+)
diff --git a/drivers/net/pcap/pcap_ethdev.c b/drivers/net/pcap/pcap_ethdev.c
index fdc74313d5..4756eecda8 100644
--- a/drivers/net/pcap/pcap_ethdev.c
+++ b/drivers/net/pcap/pcap_ethdev.c
@@ -1410,6 +1410,33 @@ eth_from_pcaps(struct rte_vdev_device *vdev,
return 0;
}
+static void
+eth_release_pcaps(struct pmd_devargs *pcaps,
+ struct pmd_devargs *dumpers,
+ int single_iface)
+{
+ unsigned int i;
+
+ if (single_iface) {
+ if (pcaps->queue[0].pcap)
+ pcap_close(pcaps->queue[0].pcap);
+ return;
+ }
+
+ for (i = 0; i < dumpers->num_of_queue; i++) {
+ if (dumpers->queue[i].dumper)
+ pcap_dump_close(dumpers->queue[i].dumper);
+
+ if (dumpers->queue[i].pcap)
+ pcap_close(dumpers->queue[i].pcap);
+ }
+
+ for (i = 0; i < pcaps->num_of_queue; i++) {
+ if (pcaps->queue[i].pcap)
+ pcap_close(pcaps->queue[i].pcap);
+ }
+}
+
static int
pmd_pcap_probe(struct rte_vdev_device *dev)
{
@@ -1639,6 +1666,9 @@ pmd_pcap_probe(struct rte_vdev_device *dev)
free_kvlist:
rte_kvargs_free(kvlist);
+ if (ret < 0)
+ eth_release_pcaps(&pcaps, &dumpers, devargs_all.single_iface);
+
return ret;
}
--
2.30.1.windows.1
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [dpdk-dev] [PATCH v2] net/pcap: solve pcap resource leakage when port probe
2021-08-30 3:01 ` [dpdk-dev] [PATCH v2] " Qiming Chen
@ 2021-09-09 13:02 ` Ferruh Yigit
0 siblings, 0 replies; 3+ messages in thread
From: Ferruh Yigit @ 2021-09-09 13:02 UTC (permalink / raw)
To: Qiming Chen, dev
On 8/30/2021 4:01 AM, Qiming Chen wrote:
> When the port is probed, if the eth_from_pcaps function fails, the
> previously opened pcap resources are not released, causing resource
> leakage.
>
> The patch solves the problem of resource leakage caused by abnormal
> branch exit during the port probe process.
>
> Signed-off-by: Qiming Chen <chenqiming_huawei@163.com>
Acked-by: Ferruh Yigit <ferruh.yigit@intel.com>
This seems missing from the begging of the PMD, need to following to commit log:
Fixes: 4c173302c307 ("pcap: add new driver")
Cc: stable@dpdk.org
Also we use 'fix' as almost like keyword, so please prefer 'fix' against 'solve'
next time, I will update while merging.
Applied to dpdk-next-net/main, thanks.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2021-09-09 13:02 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-30 2:54 [dpdk-dev] [PATCH] net/pcap: solve pcap resource leakage when port probe Qiming Chen
2021-08-30 3:01 ` [dpdk-dev] [PATCH v2] " Qiming Chen
2021-09-09 13:02 ` Ferruh Yigit
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).