Skip to content

Commit bf0ec3a

Browse files
Michal Swiatkowskigregkh
authored andcommitted
idpf: fix potential memory leak on kcalloc() failure
[ Upstream commit 8a558cb ] In case of failing on rss_data->rss_key allocation the function is freeing vport without freeing earlier allocated q_vector_idxs. Fix it. Move from freeing in error branch to goto scheme. Fixes: d4d5587 ("idpf: initialize interrupts and enable vport") Reviewed-by: Pavan Kumar Linga <pavan.kumar.linga@intel.com> Reviewed-by: Aleksandr Loktionov <aleksandr.loktionov@intel.com> Suggested-by: Pavan Kumar Linga <pavan.kumar.linga@intel.com> Signed-off-by: Michal Swiatkowski <michal.swiatkowski@linux.intel.com> Reviewed-by: Simon Horman <horms@kernel.org> Tested-by: Samuel Salin <Samuel.salin@intel.com> Signed-off-by: Tony Nguyen <anthony.l.nguyen@intel.com> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent d206ea7 commit bf0ec3a

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

drivers/net/ethernet/intel/idpf/idpf_lib.c

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1108,11 +1108,9 @@ static struct idpf_vport *idpf_vport_alloc(struct idpf_adapter *adapter,
11081108

11091109
num_max_q = max(max_q->max_txq, max_q->max_rxq);
11101110
vport->q_vector_idxs = kcalloc(num_max_q, sizeof(u16), GFP_KERNEL);
1111-
if (!vport->q_vector_idxs) {
1112-
kfree(vport);
1111+
if (!vport->q_vector_idxs)
1112+
goto free_vport;
11131113

1114-
return NULL;
1115-
}
11161114
idpf_vport_init(vport, max_q);
11171115

11181116
/* This alloc is done separate from the LUT because it's not strictly
@@ -1122,11 +1120,9 @@ static struct idpf_vport *idpf_vport_alloc(struct idpf_adapter *adapter,
11221120
*/
11231121
rss_data = &adapter->vport_config[idx]->user_config.rss_data;
11241122
rss_data->rss_key = kzalloc(rss_data->rss_key_size, GFP_KERNEL);
1125-
if (!rss_data->rss_key) {
1126-
kfree(vport);
1123+
if (!rss_data->rss_key)
1124+
goto free_vector_idxs;
11271125

1128-
return NULL;
1129-
}
11301126
/* Initialize default rss key */
11311127
netdev_rss_key_fill((void *)rss_data->rss_key, rss_data->rss_key_size);
11321128

@@ -1139,6 +1135,13 @@ static struct idpf_vport *idpf_vport_alloc(struct idpf_adapter *adapter,
11391135
adapter->next_vport = idpf_get_free_slot(adapter);
11401136

11411137
return vport;
1138+
1139+
free_vector_idxs:
1140+
kfree(vport->q_vector_idxs);
1141+
free_vport:
1142+
kfree(vport);
1143+
1144+
return NULL;
11421145
}
11431146

11441147
/**

0 commit comments

Comments
 (0)