Skip to contentSkip to conversation

scsi: cxgbi: remove redundant __kfree_skb call on skb and free cst->atid

PATCH Applied Colin King 3 participants 3 messages Apr 12, 2019 – Apr 13, 2019

Subsystems (3)
lore
Share & tools
lore

Colin King

author
#0 lore raw

PATCH v3 1/1 scsi: cxgbi: remove redundant __kfree_skb call on skb and free cst->atid

From: Colin Ian King <[email protected]>

The error return path via label rel_resource checks for a non-null skb before free'ing it. However, skb is always null at this exit path, so the null check and the free are redundant and can be removed. Removing this allows the original goto's to rel_resource to be cleaned up; the first can be replaced by a return of -EINVAL, the second can be replaced by a more appropriate -ENOMEM return and fix a memory leak by freeing csk->atid.

Addresses-Coverity: ("Logically Dead Code")

---

V2: Ensure cst->atid is free'd to fix memory leak, thanks to
Walter Harms for spotting this mistake in V1.

V3: Add missing cxgbi_sock_put, thanks to Dan Carpenter for
spotting this mistake in V2.
---

 drivers/scsi/cxgbi/cxgb3i/cxgb3i.c | 14 ++++++--------
 1 file changed, 6 insertions(+), 8 deletions(-)
drivers/scsi/cxgbi/cxgb3i/cxgb3i.c +6 -8
index 75e1273a44b3..b8dd9e648dd0 100644
@@ -979,14 +979,17 @@ static int init_act_open(struct cxgbi_sock *csk)
 	csk->atid = cxgb3_alloc_atid(t3dev, &t3_client, csk);
 	if (csk->atid < 0) {
 		pr_err("NO atid available.\n");
-		goto rel_resource;
+		return -EINVAL;
 	}
 	cxgbi_sock_set_flag(csk, CTPF_HAS_ATID);
 	cxgbi_sock_get(csk);
 
 	skb = alloc_wr(sizeof(struct cpl_act_open_req), 0, GFP_KERNEL);
-	if (!skb)
-		goto rel_resource;
+	if (!skb) {
+		cxgb3_free_atid(t3dev, csk->atid);
+		cxgbi_sock_put(csk);
+		return -ENOMEM;
+	}
 	skb->sk = (struct sock *)csk;
 	set_arp_failure_handler(skb, act_open_arp_failure);
 	csk->snd_win = cxgb3i_snd_win;
@@ -1007,11 +1010,6 @@ static int init_act_open(struct cxgbi_sock *csk)
 	cxgbi_sock_set_state(csk, CTP_ACTIVE_OPEN);
 	send_act_open_req(csk, skb, csk->l2t);
 	return 0;
-
-rel_resource:
-	if (skb)
-		__kfree_skb(skb);
-	return -EINVAL;
 }
 
 cxgb3_cpl_handler_func cxgb3i_cpl_handlers[NUM_CPL_CMDS] = {
Signature · 1 line
2.20.1
#2 lore raw
In reply to Colin King

Colin,

Quoted 7 lines

The error return path via label rel_resource checks for a non-null skb before free'ing it. However, skb is always null at this exit path, so the null check and the free are redundant and can be removed. Removing this allows the original goto's to rel_resource to be cleaned up; the first can be replaced by a return of -EINVAL, the second can be replaced by a more appropriate -ENOMEM return and fix a memory leak by freeing csk->atid.

Applied to 5.2/scsi-queue, thanks!

Signature · 1 line
Martin K. Petersen	Oracle Linux Engineering