Skip to contentSkip to conversation

RDMA/rtrs: fix potential resources leaks

PATCH In review Bo YU 3 participants 3 messages Jun 19, 2020

Subsystems (2)
lore
Share & tools
lore

Bo YU

author
#0 lore raw

PATCH 1/1 RDMA/rtrs: fix potential resources leaks

Dev is returned from allocation function kzalloc but it does not free it in out_err path.

Detected by CoverityScan, CID# 1464569: (Resource leak)

Fixes c0894b3ea69d3("RDMA/rtrs: core: lib functions shared between client and server modules")

---
drivers/infiniband/ulp/rtrs/rtrs.c | 1 +

1 file changed, 1 insertion(+)
drivers/infiniband/ulp/rtrs/rtrs.c +0 -0
index ff1093d6e4bc..03bdab92fa49 100644
@@ -607,6 +607,7 @@ rtrs_ib_dev_find_or_add(struct ib_device *ib_dev,
	else
		kfree(dev);
out_err:
+	kfree(dev);
	return NULL;
}

EXPORT_SYMBOL(rtrs_ib_dev_find_or_add);
--
2.11.0

#1 lore raw

Hi, Bo,

Quoted 3 lines · Bo YU

Dev is returned from allocation function kzalloc but it does not free it in out_err path.

If allocation failed, kzalloc return NULL, nothing to free.

Quoted 24 lines

Detected by CoverityScan, CID# 1464569: (Resource leak)

Fixes c0894b3ea69d3("RDMA/rtrs: core: lib functions shared between client and server modules")
---
 drivers/infiniband/ulp/rtrs/rtrs.c | 1 +
 1 file changed, 1 insertion(+)
drivers/infiniband/ulp/rtrs/rtrs.c +1 -1
index ff1093d6e4bc..03bdab92fa49 100644
@@ -607,6 +607,7 @@ rtrs_ib_dev_find_or_add(struct ib_device *ib_dev,
        else
                kfree(dev);
 out_err:
+       kfree(dev);
        return NULL;
 }
 EXPORT_SYMBOL(rtrs_ib_dev_find_or_add);
--

2.11.0

#2 lore raw
Quoted 6 lines · Jinpu Wang

Hi, Bo,

Quoted 3 lines · Bo YU

Dev is returned from allocation function kzalloc but it does not free it in out_err path.

If allocation failed, kzalloc return NULL, nothing to free.

You should re-organize this to not confuse coverity.

IS_ERR_OR_NULL should rarely be used and is the problem here

Jason