From nobody Sun Nov 24 10:53:57 2024 Received: from szxga04-in.huawei.com (szxga04-in.huawei.com [45.249.212.190]) (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 39AD41DB377; Wed, 6 Nov 2024 10:04:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.190 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730887501; cv=none; b=rXUSRHjGZfs97AfPsBz0HC05OeNqK2pqo16v79yqZW7d+0dpUyIfSo1yJcKvPwFH3MQ2MNbmxmE7KvgE2lytGdl3MLu6E/+i0oB6ZZt4PKKqsfjkPhBe87CuMrolm/Bx8puYvuyphEwJscexf14jQbr/AKmbCLHEfrMLDAYyofw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730887501; c=relaxed/simple; bh=w4ZxKQrqZpSMibcNS7/BllpRKF+tFp07Q8XIWWUdloo=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=h+J/llez8ZJKbKpxsWnEzVwWaweeJ9JdAQLNpCDNICP0ny/mbgvVjJxgqX65xC/ODPNhuEg7UlDhP733HZmNCyL95oxGHbEMQy4A6DVR75uf5+Qu7Gki8M4se/mXrmw1i8Hzd2efDiwmDqqIgaLzbHRPnnH3GLBd3ZqYhhHMrjQ= 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.190 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.162.112]) by szxga04-in.huawei.com (SkyGuard) with ESMTP id 4Xk13x4Xs9z2Fbms; Wed, 6 Nov 2024 18:03:09 +0800 (CST) Received: from dggemv704-chm.china.huawei.com (unknown [10.3.19.47]) by mail.maildlp.com (Postfix) with ESMTPS id A772614037C; Wed, 6 Nov 2024 18:04:50 +0800 (CST) Received: from kwepemn100017.china.huawei.com (7.202.194.122) by dggemv704-chm.china.huawei.com (10.3.19.47) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.39; Wed, 6 Nov 2024 18:04:46 +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; Wed, 6 Nov 2024 18:04:46 +0800 From: Longfang Liu To: , , , CC: , , , Subject: [PATCH v13 1/4] hisi_acc_vfio_pci: extract public functions for container_of Date: Wed, 6 Nov 2024 18:03:40 +0800 Message-ID: <20241106100343.21593-2-liulongfang@huawei.com> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20241106100343.21593-1-liulongfang@huawei.com> References: <20241106100343.21593-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 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