bus/dpaa: fix fd check before close

Message ID a592a45a42ab9aac815652cc2ec909c1ac1ea9a0.1598420841.git.wangyunjian@huawei.com (mailing list archive)
State Superseded, archived
Delegated to: Ferruh Yigit
Headers
Series bus/dpaa: fix fd check before close |

Checks

Context Check Description
ci/Intel-compilation success Compilation OK
ci/travis-robot success Travis build: passed
ci/iol-testing success Testing PASS
ci/iol-mellanox-Performance success Performance Testing PASS
ci/checkpatch success coding style OK

Commit Message

Yunjian Wang Aug. 26, 2020, 11:54 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>
---
 drivers/bus/dpaa/base/qbman/qman_driver.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
  

Comments

Sachin Saxena (OSS) Aug. 26, 2020, 12:08 p.m. UTC | #1
Thanks Yunjian for the fix.

Acked-by: Sachin Saxena<sachin.saxena@oss.nxp.com>


On 26-Aug-20 5:24 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>
> ---
>   drivers/bus/dpaa/base/qbman/qman_driver.c | 4 ++--
>   1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/bus/dpaa/base/qbman/qman_driver.c b/drivers/bus/dpaa/base/qbman/qman_driver.c
> index 1166d68e2..1bff0bc2f 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 = -1, ret;
>   
>   	q_pcfg = kzalloc((sizeof(struct qm_portal_config)), 0);
>   	if (!q_pcfg) {
> @@ -191,7 +191,7 @@ struct qman_portal *fsl_qman_fq_portal_create(int *fd)
>   err:
>   	if (portal)
>   		qman_free_global_portal(portal);
> -	if (q_fd)
> +	if (q_fd != -1)
>   		close(q_fd);
>   	process_portal_unmap(&q_map.addr);
>   	kfree(q_pcfg);
  
Ferruh Yigit Sept. 14, 2020, 5:24 p.m. UTC | #2
On 8/26/2020 12:54 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>
> ---
>  drivers/bus/dpaa/base/qbman/qman_driver.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/bus/dpaa/base/qbman/qman_driver.c b/drivers/bus/dpaa/base/qbman/qman_driver.c
> index 1166d68e2..1bff0bc2f 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 = -1, ret;
>  
>  	q_pcfg = kzalloc((sizeof(struct qm_portal_config)), 0);
>  	if (!q_pcfg) {
> @@ -191,7 +191,7 @@ struct qman_portal *fsl_qman_fq_portal_create(int *fd)
>  err:
>  	if (portal)
>  		qman_free_global_portal(portal);
> -	if (q_fd)
> +	if (q_fd != -1)
>  		close(q_fd);

There is already a 'if (q_fd == -1)' check above to goto this label,
what do you think adding a second label to remove duplicated check?
  
Yunjian Wang Sept. 15, 2020, 12:03 p.m. UTC | #3
> -----Original Message-----
> From: Ferruh Yigit [mailto:ferruh.yigit@intel.com]
> Sent: Tuesday, September 15, 2020 1:24 AM
> To: wangyunjian <wangyunjian@huawei.com>; dev@dpdk.org;
> hemant.agrawal@nxp.com; sachin.saxena@nxp.com
> Cc: Lilijun (Jerry) <jerry.lilijun@huawei.com>; xudingke
> <xudingke@huawei.com>; stable@dpdk.org
> Subject: Re: [dpdk-stable] [dpdk-dev] [PATCH] bus/dpaa: fix fd check before
> close
> 
> On 8/26/2020 12:54 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>
> > ---
> >  drivers/bus/dpaa/base/qbman/qman_driver.c | 4 ++--
> >  1 file changed, 2 insertions(+), 2 deletions(-)
> >
> > diff --git a/drivers/bus/dpaa/base/qbman/qman_driver.c
> > b/drivers/bus/dpaa/base/qbman/qman_driver.c
> > index 1166d68e2..1bff0bc2f 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 = -1, ret;
> >
> >  	q_pcfg = kzalloc((sizeof(struct qm_portal_config)), 0);
> >  	if (!q_pcfg) {
> > @@ -191,7 +191,7 @@ struct qman_portal *fsl_qman_fq_portal_create(int
> > *fd)
> >  err:
> >  	if (portal)
> >  		qman_free_global_portal(portal);
> > -	if (q_fd)
> > +	if (q_fd != -1)
> >  		close(q_fd);
> 
> There is already a 'if (q_fd == -1)' check above to goto this label, what do you
> think adding a second label to remove duplicated check?

Thanks for your suggestion. I will do like this.

Yunjian
  

Patch

diff --git a/drivers/bus/dpaa/base/qbman/qman_driver.c b/drivers/bus/dpaa/base/qbman/qman_driver.c
index 1166d68e2..1bff0bc2f 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 = -1, ret;
 
 	q_pcfg = kzalloc((sizeof(struct qm_portal_config)), 0);
 	if (!q_pcfg) {
@@ -191,7 +191,7 @@  struct qman_portal *fsl_qman_fq_portal_create(int *fd)
 err:
 	if (portal)
 		qman_free_global_portal(portal);
-	if (q_fd)
+	if (q_fd != -1)
 		close(q_fd);
 	process_portal_unmap(&q_map.addr);
 	kfree(q_pcfg);