Skip to content

Commit ece8a2c

Browse files
Longfang Liuawilliam
authored andcommitted
hisi_acc_vfio_pci: extract public functions for container_of
In the current driver, vdev is obtained from struct hisi_acc_vf_core_device through the container_of function. This method is used in many places in the driver. In order to reduce this repetitive operation, It was extracted into a public function. Signed-off-by: Longfang Liu <[email protected]> Reviewed-by: Shameer Kolothum <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Alex Williamson <[email protected]>
1 parent 9283b73 commit ece8a2c

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

drivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -630,6 +630,12 @@ static void hisi_acc_vf_disable_fds(struct hisi_acc_vf_core_device *hisi_acc_vde
630630
}
631631
}
632632

633+
static struct hisi_acc_vf_core_device *hisi_acc_get_vf_dev(struct vfio_device *vdev)
634+
{
635+
return container_of(vdev, struct hisi_acc_vf_core_device,
636+
core_device.vdev);
637+
}
638+
633639
static void hisi_acc_vf_reset(struct hisi_acc_vf_core_device *hisi_acc_vdev)
634640
{
635641
hisi_acc_vdev->vf_qm_state = QM_NOT_READY;
@@ -1031,8 +1037,7 @@ static struct file *
10311037
hisi_acc_vfio_pci_set_device_state(struct vfio_device *vdev,
10321038
enum vfio_device_mig_state new_state)
10331039
{
1034-
struct hisi_acc_vf_core_device *hisi_acc_vdev = container_of(vdev,
1035-
struct hisi_acc_vf_core_device, core_device.vdev);
1040+
struct hisi_acc_vf_core_device *hisi_acc_vdev = hisi_acc_get_vf_dev(vdev);
10361041
enum vfio_device_mig_state next_state;
10371042
struct file *res = NULL;
10381043
int ret;
@@ -1073,8 +1078,7 @@ static int
10731078
hisi_acc_vfio_pci_get_device_state(struct vfio_device *vdev,
10741079
enum vfio_device_mig_state *curr_state)
10751080
{
1076-
struct hisi_acc_vf_core_device *hisi_acc_vdev = container_of(vdev,
1077-
struct hisi_acc_vf_core_device, core_device.vdev);
1081+
struct hisi_acc_vf_core_device *hisi_acc_vdev = hisi_acc_get_vf_dev(vdev);
10781082

10791083
mutex_lock(&hisi_acc_vdev->state_mutex);
10801084
*curr_state = hisi_acc_vdev->mig_state;
@@ -1278,8 +1282,7 @@ static long hisi_acc_vfio_pci_ioctl(struct vfio_device *core_vdev, unsigned int
12781282

12791283
static int hisi_acc_vfio_pci_open_device(struct vfio_device *core_vdev)
12801284
{
1281-
struct hisi_acc_vf_core_device *hisi_acc_vdev = container_of(core_vdev,
1282-
struct hisi_acc_vf_core_device, core_device.vdev);
1285+
struct hisi_acc_vf_core_device *hisi_acc_vdev = hisi_acc_get_vf_dev(core_vdev);
12831286
struct vfio_pci_core_device *vdev = &hisi_acc_vdev->core_device;
12841287
int ret;
12851288

@@ -1302,8 +1305,7 @@ static int hisi_acc_vfio_pci_open_device(struct vfio_device *core_vdev)
13021305

13031306
static void hisi_acc_vfio_pci_close_device(struct vfio_device *core_vdev)
13041307
{
1305-
struct hisi_acc_vf_core_device *hisi_acc_vdev = container_of(core_vdev,
1306-
struct hisi_acc_vf_core_device, core_device.vdev);
1308+
struct hisi_acc_vf_core_device *hisi_acc_vdev = hisi_acc_get_vf_dev(core_vdev);
13071309
struct hisi_qm *vf_qm = &hisi_acc_vdev->vf_qm;
13081310

13091311
iounmap(vf_qm->io_base);
@@ -1318,8 +1320,7 @@ static const struct vfio_migration_ops hisi_acc_vfio_pci_migrn_state_ops = {
13181320

13191321
static int hisi_acc_vfio_pci_migrn_init_dev(struct vfio_device *core_vdev)
13201322
{
1321-
struct hisi_acc_vf_core_device *hisi_acc_vdev = container_of(core_vdev,
1322-
struct hisi_acc_vf_core_device, core_device.vdev);
1323+
struct hisi_acc_vf_core_device *hisi_acc_vdev = hisi_acc_get_vf_dev(core_vdev);
13231324
struct pci_dev *pdev = to_pci_dev(core_vdev->dev);
13241325
struct hisi_qm *pf_qm = hisi_acc_get_pf_qm(pdev);
13251326

0 commit comments

Comments
 (0)