Skip to contentSkip to conversation

Fix memory leak in cm.c

PATCH In review Nick 2 participants 2 messages Jun 16, 2014

Subsystems (2)
lore
Share & tools
lore

Nick

author
#0 lore raw

PATCH 1/1 Fix memory leak in cm.c

This patch fixes memory by checking in function,
*get_skuff if it is be passing a Null skb
struct.
Cheers Nick

---
 drivers/infiniband/hw/cxgb4/cm.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/infiniband/hw/cxgb4/cm.c +5 -1
index 5e153f6..f9477e2 100644
@@ -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);
Signature · 6 lines
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#1 lore raw
Quoted 16 lines · Nick

This patch fixes memory by checking in function,
*get_skuff if it is be passing a Null skb
struct.
Cheers Nick

---
  drivers/infiniband/hw/cxgb4/cm.c | 6 +++++-
  1 file changed, 5 insertions(+), 1 deletion(-)
drivers/infiniband/hw/cxgb4/cm.c +0 -0
index 5e153f6..f9477e2 100644
@@ -340,7 +340,11 @@ static int status2errno(int status)
   */
  static struct sk_buff *get_skb(struct sk_buff *skb, int len, gfp_t gfp)

drivers/infiniband/hw/cxgb4/cm.c static int status2errno(int status) · line 350

Quoted 10 lines
drivers/infiniband/hw/cxgb4/cm.c +5 -1
  {
-	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.