From nobody Mon Nov 25 19:33:08 2024 Received: from szxga03-in.huawei.com (szxga03-in.huawei.com [45.249.212.189]) (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 202811D363D; Fri, 25 Oct 2024 09:02:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.189 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729846964; cv=none; b=mjkS2iDWUcEolJYXx+ScFLI8enZxXQq6lfVnvS0QAnV2vM1nELf3BjcQI4NqwrwALBangtX/2F5oTeH83z8BywuEBzR/4dU0iO2p+YzB60QZyojkWRfJJQTZJw0LKyFOzLkLsQetHwjumCplqnOTWLU1HaXTe0iUPCVGSAtfTBQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729846964; c=relaxed/simple; bh=w4ZxKQrqZpSMibcNS7/BllpRKF+tFp07Q8XIWWUdloo=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=prZzN14EDPWrsfD9W17Nbqf9ScqP5R7Wp9+TGn3HM7iycIwBmftWxW3o2qD7pc6sAZfv1gp2FL+s0o16mdKYlBa5F5SWAP6su0Q3iJ/wfZXhOelX8ymnYDU6v1FXNmCxeWWSBE7EelmPWZ7j729d1BHdOPZw2rrj/eHoTw4rgfs= 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.189 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.163.174]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4XZcGc2pZFzQs4g; Fri, 25 Oct 2024 17:01:44 +0800 (CST) Received: from kwepemm600005.china.huawei.com (unknown [7.193.23.191]) by mail.maildlp.com (Postfix) with ESMTPS id 710FE140337; Fri, 25 Oct 2024 17:02:38 +0800 (CST) Received: from huawei.com (10.50.165.33) by kwepemm600005.china.huawei.com (7.193.23.191) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.39; Fri, 25 Oct 2024 17:02:37 +0800 From: Longfang Liu To: , , , CC: , , , Subject: [PATCH v11 1/4] hisi_acc_vfio_pci: extract public functions for container_of Date: Fri, 25 Oct 2024 17:01:40 +0800 Message-ID: <20241025090143.64472-2-liulongfang@huawei.com> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20241025090143.64472-1-liulongfang@huawei.com> References: <20241025090143.64472-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: dggems702-chm.china.huawei.com (10.3.19.179) To kwepemm600005.china.huawei.com (7.193.23.191) 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