public inbox for linux-rdma@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] Fix memory leak in cm.c
@ 2014-06-16  2:26 Nick
  2014-06-16 13:26 ` Steve Wise
  0 siblings, 1 reply; 2+ messages in thread
From: Nick @ 2014-06-16  2:26 UTC (permalink / raw)
  To: swise-ut6Up61K2wZBDgjK7y7TUQ
  Cc: roland-DgEjT+Ai2ygdnm+yROfE0A, sean.hefty-ral2JQCrhuEAvxtiuMwx3w,
	hal.rosenstock-Re5JQEeQqe8AvxtiuMwx3w,
	linux-rdma-u79uwXL29TY76Z2rM5mHXA,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA

This patch fixes memory by checking in function,
*get_skuff if it is be passing a Null skb
struct.
Cheers Nick 
Signed-off-by: Nick <xerofoify-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
---
 drivers/infiniband/hw/cxgb4/cm.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/infiniband/hw/cxgb4/cm.c b/drivers/infiniband/hw/cxgb4/cm.c
index 5e153f6..f9477e2 100644
--- a/drivers/infiniband/hw/cxgb4/cm.c
+++ b/drivers/infiniband/hw/cxgb4/cm.c
@@ -340,7 +340,11 @@ static int status2errno(int status)
  */
 static struct sk_buff *get_skb(struct sk_buff *skb, int len, gfp_t gfp)
 {
-	if (skb && !skb_is_nonlinear(skb) && !skb_cloned(skb)) {
+	if (!skb) {
+		return NULL;
+	}
+
+	else if (skb && !skb_is_nonlinear(skb) && !skb_cloned(skb)) {
 		skb_trim(skb, 0);
 		skb_get(skb);
 		skb_reset_transport_header(skb);
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] Fix memory leak in cm.c
  2014-06-16  2:26 [PATCH] Fix memory leak in cm.c Nick
@ 2014-06-16 13:26 ` Steve Wise
  0 siblings, 0 replies; 2+ messages in thread
From: Steve Wise @ 2014-06-16 13:26 UTC (permalink / raw)
  To: Nick, swise; +Cc: roland, sean.hefty, hal.rosenstock, linux-rdma, linux-kernel

On 6/15/2014 9:26 PM, Nick wrote:
> This patch fixes memory by checking in function,
> *get_skuff if it is be passing a Null skb
> struct.
> Cheers Nick
> Signed-off-by: Nick <xerofoify@gmail.com>
> ---
>   drivers/infiniband/hw/cxgb4/cm.c | 6 +++++-
>   1 file changed, 5 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/infiniband/hw/cxgb4/cm.c b/drivers/infiniband/hw/cxgb4/cm.c
> index 5e153f6..f9477e2 100644
> --- a/drivers/infiniband/hw/cxgb4/cm.c
> +++ b/drivers/infiniband/hw/cxgb4/cm.c
> @@ -340,7 +340,11 @@ static int status2errno(int status)
>    */
>   static struct sk_buff *get_skb(struct sk_buff *skb, int len, gfp_t gfp)
>   {
> -	if (skb && !skb_is_nonlinear(skb) && !skb_cloned(skb)) {
> +	if (!skb) {
> +		return NULL;
> +	}
> +
> +	else if (skb && !skb_is_nonlinear(skb) && !skb_cloned(skb)) {
>   		skb_trim(skb, 0);
>   		skb_get(skb);
>   		skb_reset_transport_header(skb);

This patch is incorrect.  If skb is null, then get_skb() will allocate a 
new one.  The idea is to reuse skb if it can be reused (ie is linear and 
not cloned). Otherwise allocate a new one:

static struct sk_buff *get_skb(struct sk_buff *skb, int len, gfp_t gfp)
{
         if (skb && !skb_is_nonlinear(skb) && !skb_cloned(skb)) {
                 skb_trim(skb, 0);
                 skb_get(skb);
                 skb_reset_transport_header(skb);
         } else {
                 skb = alloc_skb(len, gfp);
         }
         t4_set_arp_err_handler(skb, NULL, NULL);
         return skb;
}


However, if skb is not null and (is not linear or is cloned), then we 
leak the skb.  So there is a bug.

So the else clause should free skb if it not NULL before calling 
alloc_skb() to get a new one.

Steve.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2014-06-16 13:26 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-06-16  2:26 [PATCH] Fix memory leak in cm.c Nick
2014-06-16 13:26 ` Steve Wise

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox