Skip to content

Commit 7161714

Browse files
committed
Merge: vfio/mlx5: Backport error unwind fixes from v6.13-rc1
MR: https://gitlab.com/redhat/centos-stream/src/kernel/centos-stream-10/-/merge_requests/63 JIRA: https://issues.redhat.com/browse/RHEL-69747 Signed-off-by: Alex Williamson <alex.williamson@redhat.com> Approved-by: Donald Dutile <ddutile@redhat.com> Approved-by: Cédric Le Goater <clg@redhat.com> Approved-by: Eric Auger <eric.auger@redhat.com> Approved-by: CKI KWF Bot <cki-ci-bot+kwf-gitlab-com@redhat.com> Merged-by: Jan Stancek <jstancek@redhat.com>
2 parents 6c7a602 + e7ebca1 commit 7161714

File tree

2 files changed

+22
-19
lines changed

2 files changed

+22
-19
lines changed

drivers/vfio/pci/mlx5/cmd.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,7 @@ static int mlx5vf_add_migration_pages(struct mlx5_vhca_data_buffer *buf,
423423
unsigned long filled;
424424
unsigned int to_fill;
425425
int ret;
426+
int i;
426427

427428
to_fill = min_t(unsigned int, npages, PAGE_SIZE / sizeof(*page_list));
428429
page_list = kvzalloc(to_fill * sizeof(*page_list), GFP_KERNEL_ACCOUNT);
@@ -443,7 +444,7 @@ static int mlx5vf_add_migration_pages(struct mlx5_vhca_data_buffer *buf,
443444
GFP_KERNEL_ACCOUNT);
444445

445446
if (ret)
446-
goto err;
447+
goto err_append;
447448
buf->allocated_length += filled * PAGE_SIZE;
448449
/* clean input for another bulk allocation */
449450
memset(page_list, 0, filled * sizeof(*page_list));
@@ -454,6 +455,9 @@ static int mlx5vf_add_migration_pages(struct mlx5_vhca_data_buffer *buf,
454455
kvfree(page_list);
455456
return 0;
456457

458+
err_append:
459+
for (i = filled - 1; i >= 0; i--)
460+
__free_page(page_list[i]);
457461
err:
458462
kvfree(page_list);
459463
return ret;

drivers/vfio/pci/mlx5/main.c

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -640,14 +640,11 @@ mlx5vf_pci_save_device_data(struct mlx5vf_pci_core_device *mvdev, bool track)
640640
O_RDONLY);
641641
if (IS_ERR(migf->filp)) {
642642
ret = PTR_ERR(migf->filp);
643-
goto end;
643+
kfree(migf);
644+
return ERR_PTR(ret);
644645
}
645646

646647
migf->mvdev = mvdev;
647-
ret = mlx5vf_cmd_alloc_pd(migf);
648-
if (ret)
649-
goto out_free;
650-
651648
stream_open(migf->filp->f_inode, migf->filp);
652649
mutex_init(&migf->lock);
653650
init_waitqueue_head(&migf->poll_wait);
@@ -663,6 +660,11 @@ mlx5vf_pci_save_device_data(struct mlx5vf_pci_core_device *mvdev, bool track)
663660
INIT_LIST_HEAD(&migf->buf_list);
664661
INIT_LIST_HEAD(&migf->avail_list);
665662
spin_lock_init(&migf->list_lock);
663+
664+
ret = mlx5vf_cmd_alloc_pd(migf);
665+
if (ret)
666+
goto out;
667+
666668
ret = mlx5vf_cmd_query_vhca_migration_state(mvdev, &length, &full_size, 0);
667669
if (ret)
668670
goto out_pd;
@@ -692,10 +694,8 @@ mlx5vf_pci_save_device_data(struct mlx5vf_pci_core_device *mvdev, bool track)
692694
mlx5vf_free_data_buffer(buf);
693695
out_pd:
694696
mlx5fv_cmd_clean_migf_resources(migf);
695-
out_free:
697+
out:
696698
fput(migf->filp);
697-
end:
698-
kfree(migf);
699699
return ERR_PTR(ret);
700700
}
701701

@@ -1016,13 +1016,19 @@ mlx5vf_pci_resume_device_data(struct mlx5vf_pci_core_device *mvdev)
10161016
O_WRONLY);
10171017
if (IS_ERR(migf->filp)) {
10181018
ret = PTR_ERR(migf->filp);
1019-
goto end;
1019+
kfree(migf);
1020+
return ERR_PTR(ret);
10201021
}
10211022

1023+
stream_open(migf->filp->f_inode, migf->filp);
1024+
mutex_init(&migf->lock);
1025+
INIT_LIST_HEAD(&migf->buf_list);
1026+
INIT_LIST_HEAD(&migf->avail_list);
1027+
spin_lock_init(&migf->list_lock);
10221028
migf->mvdev = mvdev;
10231029
ret = mlx5vf_cmd_alloc_pd(migf);
10241030
if (ret)
1025-
goto out_free;
1031+
goto out;
10261032

10271033
buf = mlx5vf_alloc_data_buffer(migf, 0, DMA_TO_DEVICE);
10281034
if (IS_ERR(buf)) {
@@ -1041,20 +1047,13 @@ mlx5vf_pci_resume_device_data(struct mlx5vf_pci_core_device *mvdev)
10411047
migf->buf_header[0] = buf;
10421048
migf->load_state = MLX5_VF_LOAD_STATE_READ_HEADER;
10431049

1044-
stream_open(migf->filp->f_inode, migf->filp);
1045-
mutex_init(&migf->lock);
1046-
INIT_LIST_HEAD(&migf->buf_list);
1047-
INIT_LIST_HEAD(&migf->avail_list);
1048-
spin_lock_init(&migf->list_lock);
10491050
return migf;
10501051
out_buf:
10511052
mlx5vf_free_data_buffer(migf->buf[0]);
10521053
out_pd:
10531054
mlx5vf_cmd_dealloc_pd(migf);
1054-
out_free:
1055+
out:
10551056
fput(migf->filp);
1056-
end:
1057-
kfree(migf);
10581057
return ERR_PTR(ret);
10591058
}
10601059

0 commit comments

Comments
 (0)