Skip to contentSkip to conversation

ib/rxe: double free on error

PATCH In review Dan Carpenter 2 participants 5 messages Jun 18, 2016 1 message not in the archive

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ib/rxe: double free on error

"goto err1" could probably be remained "goto free_pkey_tbl" since that's what it does. This is a double free.

Fixes 0784481b2f32 ('Add initialization for Soft RoCE driver, pools constants etc.')
drivers/infiniband/hw/rxe/rxe.c +0 -1
index 48c41e00..50e25b0 100644
@@ -187,7 +187,6 @@ static int rxe_init_ports(struct rxe_dev *rxe)
 	port->pkey_tbl[0] = 0xffff;
 
 	if (!port->attr.gid_tbl_len) {
-		kfree(port->pkey_tbl);
 		err = -EINVAL;
 		goto err1;
 	}
#1 lore raw
Quoted 5 lines · Dan Carpenter

"goto err1" could probably be remained "goto free_pkey_tbl" since that's what it does. This is a double free.

Fixes 0784481b2f32 ('Add initialization for Soft RoCE driver, pools constants etc.')

Hi Dan,

Thank you for pointing it out.

I rewrote your patch a little bit and applied it.

From 6a320576c7304905df722afcf1b8d49242c8ae48 Mon Sep 17 00:00:00 2001
From: Dan Carpenter <[email protected]>
Date: Sat, 18 Jun 2016 11:40:21 +0300
Subject: [PATCH] IB/rxe: Simplify rxe_init_ports logic

Simplify rxe_init_ports and remove double free.

Fixes 0784481b2f32 ('Add initialization for Soft RoCE driver, pools constants etc.')
---
 drivers/infiniband/hw/rxe/rxe.c | 29 ++++++-----------------------
 1 file changed, 6 insertions(+), 23 deletions(-)
drivers/infiniband/hw/rxe/rxe.c +6 -23
index 48c41e00..156a1021 100644
@@ -165,42 +165,25 @@ static int rxe_init_port_param(struct rxe_port *port)
  */
 static int rxe_init_ports(struct rxe_dev *rxe)
 {
-	int err;
-	struct rxe_port *port;
-
-	port = &rxe->port;
+	struct rxe_port *port =  rxe->port;
 
 	rxe_init_port_param(port);
 
-	if (!port->attr.pkey_tbl_len) {
-		err = -EINVAL;
-		goto err1;
-	}
+	if (!port->attr.pkey_tbl_len || !port->attr.gid_tbl_len)
+		return -EINVAL;
 
 	port->pkey_tbl = kcalloc(port->attr.pkey_tbl_len,
 			sizeof(*port->pkey_tbl), GFP_KERNEL);
-	if (!port->pkey_tbl) {
-		err = -ENOMEM;
-		goto err1;
-	}
-
-	port->pkey_tbl[0] = 0xffff;
 
-	if (!port->attr.gid_tbl_len) {
-		kfree(port->pkey_tbl);
-		err = -EINVAL;
-		goto err1;
-	}
+	if (!port->pkey_tbl)
+		return -ENOMEM;
 
+	port->pkey_tbl[0] = 0xffff;
 	port->port_guid = rxe->ifc_ops->port_guid(rxe);
 
 	spin_lock_init(&port->port_lock);
 
 	return 0;
-
-err1:
-	kfree(port->pkey_tbl);
-	return err;
 }
 
 /* init pools of managed objects */
Signature · 1 line
2.1.4

A message that is not in the archive (sent off-list or not yet received): 20160618103430.GC5408-2ukJVAZIZ/[email protected]

#3 lore raw
Quoted 8 lines · Leon Romanovsky
 drivers/infiniband/hw/rxe/rxe.c | 29 ++++++-----------------------
 1 file changed, 6 insertions(+), 23 deletions(-)
drivers/infiniband/hw/rxe/rxe.c +0 -0
index 48c41e00..156a1021 100644

drivers/infiniband/hw/rxe/rxe.c static int rxe_init_port_param(struct rxe_port *port) · line 168

Quoted 8 lines
drivers/infiniband/hw/rxe/rxe.c +1 -4
@@ -165,42 +165,25 @@ static int rxe_init_port_param(struct rxe_port *port)
  */
 static int rxe_init_ports(struct rxe_dev *rxe)
 {
-	int err;
-	struct rxe_port *port;
-
-	port = &rxe->port;
+	struct rxe_port *port =  rxe->port;

This won't compile.

Just give me Reported-by credit not authorship.

regards,
dan carpenter

#4 lore raw
Quoted 4 lines · Dan Carpenter
Quoted 3 lines · Leon Romanovsky
 drivers/infiniband/hw/rxe/rxe.c | 29 ++++++-----------------------
 1 file changed, 6 insertions(+), 23 deletions(-)
Quoted 15 lines

drivers/infiniband/hw/rxe/rxe.c static int rxe_init_port_param(struct rxe_port *port) · line 168

Quoted 13 lines
drivers/infiniband/hw/rxe/rxe.c +1 -4
index 48c41e00..156a1021 100644
@@ -165,42 +165,25 @@ static int rxe_init_port_param(struct rxe_port *port)
  */
 static int rxe_init_ports(struct rxe_dev *rxe)
 {
-	int err;
-	struct rxe_port *port;
-
-	port = &rxe->port;
+	struct rxe_port *port =  rxe->port;

This won't compile.

Interesting, it compiled locally. I'll check it now.

Quoted 6 lines

Just give me Reported-by credit not authorship.

regards,
dan carpenter

#5 lore raw
Quoted 21 lines · Leon Romanovsky
Quoted 4 lines · Dan Carpenter
Quoted 3 lines · Leon Romanovsky
 drivers/infiniband/hw/rxe/rxe.c | 29 ++++++-----------------------
 1 file changed, 6 insertions(+), 23 deletions(-)
Quoted 15 lines

drivers/infiniband/hw/rxe/rxe.c static int rxe_init_port_param(struct rxe_port *port) · line 168

Quoted 13 lines
drivers/infiniband/hw/rxe/rxe.c +1 -4
index 48c41e00..156a1021 100644
@@ -165,42 +165,25 @@ static int rxe_init_port_param(struct rxe_port *port)
  */
 static int rxe_init_ports(struct rxe_dev *rxe)
 {
-	int err;
-	struct rxe_port *port;
-
-	port = &rxe->port;
+	struct rxe_port *port =  rxe->port;

This won't compile.

Quoted 1 line

Interesting, it compiled locally. I'll check it now.

Thanks, I accidentally pushed wrong version.

Quoted 7 lines
Quoted 7 lines

Just give me Reported-by credit not authorship.

regards,
dan carpenter