From nobody Sun Nov 24 16:05:58 2024 Received: from szxga06-in.huawei.com (szxga06-in.huawei.com [45.249.212.32]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 55DF118C015; Tue, 5 Nov 2024 03:53:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.32 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730778842; cv=none; b=Snb0ihI2CxtvS0uXaMSiCfgqlC5r4TCOrSLrAqQBNZpXL8gtAMpcOYCZCjHQUHedpw9xfWygRdwYLvwXYo0Nzg5cLiTvZKEB18lFAAwKxh3UnRcWqks27zH7pTeJnrbiskcnpSvxjSOPgx6vQVRBgrCY1YYa9u4tCSvGnpQtIVI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730778842; c=relaxed/simple; bh=w4ZxKQrqZpSMibcNS7/BllpRKF+tFp07Q8XIWWUdloo=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=GY8Y9uO3m1/G0d0xhUYHS8ZUpgu5bl1Yl6UYZHrHUo8GqqSSIEO9vLL0u3LcjPkj3FjVJbNpbqu00w+X/nYy3YVQG8h7LNMbpHOXA5t390vXfsTaOHdV53bCMZvooDgaK0PoCjdMGTegdFlOlYQNmKiMCMH+YVM8099JhPk4xho= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=45.249.212.32 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.19.88.214]) by szxga06-in.huawei.com (SkyGuard) with ESMTP id 4XjDwZ6JYDz1ypBH; Tue, 5 Nov 2024 11:54:06 +0800 (CST) Received: from dggemv711-chm.china.huawei.com (unknown [10.1.198.66]) by mail.maildlp.com (Postfix) with ESMTPS id 0F4231A016C; Tue, 5 Nov 2024 11:53:57 +0800 (CST) Received: from kwepemn100017.china.huawei.com (7.202.194.122) by dggemv711-chm.china.huawei.com (10.1.198.66) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.39; Tue, 5 Nov 2024 11:53:56 +0800 Received: from huawei.com (10.50.165.33) by kwepemn100017.china.huawei.com (7.202.194.122) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Tue, 5 Nov 2024 11:53:56 +0800 From: Longfang Liu To: , , , CC: , , , Subject: [PATCH v12 1/4] hisi_acc_vfio_pci: extract public functions for container_of Date: Tue, 5 Nov 2024 11:52:51 +0800 Message-ID: <20241105035254.24636-2-liulongfang@huawei.com> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20241105035254.24636-1-liulongfang@huawei.com> References: <20241105035254.24636-1-liulongfang@huawei.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To kwepemn100017.china.huawei.com (7.202.194.122) Content-Type: text/plain; charset="utf-8" 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 Reviewed-by: Shameer Kolothum --- .../vfio/pci/hisilicon/hisi_acc_vfio_pci.c | 21 ++++++++++--------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/drivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c b/drivers/vfio/= pci/hisilicon/hisi_acc_vfio_pci.c index 9a3e97108ace..45351be8e270 100644 --- a/drivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c +++ b/drivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c @@ -630,6 +630,12 @@ static void hisi_acc_vf_disable_fds(struct hisi_acc_vf= _core_device *hisi_acc_vde } } =20 +static struct hisi_acc_vf_core_device *hisi_acc_get_vf_dev(struct vfio_dev= ice *vdev) +{ + return container_of(vdev, struct hisi_acc_vf_core_device, + core_device.vdev); +} + static void hisi_acc_vf_reset(struct hisi_acc_vf_core_device *hisi_acc_vde= v) { hisi_acc_vdev->vf_qm_state =3D QM_NOT_READY; @@ -1033,8 +1039,7 @@ static struct file * hisi_acc_vfio_pci_set_device_state(struct vfio_device *vdev, enum vfio_device_mig_state new_state) { - struct hisi_acc_vf_core_device *hisi_acc_vdev =3D container_of(vdev, - struct hisi_acc_vf_core_device, core_device.vdev); + struct hisi_acc_vf_core_device *hisi_acc_vdev =3D hisi_acc_get_vf_dev(vde= v); enum vfio_device_mig_state next_state; struct file *res =3D NULL; int ret; @@ -1075,8 +1080,7 @@ static int hisi_acc_vfio_pci_get_device_state(struct vfio_device *vdev, enum vfio_device_mig_state *curr_state) { - struct hisi_acc_vf_core_device *hisi_acc_vdev =3D container_of(vdev, - struct hisi_acc_vf_core_device, core_device.vdev); + struct hisi_acc_vf_core_device *hisi_acc_vdev =3D hisi_acc_get_vf_dev(vde= v); =20 mutex_lock(&hisi_acc_vdev->state_mutex); *curr_state =3D hisi_acc_vdev->mig_state; @@ -1280,8 +1284,7 @@ static long hisi_acc_vfio_pci_ioctl(struct vfio_devic= e *core_vdev, unsigned int =20 static int hisi_acc_vfio_pci_open_device(struct vfio_device *core_vdev) { - struct hisi_acc_vf_core_device *hisi_acc_vdev =3D container_of(core_vdev, - struct hisi_acc_vf_core_device, core_device.vdev); + struct hisi_acc_vf_core_device *hisi_acc_vdev =3D hisi_acc_get_vf_dev(cor= e_vdev); struct vfio_pci_core_device *vdev =3D &hisi_acc_vdev->core_device; int ret; =20 @@ -1304,8 +1307,7 @@ static int hisi_acc_vfio_pci_open_device(struct vfio_= device *core_vdev) =20 static void hisi_acc_vfio_pci_close_device(struct vfio_device *core_vdev) { - struct hisi_acc_vf_core_device *hisi_acc_vdev =3D container_of(core_vdev, - struct hisi_acc_vf_core_device, core_device.vdev); + struct hisi_acc_vf_core_device *hisi_acc_vdev =3D hisi_acc_get_vf_dev(cor= e_vdev); struct hisi_qm *vf_qm =3D &hisi_acc_vdev->vf_qm; =20 iounmap(vf_qm->io_base); @@ -1320,8 +1322,7 @@ static const struct vfio_migration_ops hisi_acc_vfio_= pci_migrn_state_ops =3D { =20 static int hisi_acc_vfio_pci_migrn_init_dev(struct vfio_device *core_vdev) { - struct hisi_acc_vf_core_device *hisi_acc_vdev =3D container_of(core_vdev, - struct hisi_acc_vf_core_device, core_device.vdev); + struct hisi_acc_vf_core_device *hisi_acc_vdev =3D hisi_acc_get_vf_dev(cor= e_vdev); struct pci_dev *pdev =3D to_pci_dev(core_vdev->dev); struct hisi_qm *pf_qm =3D hisi_acc_get_pf_qm(pdev); =20 --=20 2.24.0