Skip to content

Commit 8a558cb

Browse files
Michal Swiatkowskianguy11
authored andcommitted
idpf: fix potential memory leak on kcalloc() failure
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 <[email protected]> Reviewed-by: Aleksandr Loktionov <[email protected]> Suggested-by: Pavan Kumar Linga <[email protected]> Signed-off-by: Michal Swiatkowski <[email protected]> Reviewed-by: Simon Horman <[email protected]> Tested-by: Samuel Salin <[email protected]> Signed-off-by: Tony Nguyen <[email protected]>
1 parent d4cb1ec commit 8a558cb

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
@@ -1113,11 +1113,9 @@ static struct idpf_vport *idpf_vport_alloc(struct idpf_adapter *adapter,
11131113

11141114
num_max_q = max(max_q->max_txq, max_q->max_rxq);
11151115
vport->q_vector_idxs = kcalloc(num_max_q, sizeof(u16), GFP_KERNEL);
1116-
if (!vport->q_vector_idxs) {
1117-
kfree(vport);
1116+
if (!vport->q_vector_idxs)
1117+
goto free_vport;
11181118

1119-
return NULL;
1120-
}
11211119
idpf_vport_init(vport, max_q);
11221120

11231121
/* This alloc is done separate from the LUT because it's not strictly
@@ -1127,11 +1125,9 @@ static struct idpf_vport *idpf_vport_alloc(struct idpf_adapter *adapter,
11271125
*/
11281126
rss_data = &adapter->vport_config[idx]->user_config.rss_data;
11291127
rss_data->rss_key = kzalloc(rss_data->rss_key_size, GFP_KERNEL);
1130-
if (!rss_data->rss_key) {
1131-
kfree(vport);
1128+
if (!rss_data->rss_key)
1129+
goto free_vector_idxs;
11321130

1133-
return NULL;
1134-
}
11351131
/* Initialize default rss key */
11361132
netdev_rss_key_fill((void *)rss_data->rss_key, rss_data->rss_key_size);
11371133

@@ -1144,6 +1140,13 @@ static struct idpf_vport *idpf_vport_alloc(struct idpf_adapter *adapter,
11441140
adapter->next_vport = idpf_get_free_slot(adapter);
11451141

11461142
return vport;
1143+
1144+
free_vector_idxs:
1145+
kfree(vport->q_vector_idxs);
1146+
free_vport:
1147+
kfree(vport);
1148+
1149+
return NULL;
11471150
}
11481151

11491152
/**

0 commit comments

Comments
 (0)