From: Steve Wise <swise@opengridcomputing.com>
To: Nick <xerofoify@gmail.com>, swise@chelsio.com
Cc: roland@kernel.org, sean.hefty@intel.com,
hal.rosenstock@gmail.com, linux-rdma@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH] Fix memory leak in cm.c
Date: Mon, 16 Jun 2014 08:26:10 -0500 [thread overview]
Message-ID: <539EF072.4010003@opengridcomputing.com> (raw)
In-Reply-To: <1402885579-2994-1-git-send-email-xerofoify@gmail.com>
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.
prev parent reply other threads:[~2014-06-16 13:26 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-06-16 2:26 [PATCH] Fix memory leak in cm.c Nick
2014-06-16 2:26 ` Nick
2014-06-16 13:26 ` Steve Wise [this message]
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=539EF072.4010003@opengridcomputing.com \
--to=swise@opengridcomputing.com \
--cc=hal.rosenstock@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-rdma@vger.kernel.org \
--cc=roland@kernel.org \
--cc=sean.hefty@intel.com \
--cc=swise@chelsio.com \
--cc=xerofoify@gmail.com \
/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.