Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp1746299rwl; Sat, 8 Apr 2023 00:45:23 -0700 (PDT) X-Google-Smtp-Source: AKy350Zp2tozIMQEckKHXvH7Gk2UTqz2Sw/P2rgudLkWlEmlYFHCZ/ilr9LZT4nVU0KpkLYA+QjE X-Received: by 2002:a50:ff13:0:b0:504:80f8:f6b2 with SMTP id a19-20020a50ff13000000b0050480f8f6b2mr2436482edu.25.1680939922984; Sat, 08 Apr 2023 00:45:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680939922; cv=none; d=google.com; s=arc-20160816; b=bqt7FtzE+U+qHtQirYPatGNBZMk00I/qzexiK0rdEwSXcrRWoislhdeNVpy3dZ8+ZP 6htYTnq45ugiCt2nJzP0nLSchdh9+vCspXTdL/CgYiE2SpIlisFvqx93OB3Xm17FvOWI EJQrBl0QnQakRsqpLBSwLJ664Kh1vbYJqWHBX+6m58ZWVc0PdIkj6MdFDso9ZJaIjnaR XgZRhLFPNIlpaMAjjazCGVESYqjXvIhY3p1JM6wny0xVANMz7RGZ2lxNI3deRDAt3Iw3 ivEcTYq9O+ObcuioCvEmEtM0O5x5CiFWUPK+nNFs2ghZCyVKEtNiBAS6M70vhKpLMU95 cGJw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=36XFJD0n9X43UnKMuCNyotopW10jJT7imtId3pNlR4M=; b=Oy3XxiRR/4ccQPw1GELJP0LXktcphCbUuizLw0SxxNa06ZMq9Je4uoayU3jpU5XMcH K+21K0pL5dhp4Yusf50b0PQGqzlzeym6sB/xfpjKnhdqBVo85uREq7ddcDNFsHCzajuA ArL4A3AywrdAMqGNBNP/viGAoCLQdm+lsQuZuaQciuOFQF02iu4UZ5SfS3s7TAliDamJ o5bQeq2Mgp92rEHdIWod6/4/QOeTSF/JFadmIx0yEG0e86gi3CqEDCIKIWFEOJIfkcFL mRm7hZeajO3DDN4719ZCtRNaHImB4U4k2mZfB2znHe9IBcSophyXUylZAeXfSPTaUtxY ApFQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id k1-20020aa7c041000000b0050476f7c049si3588429edo.682.2023.04.08.00.44.57; Sat, 08 Apr 2023 00:45:22 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229570AbjDHHoR (ORCPT + 99 others); Sat, 8 Apr 2023 03:44:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51846 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229484AbjDHHoQ (ORCPT ); Sat, 8 Apr 2023 03:44:16 -0400 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8448ED307 for ; Sat, 8 Apr 2023 00:44:14 -0700 (PDT) Received: from kwepemm600005.china.huawei.com (unknown [172.30.72.54]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4PtnJs4LpvzrZVx; Sat, 8 Apr 2023 15:42:53 +0800 (CST) Received: from huawei.com (10.50.163.32) by kwepemm600005.china.huawei.com (7.193.23.191) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.23; Sat, 8 Apr 2023 15:44:12 +0800 From: Longfang Liu To: , , , CC: , , , Subject: [PATCH v10 2/5] hisi_acc_vfio_pci: extract public functions for container_of Date: Sat, 8 Apr 2023 15:42:21 +0800 Message-ID: <20230408074224.62608-3-liulongfang@huawei.com> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20230408074224.62608-1-liulongfang@huawei.com> References: <20230408074224.62608-1-liulongfang@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.50.163.32] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To kwepemm600005.china.huawei.com (7.193.23.191) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-2.3 required=5.0 tests=RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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, I extracted a public function to replace it. Signed-off-by: Longfang Liu Reviewed-by: Jason Gunthorpe --- .../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 a117eaf21c14..a1589947e721 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 } } +static struct hisi_acc_vf_core_device *hisi_acc_get_vf_dev(struct vfio_device *vdev) +{ + return container_of(vdev, struct hisi_acc_vf_core_device, + core_device.vdev); +} + /* * This function is called in all state_mutex unlock cases to * handle a 'deferred_reset' if exists. @@ -1042,8 +1048,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 = container_of(vdev, - struct hisi_acc_vf_core_device, core_device.vdev); + struct hisi_acc_vf_core_device *hisi_acc_vdev = hisi_acc_get_vf_dev(vdev); enum vfio_device_mig_state next_state; struct file *res = NULL; int ret; @@ -1084,8 +1089,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 = container_of(vdev, - struct hisi_acc_vf_core_device, core_device.vdev); + struct hisi_acc_vf_core_device *hisi_acc_vdev = hisi_acc_get_vf_dev(vdev); mutex_lock(&hisi_acc_vdev->state_mutex); *curr_state = hisi_acc_vdev->mig_state; @@ -1301,8 +1305,7 @@ static long hisi_acc_vfio_pci_ioctl(struct vfio_device *core_vdev, unsigned int static int hisi_acc_vfio_pci_open_device(struct vfio_device *core_vdev) { - struct hisi_acc_vf_core_device *hisi_acc_vdev = container_of(core_vdev, - struct hisi_acc_vf_core_device, core_device.vdev); + struct hisi_acc_vf_core_device *hisi_acc_vdev = hisi_acc_get_vf_dev(core_vdev); struct vfio_pci_core_device *vdev = &hisi_acc_vdev->core_device; int ret; @@ -1325,8 +1328,7 @@ static int hisi_acc_vfio_pci_open_device(struct vfio_device *core_vdev) static void hisi_acc_vfio_pci_close_device(struct vfio_device *core_vdev) { - struct hisi_acc_vf_core_device *hisi_acc_vdev = container_of(core_vdev, - struct hisi_acc_vf_core_device, core_device.vdev); + struct hisi_acc_vf_core_device *hisi_acc_vdev = hisi_acc_get_vf_dev(core_vdev); struct hisi_qm *vf_qm = &hisi_acc_vdev->vf_qm; iounmap(vf_qm->io_base); @@ -1341,8 +1343,7 @@ static const struct vfio_migration_ops hisi_acc_vfio_pci_migrn_state_ops = { static int hisi_acc_vfio_pci_migrn_init_dev(struct vfio_device *core_vdev) { - struct hisi_acc_vf_core_device *hisi_acc_vdev = container_of(core_vdev, - struct hisi_acc_vf_core_device, core_device.vdev); + struct hisi_acc_vf_core_device *hisi_acc_vdev = hisi_acc_get_vf_dev(core_vdev); struct pci_dev *pdev = to_pci_dev(core_vdev->dev); struct hisi_qm *pf_qm = hisi_acc_get_pf_qm(pdev); -- 2.24.0