Skip to content

Commit 3947755

Browse files
Denis Bolotindavem330
authored andcommitted
qed: Fix memory/entry leak in qed_init_sp_request()
Free the allocated SPQ entry or return the acquired SPQ entry to the free list in error flows. Signed-off-by: Denis Bolotin <denis.bolotin@cavium.com> Signed-off-by: Michal Kalderon <michal.kalderon@cavium.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 0d5b931 commit 3947755

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

drivers/net/ethernet/qlogic/qed/qed_sp_commands.c

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ int qed_sp_init_request(struct qed_hwfn *p_hwfn,
8080

8181
case QED_SPQ_MODE_BLOCK:
8282
if (!p_data->p_comp_data)
83-
return -EINVAL;
83+
goto err;
8484

8585
p_ent->comp_cb.cookie = p_data->p_comp_data->cookie;
8686
break;
@@ -95,7 +95,7 @@ int qed_sp_init_request(struct qed_hwfn *p_hwfn,
9595
default:
9696
DP_NOTICE(p_hwfn, "Unknown SPQE completion mode %d\n",
9797
p_ent->comp_mode);
98-
return -EINVAL;
98+
goto err;
9999
}
100100

101101
DP_VERBOSE(p_hwfn, QED_MSG_SPQ,
@@ -109,6 +109,18 @@ int qed_sp_init_request(struct qed_hwfn *p_hwfn,
109109
memset(&p_ent->ramrod, 0, sizeof(p_ent->ramrod));
110110

111111
return 0;
112+
113+
err:
114+
/* qed_spq_get_entry() can either get an entry from the free_pool,
115+
* or, if no entries are left, allocate a new entry and add it to
116+
* the unlimited_pending list.
117+
*/
118+
if (p_ent->queue == &p_hwfn->p_spq->unlimited_pending)
119+
kfree(p_ent);
120+
else
121+
qed_spq_return_entry(p_hwfn, p_ent);
122+
123+
return -EINVAL;
112124
}
113125

114126
static enum tunnel_clss qed_tunn_clss_to_fw_clss(u8 type)

0 commit comments

Comments
 (0)