[v2] bus/dpaa: fix fd check before close

Message ID 1600171060-30200-1-git-send-email-wangyunjian@huawei.com (mailing list archive)
State Accepted, archived
Delegated to: Ferruh Yigit
Headers
Series [v2] bus/dpaa: fix fd check before close |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel-compilation fail apply issues

Commit Message

Yunjian Wang Sept. 15, 2020, 11:57 a.m. UTC
From: Yunjian Wang <wangyunjian@huawei.com>

The fd is possibly a negative value while it is passed as an
argument to function "close". Fix the check to the fd.

Fixes: b9c94167904f ("bus/dpaa: decouple FQ portal alloc and init")
Cc: stable@dpdk.org

Signed-off-by: Yunjian Wang <wangyunjian@huawei.com>
---
v2:
   Remove duplicated check suggested by Ferruh Yigit
---
 drivers/bus/dpaa/base/qbman/qman_driver.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
  

Comments

Hemant Agrawal Sept. 16, 2020, 2:48 p.m. UTC | #1
Acked-by: Hemant Agrawal <hemant.agrawal@nxp.com>
  
Ferruh Yigit Sept. 16, 2020, 11:05 p.m. UTC | #2
On 9/15/2020 12:57 PM, wangyunjian wrote:
>> From: Yunjian Wang <wangyunjian@huawei.com>
>> 
>> The fd is possibly a negative value while it is passed as an
>> argument to function "close". Fix the check to the fd.
>> 
>> Fixes: b9c94167904f ("bus/dpaa: decouple FQ portal alloc and init")
>> Cc: stable@dpdk.org
>> 
>> Signed-off-by: Yunjian Wang <wangyunjian@huawei.com>
>
 > Acked-by: Hemant Agrawal <hemant.agrawal@nxp.com>
 >

Applied to dpdk-next-net/main, thanks.
  

Patch

diff --git a/drivers/bus/dpaa/base/qbman/qman_driver.c b/drivers/bus/dpaa/base/qbman/qman_driver.c
index a466c698f..6d9aaff16 100644
--- a/drivers/bus/dpaa/base/qbman/qman_driver.c
+++ b/drivers/bus/dpaa/base/qbman/qman_driver.c
@@ -142,7 +142,7 @@  struct qman_portal *fsl_qman_fq_portal_create(int *fd)
 	struct qm_portal_config *q_pcfg;
 	struct dpaa_ioctl_irq_map irq_map;
 	struct dpaa_ioctl_portal_map q_map = {0};
-	int q_fd = 0, ret;
+	int q_fd, ret;
 
 	q_pcfg = kzalloc((sizeof(struct qm_portal_config)), 0);
 	if (!q_pcfg) {
@@ -179,7 +179,7 @@  struct qman_portal *fsl_qman_fq_portal_create(int *fd)
 	if (!portal) {
 		pr_err("Qman portal initialisation failed (%d)\n",
 		       q_pcfg->cpu);
-		goto err;
+		goto err_alloc;
 	}
 
 	irq_map.type = dpaa_portal_qman;
@@ -188,9 +188,9 @@  struct qman_portal *fsl_qman_fq_portal_create(int *fd)
 
 	*fd = q_fd;
 	return portal;
+err_alloc:
+	close(q_fd);
 err:
-	if (q_fd)
-		close(q_fd);
 	process_portal_unmap(&q_map.addr);
 	kfree(q_pcfg);
 	return NULL;