All of lore.kernel.org
 help / color / mirror / Atom feed
From: "John W. Linville" <linville-2XuSBdqkA4R54TAoqtyWWQ@public.gmane.org>
To: Ouyang Changchun
	<changchun.ouyang-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
Cc: dev-VfR2kkLFssw@public.gmane.org
Subject: Re: [PATCH v5] af_packet: Fix some klocwork errors
Date: Mon, 9 Mar 2015 15:25:31 -0400	[thread overview]
Message-ID: <20150309192531.GC22009@tuxdriver.com> (raw)
In-Reply-To: <1425891491-28779-1-git-send-email-changchun.ouyang-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>

On Mon, Mar 09, 2015 at 04:58:11PM +0800, Ouyang Changchun wrote:
> Fix possible memory leak issue: free kvlist before return;
> Fix possible resource lost issue: close qssockfd before return;
> 
> Signed-off-by: Changchun Ouyang <changchun.ouyang-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
> ---
> Change in v5:
>   - Initialize qsockfd with -1;
> 
> Change in v4:
>   - Check sockfd in internals->rx_queue against 0.
>  
> Change in v3:
>   - Also close sockets for all queues.
>  
> Change in v2:
>   - Make the error exit point a common path.
> 
>  lib/librte_pmd_af_packet/rte_eth_af_packet.c | 17 ++++++++++++++---
>  1 file changed, 14 insertions(+), 3 deletions(-)
> 
> diff --git a/lib/librte_pmd_af_packet/rte_eth_af_packet.c b/lib/librte_pmd_af_packet/rte_eth_af_packet.c
> index 80e9bdf..2a27ebc 100644
> --- a/lib/librte_pmd_af_packet/rte_eth_af_packet.c
> +++ b/lib/librte_pmd_af_packet/rte_eth_af_packet.c
> @@ -442,7 +442,8 @@ rte_pmd_init_internals(const char *name,
>  	struct tpacket_req *req;
>  	struct pkt_rx_queue *rx_queue;
>  	struct pkt_tx_queue *tx_queue;
> -	int rc, qsockfd, tpver, discard;
> +	int rc, tpver, discard;
> +	int qsockfd = -1;
>  	unsigned int i, q, rdsize;
>  	int fanout_arg __rte_unused, bypass __rte_unused;
>  
> @@ -691,9 +692,14 @@ error:
>  				rte_free((*internals)->rx_queue[q].rd);
>  			if ((*internals)->tx_queue[q].rd)
>  				rte_free((*internals)->tx_queue[q].rd);
> +			if (((*internals)->rx_queue[q].sockfd != 0) &&
> +				((*internals)->rx_queue[q].sockfd != qsockfd))
> +				close((*internals)->rx_queue[q].sockfd);
>  		}
>  		rte_free(*internals);
>  	}
> +	if (qsockfd != -1)
> +		close(qsockfd);
>  	return -1;
>  }
>  

The part above seems fine.

> @@ -823,16 +829,21 @@ rte_pmd_af_packet_devinit(const char *name, const char *params)
>  		ret = rte_kvargs_process(kvlist, ETH_AF_PACKET_IFACE_ARG,
>  		                         &open_packet_iface, &sockfd);
>  		if (ret < 0)
> -			return -1;
> +			goto error;
>  	}
>  
>  	ret = rte_eth_from_packet(name, &sockfd, numa_node, kvlist);
>  	close(sockfd); /* no longer needed */
>  
>  	if (ret < 0)
> -		return -1;
> +		goto error;
>  
> +	rte_kvargs_free(kvlist);
>  	return 0;
> +
> +error:
> +	rte_kvargs_free(kvlist);
> +	return -1;
>  }
>  
>  static struct rte_driver pmd_af_packet_drv = {

This seems a bit awkward.  How about the following?

@@ -823,16 +829,15 @@ rte_pmd_af_packet_devinit(const char *name, const char *params)
 		ret = rte_kvargs_process(kvlist, ETH_AF_PACKET_IFACE_ARG,
 		                         &open_packet_iface, &sockfd);
 		if (ret < 0)
-			return -1;
+			goto exit;
 	}
 
 	ret = rte_eth_from_packet(name, &sockfd, numa_node, kvlist);
 	close(sockfd); /* no longer needed */
 
-	if (ret < 0)
-		return -1;
-
-	return 0;
+exit:
+	rte_kvargs_free(kvlist);
+	return ret;
 }
 
 static struct rte_driver pmd_af_packet_drv = {

Does this seem OK to you?

John
-- 
John W. Linville		Someday the world will need a hero, and you
linville-2XuSBdqkA4R54TAoqtyWWQ@public.gmane.org			might be all we have.  Be ready.

  parent reply	other threads:[~2015-03-09 19:25 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-02-26  6:42 [PATCH] af_packet: Fix some klocwork errors Ouyang Changchun
     [not found] ` <1424932947-14750-1-git-send-email-changchun.ouyang-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
2015-02-26  8:44   ` Pawel Wodkowski
2015-02-27  0:49   ` [PATCH v2] " Ouyang Changchun
     [not found]     ` <1424998153-22718-1-git-send-email-changchun.ouyang-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
2015-02-27 14:04       ` Neil Horman
     [not found]         ` <20150227140431.GC1611-B26myB8xz7F8NnZeBjwnZQMhkBWG/bsMQH7oEaQurus@public.gmane.org>
2015-02-28  0:51           ` Ouyang, Changchun
2015-02-28  1:27       ` [PATCH v3] " Ouyang Changchun
     [not found]         ` <1425086874-6238-1-git-send-email-changchun.ouyang-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
2015-03-09  3:49           ` [PATCH v4] " Ouyang Changchun
2015-03-09  6:38             ` Qiu, Michael
     [not found]               ` <533710CFB86FA344BFBF2D6802E60286CF065F-0J0gbvR4kThpB2pF5aRoyrfspsVTdybXVpNB7YpNyf8@public.gmane.org>
2015-03-09  8:47                 ` Ouyang, Changchun
     [not found]             ` <1425872941-26481-1-git-send-email-changchun.ouyang-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
2015-03-09  8:58               ` [PATCH v5] " Ouyang Changchun
     [not found]                 ` <1425891491-28779-1-git-send-email-changchun.ouyang-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
2015-03-09 19:25                   ` John W. Linville [this message]
2015-03-10  3:29                   ` [PATCH v6] " Ouyang Changchun
     [not found]                     ` <1425958188-25041-1-git-send-email-changchun.ouyang-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
2015-03-10  8:36                       ` Pawel Wodkowski
     [not found]                         ` <54FEAD20.8030901-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
2015-03-10  8:49                           ` Ouyang, Changchun
     [not found]                             ` <F52918179C57134FAEC9EA62FA2F962511A2FF15-E2R4CRU6q/6iAffOGbnezLfspsVTdybXVpNB7YpNyf8@public.gmane.org>
2015-03-10  8:59                               ` Pawel Wodkowski
2015-03-10 10:19                               ` Thomas Monjalon
2015-03-11  1:18                                 ` Ouyang, Changchun
2015-03-11  1:34                       ` [PATCH v7] " Ouyang Changchun
2015-03-12 10:43                         ` Qiu, Michael
     [not found]                           ` <533710CFB86FA344BFBF2D6802E60286D02B43-0J0gbvR4kThpB2pF5aRoyrfspsVTdybXVpNB7YpNyf8@public.gmane.org>
2015-03-12 13:38                             ` Neil Horman
     [not found]                               ` <20150312133846.GA15260-B26myB8xz7F8NnZeBjwnZQMhkBWG/bsMQH7oEaQurus@public.gmane.org>
2015-03-12 17:09                                 ` John W. Linville
     [not found]                                   ` <20150312170919.GA19053-2XuSBdqkA4R54TAoqtyWWQ@public.gmane.org>
2015-03-17 21:34                                     ` Thomas Monjalon

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=20150309192531.GC22009@tuxdriver.com \
    --to=linville-2xusbdqka4r54taoqtywwq@public.gmane.org \
    --cc=changchun.ouyang-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org \
    --cc=dev-VfR2kkLFssw@public.gmane.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.