Skip to content

Commit 98657ab

Browse files
committed
idpf: fix potential memory leak on kcalloc() failure
JIRA: https://issues.redhat.com/browse/RHEL-79686 commit 8a558cb Author: Michal Swiatkowski <michal.swiatkowski@linux.intel.com> Date: Fri Apr 4 12:54:21 2025 +0200 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 <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: Michal Schmidt <mschmidt@redhat.com>
1 parent d818ae2 commit 98657ab

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

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

1118-
return NULL;
1119-
}
11201118
idpf_vport_init(vport, max_q);
11211119

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

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

@@ -1143,6 +1139,13 @@ static struct idpf_vport *idpf_vport_alloc(struct idpf_adapter *adapter,
11431139
adapter->next_vport = idpf_get_free_slot(adapter);
11441140

11451141
return vport;
1142+
1143+
free_vector_idxs:
1144+
kfree(vport->q_vector_idxs);
1145+
free_vport:
1146+
kfree(vport);
1147+
1148+
return NULL;
11461149
}
11471150

11481151
/**

0 commit comments

Comments
 (0)